mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Legger til automatisk rotasjon av brett med større bredde enn høyde
This commit is contained in:
parent
a1c8b495b8
commit
979703bcf9
@ -51,6 +51,26 @@ public final class BoardLoaderUtil {
|
|||||||
return boards;
|
return boards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a board described in a file
|
||||||
|
*
|
||||||
|
* @param boardFile The file containing the board description
|
||||||
|
* @param robotList A list of robots on the board
|
||||||
|
* @return A board
|
||||||
|
* @throws IOException If the board file cannot be loaded
|
||||||
|
*/
|
||||||
|
public static Board loadBoard(String boardFile, List<Robot> robotList) throws IOException {
|
||||||
|
TwoTuple<Grid<Tile>, Grid<Wall>> grids = loadBoardGrids(boardFile);
|
||||||
|
Grid<Tile> tileGrid = grids.value1;
|
||||||
|
Grid<Wall> wallGrid = grids.value2;
|
||||||
|
if (grids.value1.getHeight() < grids.value1.getWidth()) {
|
||||||
|
tileGrid = rotateGrid(tileGrid, true);
|
||||||
|
wallGrid = rotateGrid(wallGrid, true);
|
||||||
|
}
|
||||||
|
adjustRobotRotationToBoardRotation(tileGrid, robotList);
|
||||||
|
return new Board(tileGrid, wallGrid, robotList);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of all available boards
|
* Gets a list of all available boards
|
||||||
*
|
*
|
||||||
@ -69,21 +89,6 @@ public final class BoardLoaderUtil {
|
|||||||
return boardList;
|
return boardList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads and rotates a board described in a file
|
|
||||||
*
|
|
||||||
* @param boardFile The file containing the board description
|
|
||||||
* @param robotList A list of robots on the board
|
|
||||||
* @param clockwise Whether to rotate the board clockwise
|
|
||||||
* @return A board
|
|
||||||
* @throws IOException If the board file cannot be loaded
|
|
||||||
*/
|
|
||||||
public static Board loadBoardRotated(String boardFile, List<Robot> robotList, boolean clockwise) throws IOException {
|
|
||||||
TwoTuple<Grid<Tile>, Grid<Wall>> grids = loadBoardGrids(boardFile);
|
|
||||||
adjustRobotRotationToBoardRotation(grids.value1, robotList);
|
|
||||||
return new Board(rotateGrid(grids.value1, clockwise), rotateGrid(grids.value2, clockwise), robotList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the grids necessary to create a board
|
* Loads the grids necessary to create a board
|
||||||
*
|
*
|
||||||
@ -138,20 +143,6 @@ public final class BoardLoaderUtil {
|
|||||||
return newGrid;
|
return newGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a board described in a file
|
|
||||||
*
|
|
||||||
* @param boardFile The file containing the board description
|
|
||||||
* @param robotList A list of robots on the board
|
|
||||||
* @return A board
|
|
||||||
* @throws IOException If the board file cannot be loaded
|
|
||||||
*/
|
|
||||||
public static Board loadBoard(String boardFile, List<Robot> robotList) throws IOException {
|
|
||||||
TwoTuple<Grid<Tile>, Grid<Wall>> grids = loadBoardGrids(boardFile);
|
|
||||||
adjustRobotRotationToBoardRotation(grids.value1, robotList);
|
|
||||||
return new Board(grids.value1, grids.value2, robotList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the direction of robots to the direction which is up
|
* Changes the direction of robots to the direction which is up
|
||||||
*
|
*
|
||||||
@ -159,13 +150,13 @@ public final class BoardLoaderUtil {
|
|||||||
* @param robotList The list of robots on the board
|
* @param robotList The list of robots on the board
|
||||||
*/
|
*/
|
||||||
private static void adjustRobotRotationToBoardRotation(Grid<Tile> tileGrid, List<Robot> robotList) {
|
private static void adjustRobotRotationToBoardRotation(Grid<Tile> tileGrid, List<Robot> robotList) {
|
||||||
//The flags are always in the up direction
|
//The spawns are always in the up direction
|
||||||
List<BoardElementContainer<Tile>> flags = GridUtil.getMatchingElements(TileType.ROBOT_SPAWN_1, tileGrid);
|
List<BoardElementContainer<Tile>> spawns = GridUtil.getMatchingElements(TileType.ROBOT_SPAWN_1, tileGrid);
|
||||||
Direction boardDirection;
|
Direction boardDirection;
|
||||||
if (flags.size() == 0) {
|
if (spawns.size() == 0) {
|
||||||
boardDirection = Direction.NORTH;
|
boardDirection = Direction.NORTH;
|
||||||
} else {
|
} else {
|
||||||
boardDirection = flags.get(0).getElement().getDirection();
|
boardDirection = spawns.get(0).getElement().getDirection();
|
||||||
}
|
}
|
||||||
for (Robot robot : robotList) {
|
for (Robot robot : robotList) {
|
||||||
robot.setFacingDirection(boardDirection);
|
robot.setFacingDirection(boardDirection);
|
||||||
|
@ -86,21 +86,21 @@ public class PhaseTest {
|
|||||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||||
robot.setHasTouchedFlagThisTurn(false);
|
robot.setHasTouchedFlagThisTurn(false);
|
||||||
assertNull(testGame.getWinningPlayerName());
|
assertNull(testGame.getWinningPlayerName());
|
||||||
board.moveRobot(robotID, Direction.EAST);
|
board.moveRobot(robotID, Direction.SOUTH);
|
||||||
testPhase.checkAllFlags();
|
testPhase.checkAllFlags();
|
||||||
//Should have registered second flag
|
//Should have registered second flag
|
||||||
assertEquals(2, robot.getLastFlagVisited());
|
assertEquals(2, robot.getLastFlagVisited());
|
||||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||||
assertNull(testGame.getWinningPlayerName());
|
assertNull(testGame.getWinningPlayerName());
|
||||||
robot.setHasTouchedFlagThisTurn(false);
|
robot.setHasTouchedFlagThisTurn(false);
|
||||||
board.moveRobot(robotID, Direction.EAST);
|
board.moveRobot(robotID, Direction.SOUTH);
|
||||||
testPhase.checkAllFlags();
|
testPhase.checkAllFlags();
|
||||||
//Should have registered third flag
|
//Should have registered third flag
|
||||||
assertEquals(3, robot.getLastFlagVisited());
|
assertEquals(3, robot.getLastFlagVisited());
|
||||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||||
assertNull(testGame.getWinningPlayerName());
|
assertNull(testGame.getWinningPlayerName());
|
||||||
robot.setHasTouchedFlagThisTurn(false);
|
robot.setHasTouchedFlagThisTurn(false);
|
||||||
board.moveRobot(robotID, Direction.EAST);
|
board.moveRobot(robotID, Direction.SOUTH);
|
||||||
testPhase.checkAllFlags();
|
testPhase.checkAllFlags();
|
||||||
//Should have registered fourth and last flag
|
//Should have registered fourth and last flag
|
||||||
assertEquals(4, robot.getLastFlagVisited());
|
assertEquals(4, robot.getLastFlagVisited());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user