working main-loop

This commit is contained in:
Volodymyr Patuta 2020-10-31 20:21:21 +01:00
parent a470e883af
commit 60a721742a

View File

@ -220,19 +220,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
loop { loop {
let mut piouff: u32 = 0; let mut piouff: u32 = 0;
for mut r in robot_pool { for r in &mut robot_pool {
if robot::is_piouff(&r) { if robot::is_piouff(&r) {
piouff += 1; piouff += 1;
} else { } else {
hash.remove(&r.p);
r.execute_instruction(); r.execute_instruction();
check_map(&r, &world)?;
check_collisions(&r, &hash)?;
hash.insert(robot::Position { x: r.p.x, y: r.p.y }, r.id);
} }
check_map(&r, &world)?;
check_collisions(&r, &hash)?;
} }
if piouff == robot_pool.len() as u32 { if piouff == robot_pool.len() as u32 {
break; break;
} }
} }
for r in &robot_pool {
println!("Robot id: {}: Final position: ({}, {})", r.id, r.p.x, r.p.y);
}
Ok(()) Ok(())
} }