mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Legger til forbedring av posisjonssjekking i Board
This commit is contained in:
parent
a86b4efbb7
commit
f22e577180
@ -187,14 +187,20 @@ 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) {
|
||||||
try {
|
return hasWallFacing(robotPosition, direction) || (isValidPosition(newPosition) &&
|
||||||
return hasWallFacing(robotPosition, direction) ||
|
hasWallFacing(newPosition, Direction.getReverseDirection(direction)));
|
||||||
hasWallFacing(newPosition, Direction.getReverseDirection(direction));
|
}
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a given position is valid
|
||||||
|
* @param position The position to test
|
||||||
|
* @return True if the position is valid. False otherwise
|
||||||
|
*/
|
||||||
|
private boolean isValidPosition(Position position) {
|
||||||
|
return position.getXCoordinate() >= 0
|
||||||
|
&& position.getXCoordinate() < boardWidth
|
||||||
|
&& position.getYCoordinate() >= 0
|
||||||
|
&& position.getYCoordinate() < boardHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,10 +210,7 @@ public class Board {
|
|||||||
* @return True if the robot was killed for leaving the board
|
* @return True if the robot was killed for leaving the board
|
||||||
*/
|
*/
|
||||||
private boolean killRobotIfGoesOutsideMap(Robot robot, Position newPosition) {
|
private boolean killRobotIfGoesOutsideMap(Robot robot, Position newPosition) {
|
||||||
if (newPosition.getXCoordinate() < 0
|
if (!isValidPosition(newPosition)) {
|
||||||
|| newPosition.getXCoordinate() >= boardWidth
|
|
||||||
|| newPosition.getYCoordinate() < 0
|
|
||||||
|| newPosition.getYCoordinate() >= boardHeight) {
|
|
||||||
killRobot(robot);
|
killRobot(robot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user