Package a5.logic
Class Board
java.lang.Object
a5.logic.Board
A mutable representation of an m-by-n board in which each cell
can be occupied by a player or be empty
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
colSize()
boolean
Board equality is determined using state equality.protected void
Effect: set the cell at positionp
to empty.int
Returns: the board state of a cell.int
hashCode()
boolean
Returns: true ifp
is within the board.protected void
place
(Position p, PlayerRole currentPlayer) Effect: place a stone ascurrentPlayer
on board at positionp
.int
rowSize()
boolean
Returns: true ifp
is a valid cell to place stones.
-
Constructor Details
-
Board
public Board(int rowSize, int colSize) Creates a newrowSize
-by-colSize
board. -
Board
Creates a new board that deep copies a provided board.- Parameters:
board
- the board to copy from
-
-
Method Details
-
get
Returns: the board state of a cell. Returns 0 if it is empty; otherwise, the returned value matches the player role'sboardValue
. Requires:p
is on board- Parameters:
p
- the position of the cell
-
place
Effect: place a stone ascurrentPlayer
on board at positionp
. Requires:p
is on board andget(p)
== 0- Parameters:
p
- the position to place a stonecurrentPlayer
- role of the current player
-
erase
Effect: set the cell at positionp
to empty. Requires:p
is on board -
rowSize
public int rowSize() -
colSize
public int colSize() -
equals
Board equality is determined using state equality. -
hashCode
public int hashCode() -
validPos
Returns: true ifp
is a valid cell to place stones. -
onBoard
Returns: true ifp
is within the board.
-