mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Fikser bug der robot kan gå forbi vegger som er på kanten av brettet.
This commit is contained in:
parent
4d309d4321
commit
a86b4efbb7
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user