From 60a721742a8352ae135bf3d179d1660e401b6125 Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Sat, 31 Oct 2020 20:21:21 +0100 Subject: [PATCH] working main-loop --- src/main.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 211ab08..61e9d8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -220,19 +220,24 @@ fn main() -> Result<(), Box> { loop { let mut piouff: u32 = 0; - for mut r in robot_pool { + for r in &mut robot_pool { if robot::is_piouff(&r) { piouff += 1; } else { + hash.remove(&r.p); 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 { break; } } + for r in &robot_pool { + println!("Robot id: {}: Final position: ({}, {})", r.id, r.p.x, r.p.y); + } Ok(()) }