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); }