diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Q9/MovingRobot.java | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/src/Q9/MovingRobot.java b/src/Q9/MovingRobot.java index 03d67c9..aa3ff6e 100644 --- a/src/Q9/MovingRobot.java +++ b/src/Q9/MovingRobot.java @@ -4,7 +4,6 @@ import java.util.*; public class MovingRobot extends Robot { private ArrayList<Integer> moves = new ArrayList<Integer>(); - private int nextMove; private Random rng; public MovingRobot(int x, int y) { @@ -12,10 +11,6 @@ public class MovingRobot extends Robot { this.rng = new Random(); } - public boolean validateNextMove() { - return validateNextMove(nextMove); - } - public boolean validateNextMove(int direction) { switch (direction) { case Robot.NORTH: @@ -55,9 +50,7 @@ public class MovingRobot extends Robot { public void move() { int direction = generateNextMove(); - // if (!validateNextMove(direction)) this.move(); - - // this.nextMove = direction; + while (!validateNextMove(direction)) direction = generateNextMove(); this.move(direction); } @@ -143,6 +136,8 @@ public class MovingRobot extends Robot { System.out.println( String.format("R1 (%d, %d), R2: (%d, %d)", r1.getX(), r1.getY(), r2.getX(), r2.getY())); System.out.println(Robot.printGrid(r1, r2)); + System.out.println(String.format("R1 Route: [%s]", r1.printMoves())); + System.out.println(String.format("R2 Route: [%s]", r2.printMoves())); sleep(1000); } |
