public class Board
extends java.lang.Object
Important: Boards are immutable; the update method returns a modified COPY of the board, without modifying the original board.
Boards have no public constructors. Instead, they should be created by starting with EMPTY and repeatedly calling update(...).
| Modifier and Type | Class and Description |
|---|---|
static class |
Board.State
The possible states of the game.
|
| Modifier and Type | Field and Description |
|---|---|
static @NonNull Board |
EMPTY
The empty board.
|
static @NonNull java.lang.Iterable<Location> |
LOCATIONS
The set of all valid locations.
|
static int |
NUM_COLS
The number of columns on any board.
|
static int |
NUM_ROWS
The number of rows on any board.
|
| Modifier and Type | Method and Description |
|---|---|
Player |
get(int row,
int col)
Return the player who has played in (r,c), or null if it is empty.
|
Player |
get(@NonNull Location loc)
Return the player who has played in loc, or null if loc is empty.
|
@NonNull Board.State |
getState()
Return the state of the board
|
@NonNull Victory |
getWinner()
Return a Victory object if the game has been won.
|
Board |
update(@NonNull Player p,
@NonNull Location loc)
Return a new board that is the same as this with loc mapped to p.
|
public static final int NUM_ROWS
public static final int NUM_COLS
public static final @NonNull Board EMPTY
public static final @NonNull java.lang.Iterable<Location> LOCATIONS
public Board update(@NonNull Player p, @NonNull Location loc) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if loc has already been playedpublic Player get(@NonNull Location loc)
public Player get(int row, int col)
public @NonNull Victory getWinner() throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the game has not been won.public @NonNull Board.State getState()