Merge branch 'display-grid' into 'master'
Display grid See merge request mhart/DancingDroids!45
This commit is contained in:
		
						commit
						9adcfe9ce3
					
				
							
								
								
									
										30
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/main.rs
									
									
									
									
									
								
							@ -198,6 +198,34 @@ fn open_file(filename: &str) -> io::Result<String> {
 | 
				
			|||||||
    Ok(content)
 | 
					    Ok(content)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Here we display the grid by looping in every position checking if it exists in the HashMap.
 | 
				
			||||||
 | 
					fn display_grid(
 | 
				
			||||||
 | 
					    w: &world::World,
 | 
				
			||||||
 | 
					    robot_pool: &Vec<robot::Robot>,
 | 
				
			||||||
 | 
					    h: &HashMap<robot::Position, u32>,
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
 | 
					    for i in (0..w.y).rev() {
 | 
				
			||||||
 | 
					        print!("{}  ", i);
 | 
				
			||||||
 | 
					        for j in 0..w.x {
 | 
				
			||||||
 | 
					            match h.get(&robot::Position { x: j, y: i }) {
 | 
				
			||||||
 | 
					                Some(id) => match robot_pool[(id - 1) as usize].o {
 | 
				
			||||||
 | 
					                    robot::Orientation::N => print!("↑  "),
 | 
				
			||||||
 | 
					                    robot::Orientation::E => print!("→  "),
 | 
				
			||||||
 | 
					                    robot::Orientation::S => print!("↓  "),
 | 
				
			||||||
 | 
					                    robot::Orientation::W => print!("←  "),
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                None => print!(".  "),
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        println!();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    print!("   ");
 | 
				
			||||||
 | 
					    for j in 0..w.x {
 | 
				
			||||||
 | 
					        print!("{}  ", j);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    println!();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
					fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
				
			||||||
    // We handle CLI flags here.
 | 
					    // We handle CLI flags here.
 | 
				
			||||||
    let matches = App::new("DancingDroids")
 | 
					    let matches = App::new("DancingDroids")
 | 
				
			||||||
@ -218,7 +246,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
				
			|||||||
    let world: world::World = parse_config(raw_conf, &mut robot_pool)?;
 | 
					    let world: world::World = parse_config(raw_conf, &mut robot_pool)?;
 | 
				
			||||||
    let mut hash: HashMap<robot::Position, u32> = HashMap::new();
 | 
					    let mut hash: HashMap<robot::Position, u32> = HashMap::new();
 | 
				
			||||||
    create_hash_map(&robot_pool, &mut hash);
 | 
					    create_hash_map(&robot_pool, &mut hash);
 | 
				
			||||||
 | 
					    display_grid(&world, &robot_pool, &hash);
 | 
				
			||||||
    loop {
 | 
					    loop {
 | 
				
			||||||
        let mut piouff: u32 = 0;
 | 
					        let mut piouff: u32 = 0;
 | 
				
			||||||
        for r in &mut robot_pool {
 | 
					        for r in &mut robot_pool {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user