public class HexState
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
NONE |
static int |
PLAYER1 |
static int |
PLAYER2 |
Constructor and Description |
---|
HexState(HexState state)
Create a deep copy of the given Hex game state (including current player).
|
HexState(int size)
Create an empty Hex board that has the given number of rows and upper-left diagonals for hex grid positions.
|
Modifier and Type | Method and Description |
---|---|
int |
getPlayer()
Return the current player constant PLAYER1 or PLAYER2.
|
int |
getPosition(int row,
int col)
Return the contents of a board row and column (upper-left diagonal) position using integer constants PLAYER1/PLAYER2/NONE.
|
int |
getPosition(java.lang.String pos)
Return the contents of a board row and column (upper-left diagonal) position using integer constants PLAYER1/PLAYER2/NONE.
|
int |
getSize()
Return the number of rows and columns (i.e.
|
int |
getWinner()
Return the winner PLAYER1/PLAYER2 if there is a winner, or NONE is there is no winner.
|
boolean |
playAt(int row,
int col)
Attempt to make a legal play for the current player at the given position and then change the player and return true.
|
boolean |
playAt(java.lang.String pos)
Attempt to make a legal play for the current player at the given position and then change the player and return true.
|
java.lang.String |
toString()
Return a String representation of the board according to the following specification: There should be one line per board row, one line with column letter labels, and one final line terminated with a newline that describes the current player/winner.
|
public static final int PLAYER1
public static final int PLAYER2
public static final int NONE
public HexState(int size)
size
- the given number of rows and columns (i.e. upper-left diagonals) for hex grid positionspublic HexState(HexState state)
state
- the given Hex game state to copypublic int getSize()
public int getPlayer()
public int getPosition(int row, int col)
row
- given board rowcol
- given board column (upper-left diagonal)public int getPosition(java.lang.String pos)
pos
- an algebraic notation of the board position consisting of a letter concatenated with an integer,
where the integer is one more than the row index and the initial letter indicates the column (upper-left diagonal) with 'a'=0, 'b'=1, etc.public boolean playAt(int row, int col)
row
- given board rowcol
- given board column (upper-left diagonal)public boolean playAt(java.lang.String pos)
pos
- an algebraic notation of the board position consisting of a letter concatenated with an integer,
where the integer is one more than the row index and the initial letter indicates the column (upper-left diagonal) with 'a'=0, 'b'=1, etc.public java.lang.String toString()
toString
in class java.lang.Object
public int getWinner()