From f7d86c9991fa18c6d1c7d7db8d48038eb30ca4e0 Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Mon, 26 Oct 2020 20:15:44 +0100 Subject: [PATCH] completed move functions --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 208b010..cb70b49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,7 +110,8 @@ impl Robot { } } /// Apply right instruction to the robot. - fn move_right(&mut self) { + fn move_right(&mut self, w: &mut World) { + w.map[(self.p.x + (self.p.y * w.x as i32)) as usize] = '.'; match self.o { Orientation::N => self.p.x += 1, Orientation::S => self.p.x -= 1, @@ -119,7 +120,8 @@ impl Robot { } } /// Apply left instruction to the robot. - fn move_left(&mut self) { + fn move_left(&mut self, w: &mut World) { + w.map[(self.p.x + (self.p.y * w.x as i32)) as usize] = '.'; match self.o { Orientation::N => self.p.x -= 1, Orientation::S => self.p.x += 1, @@ -307,9 +309,9 @@ mod tests { w.create(); r.move_forward(&mut w); assert_eq!(0, r.p.y); - r.move_right(); + r.move_right(&mut w); assert_eq!(2, r.p.x); - r.move_left(); + r.move_left(&mut w); assert_eq!(1, r.p.x); }