13 package host.labyrinth;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.function.IntFunction;
39 walls =
new ArrayList<Edge>();
40 moves =
new ArrayList<Integer[]>();
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>();
57 moves =
new ArrayList<Integer[]>();
83 for (Integer[] m : b.
moves) {
118 String[][] frame =
new String[2*
N+1][
N];
120 for (
int row=0 ; row<
N ; ++row) {
122 for (col =0 ; col<N-1 ; ++col)
123 renderTile(frame, row, col, theseusTile, minotaurTile);
139 for (
int i=sBoard.length-1 ; i>=0 ; --i) {
140 for (String it : sBoard[i])
141 System.out.print(it);
142 System.out.println();
231 for (Integer[] m :
moves) {
233 ret[ri++] = Arrays.stream(m).mapToInt(i->i).toArray();
245 return moves.size() -1;
259 moves.set(playerId, Arrays.stream(m).boxed().toArray(Integer[]::
new));
367 for (
int tileId, i=0 ; i<
supplies.length ; ++i) {
371 while (tileId == theseusTile || tileId == minotaurTile);
389 ArrayList<Edge> w =
new ArrayList<Edge>();
397 for (
int i =0,
S=w.size() ; i<
S ; ++i)
402 }
while (size != w.size());
407 for (
Edge it : walls) {
408 if (g.
count(it.getV1()) > 1)
return true;
409 if (g.
count(it.getV2()) > 1)
return true;
488 for (
int i =0 ; i<
tiles.length ; ++i) {
493 wallCount += ((up?1:0) + (down?1:0) + (left?1:0) + (right?1:0));
494 tiles[i] =
new Tile (i, up, down, left, right);
515 dir = randDirections.
get();
533 for (
int tileId,
walls =0, shuffleMark =0 ; true ; ) {
537 if (
walls == shuffleMark)
559 private String
getTileBody (
int row,
int col,
int theseusTile,
int minotaurTile) {
561 boolean T = (tileId == theseusTile) ?
true :
false;
562 boolean M = (tileId == minotaurTile) ?
true :
false;
565 if (T && !M)
return " T ";
566 else if (T && M)
return "T+M";
572 return String.format(
"s%02d", S+1);
585 private void renderTile(String[][] frame,
int row,
int col,
int theseusTile,
int minotaurTile) {
586 IntFunction<Integer> toframe = (r)->{
return 2*r+1; };
591 +
getTileBody(row, col, theseusTile, minotaurTile);
605 private void renderSentinelTile(String[][] frame,
int row,
int col,
int theseusTile,
int minotaurTile ) {
606 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.
int [][] getOpponentMoves(int playerId)
Boards utility to give access to other player moves.
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 createBasicTileWalls()
This utility function create/allocate the tiles of the board and create the outer walls at the same t...
ArrayList< Integer[]> moves
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.
void setMoves(ArrayList< Integer[]> moves)
IntFunction< Integer > rightTileId
ArrayList< Edge > walls
Array to hold all the walls using the edge representation required by the closed room preventing algo...
ArrayList< Integer[]> getMoves()
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.
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.
static final int moveItems
The number of items return by move()
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 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.