completed move functions

This commit is contained in:
Volodymyr Patuta 2020-10-26 20:15:44 +01:00
parent 80dfe2d69e
commit f7d86c9991
1 changed files with 6 additions and 4 deletions

View File

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