Fikser #68 Closes #68

This commit is contained in:
Kristian Knarvik 2020-04-21 16:19:51 +02:00
parent cf8c04dc17
commit 417681d1e2
2 changed files with 8 additions and 4 deletions

View File

@ -329,6 +329,9 @@ public class Board {
return true;
}
Position positionInFront = getNewPosition(conveyorBeltPosition, conveyorBeltDirection);
if (!isValidPosition(positionInFront)) {
return true;
}
Tile tileInFront = getTileOnPosition(positionInFront);
//If a conveyor belt will move the robot outside the map, the move is valid
if (!isValidPosition(positionInFront)) {
@ -564,7 +567,7 @@ public class Board {
* @param position The position to test
* @return True if the position is valid. False otherwise
*/
private boolean isValidPosition(Position position) {
public boolean isValidPosition(Position position) {
return position.getXCoordinate() >= 0
&& position.getXCoordinate() < boardWidth
&& position.getYCoordinate() >= 0

View File

@ -128,10 +128,11 @@ public class Phase {
if (!gameBoard.hasRobotOnPosition(cogwheel.getPosition())) {
continue;
}
RobotID robotAtCogwheel = gameBoard.getRobotOnPosition(cogwheel.getPosition());
if (cogwheel.getElement().getTileType() == TileType.COGWHEEL_RIGHT) {
gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
gameBoard.rotateRobotRight(robotAtCogwheel);
} else {
gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
gameBoard.rotateRobotLeft(robotAtCogwheel);
}
}
}
@ -269,7 +270,7 @@ public class Phase {
Map<RobotID, Position> newPositions, Map<RobotID, Boolean> moveNormally) {
RobotID robotAtConveyorBelt = gameBoard.getRobotOnPosition(conveyorBeltPosition);
Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltDirection);
if (gameBoard.isConveyorBelt(gameBoard.getTileOnPosition(newPosition))) {
if (gameBoard.isValidPosition(newPosition) && gameBoard.isConveyorBelt(gameBoard.getTileOnPosition(newPosition))) {
newPositions.put(robotAtConveyorBelt, newPosition);
moveNormally.put(robotAtConveyorBelt, false);
Direction newDirection = gameBoard.getTileOnPosition(newPosition).getDirection();