13 package host.labyrinth;
15 import java.util.ArrayList;
16 import java.util.function.IntFunction;
38 walls =
new ArrayList<Edge>();
49 assert (N%2 != 0) :
"Board's size has to be an odd number.";
50 assert (S <= (N*N-2)) :
"At least 2 tiles has to be without supplies.";
56 walls =
new ArrayList<Edge>();
81 walls =
new ArrayList<Edge>();
86 for (
int i=0 ; i<b.
moves.length ; ++i)
87 this.moves[i] = b.
moves[i].clone();
90 for (
int i=0 ; i<b.
tiles.length ; ++i)
92 for (
int i=0 ; i<b.
supplies.length ; ++i)
130 String[][] frame =
new String[2*
N+1][
N];
132 for (
int row=0 ; row<
N ; ++row) {
134 for (col =0 ; col<N-1 ; ++col)
135 renderTile(frame, row, col, theseusTile, minotaurTile);
151 for (
int i=sBoard.length-1 ; i>=0 ; --i) {
152 for (String it : sBoard[i])
153 System.out.print(it);
154 System.out.println();
242 throw new Exception(
"Maximum number of players exceeded");
385 for (
int tileId, i=0 ; i<
supplies.length ; ++i) {
389 while (tileId == theseusTile || tileId == minotaurTile);
407 ArrayList<Edge> w =
new ArrayList<Edge>();
415 for (
int i =0,
S=w.size() ; i<
S ; ++i)
420 }
while (size != w.size());
425 for (
Edge it : walls) {
426 if (g.
count(it.getV1()) > 1)
return true;
427 if (g.
count(it.getV2()) > 1)
return true;
506 for (
int i =0 ; i<
tiles.length ; ++i) {
511 wallCount += ((up?1:0) + (down?1:0) + (left?1:0) + (right?1:0));
512 tiles[i] =
new Tile (i, up, down, left, right);
533 dir = randDirections.
get();
551 for (
int tileId,
walls =0, shuffleMark =0 ; true ; ) {
555 if (
walls == shuffleMark)
577 private String
getTileBody (
int row,
int col,
int theseusTile,
int minotaurTile) {
579 boolean T = (tileId == theseusTile) ?
true :
false;
580 boolean M = (tileId == minotaurTile) ?
true :
false;
583 if (T && !M)
return " T ";
584 else if (T && M)
return "T+M";
590 return String.format(
"s%02d", S+1);
603 private void renderTile(String[][] frame,
int row,
int col,
int theseusTile,
int minotaurTile) {
604 IntFunction<Integer> toframe = (r)->{
return 2*r+1; };
609 +
getTileBody(row, col, theseusTile, minotaurTile);
623 private void renderSentinelTile(String[][] frame,
int row,
int col,
int theseusTile,
int minotaurTile ) {
624 IntFunction<Integer> toframe = (r)->{
return 2*r+1; };
Board()
The empty constructor for default initialization.
This class is the representation of the supplies in the game.
boolean isWallable(int tileId)
Predicate to check if a tile is Wallable.
IntFunction< Integer > upTileId
static final int RIGHT
East direction.
int hasWalls()
Checks if the tile has walls and return the number of them.
void createBoard(int theseusTile, int minotaurTile)
Creates the board with all the requested walls and supplies.
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 ...
This class is the representation of the games's board.
Class to hold constant values for entire application.
void pickSupply(Supply[] supplies, int supplyId)
Utility to find a supply in the supplies array and removes it.
Board(Board b)
Deep copy constructor.
int getOpponentId(int playerId)
Boards utility to give access to other player Id.
int createBasicTileWalls()
This utility function create/allocate the tiles of the board and create the outer walls at the same t...
void setSupplies(Supply[] supplies)
Helper C++-like enumerator class to hold direction.
void createTiles()
This function creates randomly all the tiles of the board.
int W
The number of walls on the board.
static final int End
Iterator style end of range direction (one place after the last)
boolean hasWall(int direction)
Checks if the tile has wall in the requested direction.
static final int Step
Step for iterator style direction.
String [][] getStringRepresentation(int theseusTile, int minotaurTile)
Returns a 2-D array with the string representation of the board.
Tile [] tiles
Array to hold all the tiles for the board.
This class represents the game's player.
IntFunction< Integer > rightTileId
ArrayList< Edge > walls
Array to hold all the walls using the edge representation required by the closed room preventing algo...
static final int numOfPlayers
void setMoves(int[][] moves)
String getTileBody(int row, int col, int theseusTile, int minotaurTile)
Utility to get the body (center line) of the string representation of the tile.
int createInnerWalls()
This utility creates the inner walls of the board.
static final int MOVE_DATA_SIZE
Helper variables to keep track of the move() return values.
This class is the representation of the board's tile.
Provides a graph functionality for the room preventing algorithm.
Helper C++ like enumerator class for direction ranged loops.
Board(int N, int S)
The main constructor for the application.
int getId()
Read access to id coordinate.
int S
The number of the supplies on the board.
int N
The size of each edge of the board.
static int toRow(int id)
Takes Id coordinate and return the corresponding row coordinate.
Supply [] supplies
Array to hold all the supplies on the board.
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.
boolean isRoomCreator(int tileId, int direction)
Predicate to check if a wall creates a closed room.
boolean isWalkable(int row, int col, int direction)
Predicate to check if a direction is Walkable.
ArrayList< Edge > getWalls()
static final int EOR
Number to indicate the End Of Range.
boolean isLeftSentinel(int tileId)
static int toCol(int id)
Takes Id coordinate and return the corresponding column coordinate.
IntFunction< Integer > leftTileId
An Application wide board position implementation holding just the id coordinate. ...
int hasSupply(Supply[] supplies)
Utility to check if the tile has a supply.
static final int maxTileWalls
Number of maximum walls for each tile on the board.
static boolean loopGuard
When true a wall creation guard is added to prevent closed rooms inside the board.
boolean attach(Edge e)
Attach an edge into a graph IFF the graph already has a vertex with the same value as one of the vert...
boolean isUpSentinel(int tileId)
void setWalls(ArrayList< Edge > walls)
int generatePlayerId()
Utility function to create player IDs.
boolean isWallableDir(int tileId, int direction)
Predicate to check if a tile direction is Wallable.
void setWall(int direction)
Sets the tile's wall in the requested direction.
int dice()
A plain fair dice functionality provided by the board.
static final int noSupply
Number to indicate the absent of supply.
static int toID(int row, int col)
Takes row and column coordinates and return the calculated Id coordinate.
void setTiles(Tile[] tiles)
Application wide object to hold settings like values for the session.
Class to create ranges of numbers.
boolean hasSupply(int tileId)
Utility function to check if there is a supply on the tile or not.
boolean isWalkable(int tileId, int direction)
Predicate to check if a direction is Walkable.
static int boardSize
Default board's size (if no one set it via command line)
static final int LEFT
West direction.
static final int noTileId
Number to indicate wrong tileId.
A utility class used for room prevent algorithm.
int count(int v)
Counts the number of vertices on the graph with the value of v
static final int UP
North direction.
void updateMove(int[] m, int playerId)
Utility to update the moves of each player.
static int opposite(int direction)
Utility to get the opposite direction.
static final int DOWN
South direction.
void createSupplies(int theseusTile, int minotaurTile)
This function create randomly the board's supplies.
IntFunction< Integer > downTileId
void createInnerWall(int tileId)
Create randomly a wall in the wallable selected tile.
static final int Begin
Iterator style begin of range direction (starting north)
boolean isRightSentinel(int tileId)
void printBoard(String[][] sBoard)
Print board utility.
int [] getOpponentMove(int playerId)
Boards utility to give access to other player moves.
int tryPickSupply(int tileId)
Try to pick supply from a tile.
Class to create shuffled ranges of numbers.
boolean isDownSentinel(int tileId)
int get()
Extract and return the first item from the range.