Package be.belegkarnil.game.board.tak
Class Board
java.lang.Object
be.belegkarnil.game.board.tak.Board
- All Implemented Interfaces:
Cloneable
This class represents the board of the Tak game.
This class includes some utility methods to compute neighbors positions, check if a piece can be put, and move of a
Piece.- Author:
- Belegkarnil
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefine an amount used to express that is invalid (i.e. -
Constructor Summary
ConstructorsConstructorDescriptionBoard()Construct aBoard.Size.HUGE BoardConstruct a copy of the current boardBoard(Board.Size size) Construct a board of the given size -
Method Summary
Modifier and TypeMethodDescriptionbooleanKnow if a player can make the given movebooleanKnow if a player can make the given movebooleanKnow if aPiececan be placed at a given position on the boardbooleanKnow if aPiececan be placed at a given position on the boardclone()Clone (seeCloneable) the current boardprotected static final intcomputeAmount(int[] amount) Compute total amount of a move action (path)intCount how much cells are freeintCount the initial capstones (depending on the board size) that a player has when the game startsintCount the initial stones (depending on the board size) that a player has when the game startsintcountPieces(Piece piece) Count how much times a type ofPiece(color and type) is on the boardintGet the load limit of a stack defined in the rules (i.e.getNeighbors(Point cell) Get neighbors positions of a cell in the boardintgetSize()Get the board sizePiece[]getStack(int row, int col) Get the stack ofPieces at a given position (bottom is at position 0, top at stack length -1)Piece[]Get the stack ofPieces at a given position (bottom is at position 0, top at stack length -1)getTop(int row, int col) Get the Piece (at top of a stack) at a given positionGet the Piece (at top of a stack) at a given positionbooleaninBounds(int row, int column) Know if the position is on the boardbooleanKnow if the position is on the boardbooleanKnow if the board is completed (no cells are free)booleanisFree(int row, int column) Know if the position is free on the boardbooleanKnow if the position is free on the boardstatic booleanisStraightPath(int srcRow, int srcColumn, int dstRow, int dstColumn) Know if exists a straight path (horizontal or vertical) between two positionsstatic booleanisStraightPath(Point src, Point dst) Know if exists a straight path (horizontal or vertical) between two positionsbooleanisUnderControl(Color player, int row, int column) Know if the position is under the control of a playerbooleanisUnderControl(Color player, Point point) Know if the position is under the control of a playerprotected ColorMove somePieces on the board according to the given pathbooleanpathExists(int row, int column, Color color) Know if a path exists to link left to right or top to downbooleanpathExists(Point point, Color color) Know if a path exists to link left to right or top to downprotected ColorPlace aPieceon the board at a given positionprotected voidreset()Reset the board, remove all pieces
-
Field Details
-
INVALID_AMOUNT
public static final int INVALID_AMOUNTDefine an amount used to express that is invalid (i.e. 0)- See Also:
-
-
Constructor Details
-
Board
public Board()Construct aBoard.Size.HUGE Board -
Board
Construct a board of the given size- Parameters:
size- the boardBoard.Size
-
Board
Construct a copy of the current board- Parameters:
board- The board to copy
-
-
Method Details
-
reset
protected void reset()Reset the board, remove all pieces -
inBounds
Know if the position is on the board- Parameters:
point- The position to check if it is on the board- Returns:
- true iff the position is on the board, false otherwise
-
inBounds
public boolean inBounds(int row, int column) Know if the position is on the board- Parameters:
row- The y coordinate of position to check if it is on the boardcolumn- The x coordinate of position to check if it is on the board- Returns:
- true iff the position is on the board, false otherwise
-
isFree
Know if the position is free on the board- Parameters:
point- The position to check if it is free on the board- Returns:
- true iff the position is free on the board, false otherwise
-
isFree
public boolean isFree(int row, int column) Know if the position is free on the board- Parameters:
row- The y coordinate of position to check if it is free on the boardcolumn- The x coordinate of position to check if it is free on the board- Returns:
- true iff the position is free on the board, false otherwise
-
isUnderControl
Know if the position is under the control of a player- Parameters:
player- The color of the player to checkpoint- The position to check- Returns:
- true iff the position is under the control of the player, false otherwise
-
isUnderControl
Know if the position is under the control of a player- Parameters:
player- The color of the player to checkrow- The y coordinate of position to checkcolumn- The x coordinate of position to check- Returns:
- true iff the position is under the control of the player, false otherwise
-
canPlace
Know if aPiececan be placed at a given position on the board- Parameters:
piece- ThePieceto placepoint- The position to check- Returns:
- true iff the piece can be placed, false otherwise
-
canPlace
Know if aPiececan be placed at a given position on the board- Parameters:
piece- ThePieceto placerow- The y coordinate of position to checkcolumn- The x coordinate of position to check- Returns:
- true iff the piece can be placed, false otherwise
-
isCompleted
public boolean isCompleted()Know if the board is completed (no cells are free)- Returns:
- true iff countEmpty() == 0, false otherwise
-
countEmpty
public int countEmpty()Count how much cells are free- Returns:
- Amount of free (empty) cells of the board
-
place
Place aPieceon the board at a given position -
getNeighbors
Get neighbors positions of a cell in the board- Parameters:
cell- A position on the board- Returns:
- The list of existing (i.e. inBounds(.)) positions
-
pathExists
Know if a path exists to link left to right or top to down -
pathExists
Know if a path exists to link left to right or top to down- Parameters:
row- is the y coordinate of a point on the path (i.e. newPieceorPiecemoved)column- is the x coordinate of a point on the path (i.e. newPieceorPiecemoved)color- The color of thePlayerthat attempted to create a path- Returns:
- true iff a path exists from point with the given color, false otherwise
-
canMove
Know if a player can make the given move -
computeAmount
protected static final int computeAmount(int[] amount) Compute total amount of a move action (path)- Parameters:
amount- The amount array of a move action- Returns:
- total amount iff move seems valid (i.e. each amount > 0 and amount.length > 0), false otherwise
-
canMove
public boolean canMove(Color player, int srcRow, int srcColumn, int[] amount, int dstRow, int dstColumn) Know if a player can make the given move- Parameters:
player- ThePlayer'sColor(seeConstants)srcRow- is the y coordinate of the initial position of the pathsrcColumn- is the x coordinate of the initial position of the pathamount- The amount ofPieces taken from initial position and placed along the pathdstRow- is the y coordinate of the final position of the pathdstColumn- is the x coordinate of the final position of the path- Returns:
- true iff the move is valid, false otherwise
-
isStraightPath
public static boolean isStraightPath(int srcRow, int srcColumn, int dstRow, int dstColumn) Know if exists a straight path (horizontal or vertical) between two positions- Parameters:
srcRow- is the y coordinate of the initial position of the pathsrcColumn- is the x coordinate of the initial position of the pathdstRow- is the y coordinate of the final position of the pathdstColumn- is the x coordinate of the final position of the path- Returns:
- true iff the path is going straight, false otherwise
-
isStraightPath
Know if exists a straight path (horizontal or vertical) between two positions- Parameters:
src- The initial position of the pathdst- The final position of the path- Returns:
- true iff the path is going straight, false otherwise
-
move
Move somePieces on the board according to the given path -
getLoadLimit
public int getLoadLimit()Get the load limit of a stack defined in the rules (i.e. board size)- Returns:
- The maximum load of each stack
-
getSize
public int getSize()Get the board size- Returns:
- The board size
-
countPieces
Count how much times a type ofPiece(color and type) is on the board- Parameters:
piece- APiece(color and type) that defines the type- Returns:
- the counter
-
getStack
Get the stack ofPieces at a given position (bottom is at position 0, top at stack length -1)- Parameters:
row- The y coordinate of the position to fetch the stackcol- The x coordinate of the position to fetch the stack- Returns:
- A copy of
Pieces that are at the given position
-
getStack
Get the stack ofPieces at a given position (bottom is at position 0, top at stack length -1)- Parameters:
position- The position to fetch the stack- Returns:
- A copy of
Pieces that are at the given position
-
getTop
Get the Piece (at top of a stack) at a given position- Parameters:
position- The position to fetch the stack- Returns:
- A copy of the
Piecethat is at the given position
-
getTop
Get the Piece (at top of a stack) at a given position- Parameters:
row- The y coordinate of the position to fetch the stackcol- The x coordinate of the position to fetch the stack- Returns:
- A copy of the
Piecethat is at the given position
-
countInitialCapstones
public int countInitialCapstones()Count the initial capstones (depending on the board size) that a player has when the game starts- Returns:
- the number of capstones (see
Piece)
-
countInitialStones
public int countInitialStones()Count the initial stones (depending on the board size) that a player has when the game starts- Returns:
- the number of stones (see
Piece)
-
clone
Clone (seeCloneable) the current board
-