limit grid display to (60x45)max
This commit is contained in:
		
							parent
							
								
									14d307ef88
								
							
						
					
					
						commit
						9857639b12
					
				
							
								
								
									
										24
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/main.rs
									
									
									
									
									
								
							@ -266,9 +266,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
				
			|||||||
    create_hash_map(&robot_pool, &mut hash);
 | 
					    create_hash_map(&robot_pool, &mut hash);
 | 
				
			||||||
    let mut print_all = format!("World {{ x_max = {}; y_max = {} }}\n", world.x, world.y);
 | 
					    let mut print_all = format!("World {{ x_max = {}; y_max = {} }}\n", world.x, world.y);
 | 
				
			||||||
    print_all = format!("{}{}", print_all, robot::print_robots(&robot_pool));
 | 
					    print_all = format!("{}{}", print_all, robot::print_robots(&robot_pool));
 | 
				
			||||||
    print_all = format!("{}Initial state\n", print_all);
 | 
					    if world.x <= 60 && world.y <= 45 {
 | 
				
			||||||
    print_all = format!("{}==============\n", print_all);
 | 
					        print_all = format!("{}Initial state\n", print_all);
 | 
				
			||||||
    print_all = format!("{}{}", print_all, display_grid(&world, &robot_pool, &hash));
 | 
					        print_all = format!("{}==============\n", print_all);
 | 
				
			||||||
 | 
					        print_all = format!("{}{}", print_all, 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 {
 | 
				
			||||||
@ -282,18 +284,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
				
			|||||||
                hash.insert(robot::Position { x: r.p.x, y: r.p.y }, r.id);
 | 
					                hash.insert(robot::Position { x: r.p.x, y: r.p.y }, r.id);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        std::thread::sleep(std::time::Duration::from_millis(600));
 | 
					        if world.x <= 60 && world.y <= 45 {
 | 
				
			||||||
        print!("\x1B[2J\x1B[1;1H");
 | 
					            std::thread::sleep(std::time::Duration::from_millis(600));
 | 
				
			||||||
        print!("{}", display_grid(&world, &robot_pool, &hash));
 | 
					            print!("\x1B[2J\x1B[1;1H");
 | 
				
			||||||
 | 
					            print!("{}", display_grid(&world, &robot_pool, &hash));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        if piouff == robot_pool.len() as u32 {
 | 
					        if piouff == robot_pool.len() as u32 {
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    print!("\x1B[2J\x1B[1;1H");
 | 
					    print!("\x1B[2J\x1B[1;1H");
 | 
				
			||||||
    print!("{}", print_all);
 | 
					    print!("{}", print_all);
 | 
				
			||||||
    println!("Final state");
 | 
					    if world.x <= 60 && world.y <= 45 {
 | 
				
			||||||
    println!("============");
 | 
					        println!("Final state");
 | 
				
			||||||
    print!("{}", display_grid(&world, &robot_pool, &hash));
 | 
					        println!("============");
 | 
				
			||||||
 | 
					        print!("{}", display_grid(&world, &robot_pool, &hash));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    for r in &robot_pool {
 | 
					    for r in &robot_pool {
 | 
				
			||||||
        println!("Robot id: {}: Final position: ({}, {})", r.id, r.p.x, r.p.y);
 | 
					        println!("Robot id: {}: Final position: ({}, {})", r.id, r.p.x, r.p.y);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@ pub struct World {
 | 
				
			|||||||
/// Create a random World.
 | 
					/// Create a random World.
 | 
				
			||||||
pub fn random_world() -> World {
 | 
					pub fn random_world() -> World {
 | 
				
			||||||
    let mut rng = rand::thread_rng();
 | 
					    let mut rng = rand::thread_rng();
 | 
				
			||||||
    let z = rng.gen_range(5, 50);
 | 
					    let z = rng.gen_range(5, 45);
 | 
				
			||||||
    World { x: z, y: z }
 | 
					    World { x: z, y: z }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user