Commit 2394801
Changed files (1)
src
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);
}