limit grid display to (60x45)max

This commit is contained in:
Volodymyr Patuta 2020-11-07 15:05:47 +01:00
parent 14d307ef88
commit 9857639b12
2 changed files with 16 additions and 10 deletions

View File

@ -266,9 +266,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
create_hash_map(&robot_pool, &mut hash);
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));
if world.x <= 60 && world.y <= 45 {
print_all = format!("{}Initial state\n", print_all);
print_all = format!("{}==============\n", print_all);
print_all = format!("{}{}", print_all, display_grid(&world, &robot_pool, &hash));
}
loop {
let mut piouff: u32 = 0;
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);
}
}
if world.x <= 60 && world.y <= 45 {
std::thread::sleep(std::time::Duration::from_millis(600));
print!("\x1B[2J\x1B[1;1H");
print!("{}", display_grid(&world, &robot_pool, &hash));
}
if piouff == robot_pool.len() as u32 {
break;
}
}
print!("\x1B[2J\x1B[1;1H");
print!("{}", print_all);
if world.x <= 60 && world.y <= 45 {
println!("Final state");
println!("============");
print!("{}", display_grid(&world, &robot_pool, &hash));
}
for r in &robot_pool {
println!("Robot id: {}: Final position: ({}, {})", r.id, r.p.x, r.p.y);
}

View File

@ -9,7 +9,7 @@ pub struct World {
/// Create a random World.
pub fn random_world() -> World {
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 }
}