mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +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);
|
Robot robot = robots.get(robotID);
|
||||||
Position robotPosition = robot.getPosition();
|
Position robotPosition = robot.getPosition();
|
||||||
Position newPosition = getNewPosition(robotPosition, direction);
|
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.
|
//There is a wall blocking the robot. It can't proceed.
|
||||||
if (robotMoveIsStoppedByWall(robotPosition, newPosition, direction)) {
|
if (robotMoveIsStoppedByWall(robotPosition, newPosition, direction)) {
|
||||||
return false;
|
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 another robot is blocking this robot's path, try to shove it.
|
||||||
if (hasRobotOnPosition(newPosition)) {
|
if (hasRobotOnPosition(newPosition)) {
|
||||||
RobotID otherRobotID = getRobotOnPosition(newPosition);
|
RobotID otherRobotID = getRobotOnPosition(newPosition);
|
||||||
@ -187,8 +187,14 @@ public class Board {
|
|||||||
* @return True if a wall would stop its path
|
* @return True if a wall would stop its path
|
||||||
*/
|
*/
|
||||||
private boolean robotMoveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) {
|
private boolean robotMoveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) {
|
||||||
return hasWallFacing(robotPosition, direction) ||
|
try {
|
||||||
hasWallFacing(newPosition, Direction.getReverseDirection(direction));
|
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 {
|
private void runGameLoop() throws InterruptedException {
|
||||||
TimeUnit.SECONDS.sleep(3);
|
TimeUnit.SECONDS.sleep(3);
|
||||||
makeMove(RobotID.ROBOT_1, Action.MOVE_1);
|
makeMove(RobotID.ROBOT_1, Action.MOVE_1);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_1, Action.MOVE_2);
|
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.BACK_UP);
|
makeMove(RobotID.ROBOT_1, Action.BACK_UP);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_1, Action.MOVE_3);
|
makeMove(RobotID.ROBOT_1, Action.MOVE_3);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_1, Action.ROTATE_LEFT);
|
makeMove(RobotID.ROBOT_1, Action.ROTATE_LEFT);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_1, Action.U_TURN);
|
makeMove(RobotID.ROBOT_1, Action.U_TURN);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_1, Action.ROTATE_RIGHT);
|
makeMove(RobotID.ROBOT_1, Action.ROTATE_RIGHT);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT);
|
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.MOVE_3);
|
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.U_TURN);
|
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.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.MOVE_3);
|
||||||
|
|
||||||
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.BACK_UP);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT);
|
makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT);
|
||||||
|
|
||||||
makeMove(RobotID.ROBOT_2, Action.U_TURN);
|
makeMove(RobotID.ROBOT_2, Action.U_TURN);
|
||||||
|
makeMove(RobotID.ROBOT_2, Action.MOVE_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user