diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 05c471b..3ecc739 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -133,14 +133,14 @@ public class Board { Robot robot = robots.get(robotID); Position robotPosition = robot.getPosition(); Position newPosition = getNewPosition(robotPosition, direction); - //Robot tried to go outside of the map. Kill it. - if (killRobotIfGoesOutsideMap(robot, newPosition)) { - return true; - } //There is a wall blocking the robot. It can't proceed. if (robotMoveIsStoppedByWall(robotPosition, newPosition, direction)) { return false; } + //Robot tried to go outside of the map. Kill it. + if (killRobotIfGoesOutsideMap(robot, newPosition)) { + return true; + } //If another robot is blocking this robot's path, try to shove it. if (hasRobotOnPosition(newPosition)) { RobotID otherRobotID = getRobotOnPosition(newPosition); @@ -187,8 +187,14 @@ public class Board { * @return True if a wall would stop its path */ private boolean robotMoveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) { - return hasWallFacing(robotPosition, direction) || - hasWallFacing(newPosition, Direction.getReverseDirection(direction)); + try { + return hasWallFacing(robotPosition, direction) || + hasWallFacing(newPosition, Direction.getReverseDirection(direction)); + } + catch (IllegalArgumentException e) { + return false; + } + } /** diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 46554bd..54ea4f6 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -105,46 +105,27 @@ public class RoboRallyGame implements IDrawableGame { private void runGameLoop() throws InterruptedException { TimeUnit.SECONDS.sleep(3); makeMove(RobotID.ROBOT_1, Action.MOVE_1); - makeMove(RobotID.ROBOT_1, Action.MOVE_2); - makeMove(RobotID.ROBOT_1, Action.BACK_UP); - makeMove(RobotID.ROBOT_1, Action.BACK_UP); - makeMove(RobotID.ROBOT_1, Action.MOVE_3); - makeMove(RobotID.ROBOT_1, Action.ROTATE_LEFT); - makeMove(RobotID.ROBOT_1, Action.U_TURN); - makeMove(RobotID.ROBOT_1, Action.ROTATE_RIGHT); - makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT); - makeMove(RobotID.ROBOT_2, Action.MOVE_3); - makeMove(RobotID.ROBOT_2, Action.MOVE_3); - makeMove(RobotID.ROBOT_2, Action.BACK_UP); - makeMove(RobotID.ROBOT_2, Action.U_TURN); - makeMove(RobotID.ROBOT_2, Action.BACK_UP); - makeMove(RobotID.ROBOT_2, Action.BACK_UP); - makeMove(RobotID.ROBOT_2, Action.BACK_UP); - makeMove(RobotID.ROBOT_2, Action.MOVE_3); - makeMove(RobotID.ROBOT_2, Action.BACK_UP); - makeMove(RobotID.ROBOT_2, Action.BACK_UP); - makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT); - makeMove(RobotID.ROBOT_2, Action.U_TURN); + makeMove(RobotID.ROBOT_2, Action.MOVE_1); } /**