Package net.royalur.model
Class Board
java.lang.Object
net.royalur.model.Board
Stores the placement of pieces on the tiles of a Royal Game of Ur board.
-
Constructor Summary
ModifierConstructorDescriptionprotected
Instantiates a board with the same shape and pieces astemplate
.Board
(BoardShape shape) Instantiates an empty board with the shapeshape
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all pieces from this board.boolean
Determines whethertile
falls within the bounds of this board.boolean
containsIndices
(int ix, int iy) Determines whether the tile at the indices (ix
,iy
), 0-based, falls within the bounds of this board.copy()
Creates an exact copy of this board.int
countPieces
(PlayerType player) Counts the number of pieces that are on the board forplayer
.boolean
Gets the piece ontile
.getByIndices
(int ix, int iy) Gets the piece on the tile at the indices (ix
,iy
), 0-based.int
Gets the height of the board, which represents the number of y-coordinates in this board.getShape()
Gets the shape of this board.int
getWidth()
Gets the width of the board, which represents the number of x-coordinates in this board.Sets the piece ontile
topiece
.setByIndices
(int ix, int iy, Piece piece) Sets the piece on the tile at the indices (ix
,iy
), 0-based, to the piecepiece
.toString()
Writes the contents of this board into a String, where each column is separated by a delimiter.
-
Constructor Details
-
Board
Instantiates an empty board with the shapeshape
.- Parameters:
shape
- The shape of this board.
-
Board
Instantiates a board with the same shape and pieces astemplate
.- Parameters:
template
- Another board to use as a template to copy from.
-
-
Method Details
-
copy
Creates an exact copy of this board.- Returns:
- An exact copy of this board.
-
getShape
Gets the shape of this board.- Returns:
- The shape of this board.
-
getWidth
public int getWidth()Gets the width of the board, which represents the number of x-coordinates in this board.- Returns:
- The number of x-coordinates that exist in this board.
-
getHeight
public int getHeight()Gets the height of the board, which represents the number of y-coordinates in this board.- Returns:
- The number of y-coordinates that exist in this board.
-
contains
Determines whethertile
falls within the bounds of this board.- Parameters:
tile
- The tile to be bounds-checked.- Returns:
- Whether the given tile falls within the bounds of this board.
-
containsIndices
public boolean containsIndices(int ix, int iy) Determines whether the tile at the indices (ix
,iy
), 0-based, falls within the bounds of this board.- Parameters:
ix
- The x-index of the tile to be bounds-checked. This coordinate is 0-based.iy
- The y-index of the tile to be bounds-checked. This coordinate is 0-based.- Returns:
- Whether the given tile falls within the bounds of this board.
-
get
Gets the piece ontile
. Returnsnull
if there is no piece on the tile.- Parameters:
tile
- The tile to find the piece on.- Returns:
- The piece on the given tile if one exists, or else
null
.
-
getByIndices
Gets the piece on the tile at the indices (ix
,iy
), 0-based. Returnsnull
if there is no piece on the tile.- Parameters:
ix
- The x-index of the tile to find the piece on. This coordinate is 0-based.iy
- The y-index of the tile to find the piece on. This coordinate is 0-based.- Returns:
- The piece on the given tile if one exists, or else
null
.
-
set
Sets the piece ontile
topiece
. Ifpiece
isnull
, it removes any piece on the tile. Returns the piece that was previously on the tile, ornull
if there was no piece on the tile.- Parameters:
tile
- The tile to find the piece on.piece
- The piece that should be placed on the tile.- Returns:
- The previous piece on the given tile if there was one,
or else
null
.
-
setByIndices
Sets the piece on the tile at the indices (ix
,iy
), 0-based, to the piecepiece
. Ifpiece
isnull
, it removes any piece on the tile. Returns the piece that was previously on the tile, ornull
if there was no piece on the tile.- Parameters:
ix
- The x-index of the tile to place the piece on. This coordinate is 0-based.iy
- The y-index of the tile to place the piece on. This coordinate is 0-based.piece
- The piece that should be placed on the tile.- Returns:
- The previous piece on the given tile if there was one,
or else
null
.
-
clear
public void clear()Removes all pieces from this board. -
countPieces
Counts the number of pieces that are on the board forplayer
.- Parameters:
player
- The player to count the pieces of.- Returns:
- The number of pieces on the board for the given player.
-
equals
-
toString
Writes the contents of this board into a String, where each column is separated by a delimiter.- Parameters:
columnDelimiter
- The delimiter to use to distinguish columns of the board.includeOffBoardTiles
- Whether to include tiles that don't fall on the board as spaces.- Returns:
- A String representing the contents of this board.
-
toString
-