Labyrinth
A labyrinth game assignment
|
This class is the representation of the games's board. More...
Package Functions | |
Constructors | |
Board () | |
The empty constructor for default initialization. More... | |
Board (int N, int S) | |
The main constructor for the application. More... | |
Board (Board b) | |
Deep copy constructor. More... | |
Board's main application interface | |
void | createBoard (int theseusTile, int minotaurTile) |
Creates the board with all the requested walls and supplies. More... | |
String [][] | getStringRepresentation (int theseusTile, int minotaurTile) |
Returns a 2-D array with the string representation of the board. More... | |
void | printBoard (String[][] sBoard) |
Print board utility. More... | |
boolean | isWalkable (int tileId, int direction) |
Predicate to check if a direction is Walkable. More... | |
boolean | isWalkable (int row, int col, int direction) |
Predicate to check if a direction is Walkable. More... | |
boolean | hasSupply (int tileId) |
Utility function to check if there is a supply on the tile or not. More... | |
int | tryPickSupply (int tileId) |
Try to pick supply from a tile. More... | |
int | dice () |
A plain fair dice functionality provided by the board. More... | |
int | size () |
int | generatePlayerId () throws Exception |
Utility function to create player IDs. More... | |
int | getOpponentId (int playerId) |
Boards utility to give access to other player Id. More... | |
int [] | getOpponentMove (int playerId) |
Boards utility to give access to other player moves. More... | |
void | updateMove (int[] m, int playerId) |
Utility to update the moves of each player. More... | |
Accessor/Mutator interface | |
| |
int | getN () |
int | getS () |
int | getW () |
Tile [] | getTiles () |
Supply [] | getSupplies () |
ArrayList< Edge > | getWalls () |
int [][] | getMoves () |
void | setN (int N) |
void | setS (int S) |
void | setW (int W) |
void | setTiles (Tile[] tiles) |
void | setSupplies (Supply[] supplies) |
void | setWalls (ArrayList< Edge > walls) |
void | setMoves (int[][] moves) |
Private Member Functions | |
Sentinel predicates | |
boolean | isLeftSentinel (int tileId) |
boolean | isRightSentinel (int tileId) |
boolean | isUpSentinel (int tileId) |
boolean | isDownSentinel (int tileId) |
private functionality of the object | |
void | createTiles () |
This function creates randomly all the tiles of the board. More... | |
void | createSupplies (int theseusTile, int minotaurTile) |
This function create randomly the board's supplies. More... | |
boolean | isRoomCreator (int tileId, int direction) |
Predicate to check if a wall creates a closed room. More... | |
boolean | isWallableDir (int tileId, int direction) |
Predicate to check if a tile direction is Wallable . More... | |
boolean | isWallable (int tileId) |
Predicate to check if a tile is Wallable . More... | |
int | createBasicTileWalls () |
This utility function create/allocate the tiles of the board and create the outer walls at the same time. More... | |
void | createInnerWall (int tileId) |
Create randomly a wall in the wallable selected tile. More... | |
int | createInnerWalls () |
This utility creates the inner walls of the board. More... | |
String | getTileBody (int row, int col, int theseusTile, int minotaurTile) |
Utility to get the body (center line) of the string representation of the tile. More... | |
void | renderTile (String[][] frame, int row, int col, int theseusTile, int minotaurTile) |
Utility to render the 3 strings of the tile in the representation frame. More... | |
void | renderSentinelTile (String[][] frame, int row, int col, int theseusTile, int minotaurTile) |
Utility to render the 3 strings of the tile in the representation frame in the case the tile lies in the east wall. More... | |
Private Attributes | |
Neighbor access lambdas | |
IntFunction< Integer > | leftTileId = (id) -> { return Position.toID(Position.toRow(id), Position.toCol(id)-1); } |
IntFunction< Integer > | rightTileId = (id) -> { return Position.toID(Position.toRow(id), Position.toCol(id)+1); } |
IntFunction< Integer > | upTileId = (id) -> { return Position.toID(Position.toRow(id)+1, Position.toCol(id) ); } |
IntFunction< Integer > | downTileId = (id) -> { return Position.toID(Position.toRow(id)-1, Position.toCol(id) ); } |
Class data | |
int | N |
The size of each edge of the board. More... | |
int | S |
The number of the supplies on the board. More... | |
int | W |
The number of walls on the board. More... | |
Tile [] | tiles |
Array to hold all the tiles for the board. More... | |
Supply [] | supplies |
Array to hold all the supplies on the board. More... | |
ArrayList< Edge > | walls |
Array to hold all the walls using the edge representation required by the closed room preventing algorithm. More... | |
int [][] | moves |
int | playerCount |
This class is the representation of the games's board.
The board is the square arrangement of the tiles. This class is also the owner of the tile and supply objects.
Definition at line 25 of file Board.java.
|
package |
The empty constructor for default initialization.
Definition at line 32 of file Board.java.
|
package |
The main constructor for the application.
N | The size of each edge of the board |
S | The number of supplies on the board |
Definition at line 48 of file Board.java.
|
package |
Deep copy constructor.
b | The board to copy |
Definition at line 74 of file Board.java.
|
private |
This utility function create/allocate the tiles of the board and create the outer walls at the same time.
Definition at line 504 of file Board.java.
|
package |
Creates the board with all the requested walls and supplies.
theseusTile | |
minotaurTile |
Definition at line 110 of file Board.java.
|
private |
Create randomly a wall in the wallable selected tile.
tileId | The wallable tile to create the wall |
Definition at line 528 of file Board.java.
|
private |
This utility creates the inner walls of the board.
Definition at line 549 of file Board.java.
|
private |
This function create randomly the board's supplies.
The supplies has to be in separate tiles and in tiles with no player
theseusTile | The tile of the Theseus |
minotaurTile | The tile of the Minotaur |
Definition at line 383 of file Board.java.
|
private |
This function creates randomly all the tiles of the board.
Definition at line 368 of file Board.java.
|
package |
A plain fair dice functionality provided by the board.
Definition at line 226 of file Board.java.
|
package |
Utility function to create player IDs.
Definition at line 238 of file Board.java.
|
package |
Definition at line 316 of file Board.java.
|
package |
Definition at line 288 of file Board.java.
|
package |
Boards utility to give access to other player Id.
playerId | The id of player who asks |
Definition at line 251 of file Board.java.
|
package |
Boards utility to give access to other player moves.
playerId | The id of player who asks |
Definition at line 261 of file Board.java.
|
package |
Definition at line 289 of file Board.java.
|
package |
Returns a 2-D array with the string representation of the board.
The rows of the array represent the Y-coordinate and the columns the X-coordinate. The only difference is that between each row there is an extra row with the possible walls. This way the number of rows of the returning array are 2N+1 and the number of columns N+1.
So each tile of the board is represented by 3 strings. One for the north wall, one for the body and one for the south wall.
theseusTile | The current Theseus tile |
minotaurTile | The current Minotaur tile |
Definition at line 129 of file Board.java.
|
package |
Definition at line 302 of file Board.java.
|
private |
Utility to get the body (center line) of the string representation of the tile.
row | What board's row to get. |
col | What board's column to get. |
theseusTile | The current tile of the Theseus. |
minotaurTile | The current tile of the Minotaur. |
Definition at line 577 of file Board.java.
|
package |
Definition at line 296 of file Board.java.
|
package |
Definition at line 290 of file Board.java.
|
package |
Definition at line 309 of file Board.java.
|
package |
Utility function to check if there is a supply on the tile or not.
tileId | The tile to check |
Definition at line 200 of file Board.java.
|
private |
Definition at line 357 of file Board.java.
|
private |
Definition at line 354 of file Board.java.
|
private |
Definition at line 355 of file Board.java.
|
private |
Predicate to check if a wall creates a closed room.
This algorithm has a complexity of where N represents the total number of tiles. It should be used with care.
tileId | The tileId of the wall. |
direction | The wall's relative direction. |
Definition at line 405 of file Board.java.
|
private |
Definition at line 356 of file Board.java.
|
package |
Predicate to check if a direction is Walkable.
A walkable
direction is a tile direction where:
tileId | The starting tileId. |
direction | The desired direction. |
Definition at line 171 of file Board.java.
|
package |
Predicate to check if a direction is Walkable.
A walkable
direction is a tile direction where:
row | Row position of the starting tile. |
col | Column position of the starting tile. |
direction | The desired direction. |
Definition at line 190 of file Board.java.
|
private |
Predicate to check if a tile is Wallable
.
A wallable
tile is a tile where:
Const.maxTileWalls -1
walls. tileId | The tile to check |
Definition at line 484 of file Board.java.
|
private |
Predicate to check if a tile direction is Wallable
.
A wallable
direction is a tile direction where:
Const.maxTileWalls -1
walls. tileId | The tile to check. |
direction | The direction to check |
Definition at line 450 of file Board.java.
|
package |
Print board utility.
sBoard | Reference to string representation of the board to print. |
Definition at line 150 of file Board.java.
|
private |
Utility to render the 3 strings of the tile in the representation frame in the case the tile lies in the east wall.
We call these tiles sentinel tiles
frame | Reference to the frame to print into. |
row | The board's row to print. |
col | The board's column to print. |
theseusTile | The current tile of the Theseus. |
minotaurTile | The current tile of the Minotaur. |
Definition at line 623 of file Board.java.
|
private |
Utility to render the 3 strings of the tile in the representation frame.
frame | Reference to the frame to print into. |
row | The board's row to print. |
col | The board's column to print. |
theseusTile | The current tile of the Theseus. |
minotaurTile | The current tile of the Minotaur. |
Definition at line 603 of file Board.java.
|
package |
moves | Reference to moves that we want to act as replacement for the inner moves vector. |
Definition at line 347 of file Board.java.
|
package |
Definition at line 318 of file Board.java.
|
package |
Definition at line 319 of file Board.java.
|
package |
supplies | Reference to supplies that we want to act as replacement for the inner supplies array. |
Definition at line 333 of file Board.java.
|
package |
tiles | Reference to tiles that we want to act as replacement for the inner tiles array. |
Definition at line 327 of file Board.java.
|
package |
Definition at line 320 of file Board.java.
|
package |
walls | Reference to walls that we want to act as replacement for the inner walls vector. |
Definition at line 340 of file Board.java.
|
package |
Definition at line 232 of file Board.java.
|
package |
Try to pick supply from a tile.
If succeed it also erases the supply from the board.
tileId | The tile to check |
Definition at line 213 of file Board.java.
|
package |
Utility to update the moves of each player.
This function is used by the players to update their position on the board. After that a player can read other player positions using getOpponentMoves()
m | Reference to new move data |
playerId | The id of the player who update his/her data. |
Definition at line 275 of file Board.java.
|
private |
Definition at line 640 of file Board.java.
|
private |
Definition at line 637 of file Board.java.
|
private |
Definition at line 654 of file Board.java.
|
private |
The size of each edge of the board.
Definition at line 645 of file Board.java.
|
private |
Definition at line 655 of file Board.java.
|
private |
Definition at line 638 of file Board.java.
|
private |
The number of the supplies on the board.
Definition at line 646 of file Board.java.
|
private |
Array to hold all the supplies on the board.
Definition at line 649 of file Board.java.
|
private |
Array to hold all the tiles for the board.
Definition at line 648 of file Board.java.
|
private |
Definition at line 639 of file Board.java.
|
private |
The number of walls on the board.
Definition at line 647 of file Board.java.
|
private |
Array to hold all the walls using the edge representation required by the closed room preventing algorithm.
Definition at line 650 of file Board.java.