Modifier and Type | Field and Description |
---|---|
protected static long[][] |
COEFFICIENTS
Binomial coefficients used to compute hash codes
|
static int |
MAX_CAPACITY
The maximum number of moves this object can store
|
static int |
MAX_SCORE
Maximum score to which positions are evaluated
|
static byte[] |
START_POSITION
Default start position
|
Constructor and Description |
---|
OwareGame()
Instantiates a new
OwareGame object with the default
start position and capacity. |
OwareGame(int capacity)
Instantiates a new
OwareGame object with the default
start position and the specified capacity. |
Modifier and Type | Method and Description |
---|---|
void |
endMatch()
Sets the internal board to its endgame position based on the
current position
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of the game object if necessary.
|
protected byte[] |
gameState()
Returns the current game state representation.
|
boolean |
hasEnded()
Checks if the game has ended on the current position.
|
long |
hash()
Returns the unique hash code for the current position.
|
boolean |
hasLegalMoves()
Checks if at least one legal move can be performed for the
current position and turn
|
boolean |
isCapture(int move)
Checks if the move is a capturing move for the current position.
|
boolean |
isLegal(int move)
Check if a move may be performed on the current position.
|
boolean |
isRepetition()
Checks if the current position is a move repetition.
|
int[] |
legalMoves()
Returns all the legal moves that can be performed on the current
game position.
|
int |
length()
Returns the number of moves performed for this game from the
initial position till the current move.
|
void |
makeMove(int move)
Performs a move on the internal board.
|
int[] |
moves()
Returns an array with all the performed moves till the current
position of the game.
|
int |
nextMove()
Returns the next legal move for the current position and turn.
|
byte |
northStore()
Returns the number of seed captured by the north player till
the current position.
|
int |
outcome()
Returns an utility evaluation of the current position.
|
byte[] |
position()
Returns an array representation of the current position.
|
int |
score()
Returns the heuristic evaluation of the current position
|
void |
setStart(java.lang.Object position,
int turn)
Sets a new position and turn as the initial board for the game.
|
byte |
southStore()
Returns the number of seed captured by the south player till
the current position.
|
int |
turn()
Returns the playing turn for the current game position.
|
void |
unmakeMove()
Undoes the last performed move on the internal board.
|
boolean |
wasCapture()
Returns whether the last performed move was a capture or not.
|
int |
winner()
Returns the winner of the game for the current position.
|
public static final int MAX_SCORE
public static final int MAX_CAPACITY
public static final byte[] START_POSITION
protected static final long[][] COEFFICIENTS
public OwareGame()
OwareGame
object with the default
start position and capacity.public OwareGame(int capacity)
OwareGame
object with the default
start position and the specified capacity.capacity
- Number of moves this game can store initiallypublic void setStart(java.lang.Object position, int turn)
public int length()
public int[] moves()
public int turn()
public byte[] position()
protected byte[] gameState()
public byte southStore()
public byte northStore()
public void endMatch()
public boolean hasEnded()
public int winner()
public int score()
score
in interface Game
-MAX_SCORE
and MAX_SCORE
Game.outcome()
public int outcome()
This method evaluates the current position as an endgame,
returning ±MAX_SCORE
if a player won or Game.DRAW_SCORE
if the match hasn't ended or it is drawn.
outcome
in interface Game
-MAX_SCORE
,
MAX_SCORE
or DRAW_SCORE
Game.score()
public long hash()
public boolean isLegal(int move)
A move is legal if it sows seeds into the opponent houses, unless no such move could be performed, in which case all the moves that sow seeds are legal. Grand Slam moves are legal but they don't capture any seeds.
isLegal
in interface Game
move
- A move identifiertrue
if the move is legalGame.makeMove(int)
public boolean hasLegalMoves()
true
if a legal move can be performed for the
player to move or false
otherwisepublic boolean isRepetition()
OwareGame
object move history contains
a move performed by the current player that lead to a position
equal to the current position.true
if the last performed move lead to a
position repetition; false
otherwisepublic boolean isCapture(int move)
move
- The move to determine if it's a capturetrue
if the move would perform a legal
capture or false
otherwisepublic boolean wasCapture()
true
if the last move captured seedspublic void makeMove(int move)
makeMove
in interface Game
move
- The move to perform on the internal boardjava.lang.IndexOutOfBoundsException
- if this game object does not
have enought capacity to store the moveensureCapacity(int)
public void unmakeMove()
makeMove
was called.unmakeMove
in interface Game
makeMove(int)
public int nextMove()
Legal moves are iterated based on the internal board move generation status and sorted according to their preferenece. Captures are returned first, followed by those that seed a house with less than tree seeds and the remaining moves.
nextMove
in interface Game
Game.NULL_MOVE
if no more moves can be returnedGame.legalMoves()
public int[] legalMoves()
This method does not change the state of the game, thus, the
moves returned by the method nextMove
remain unaltered.
The order in which moves are sorted in the resulting array is the
same as defined by nextMove
.
legalMoves
in interface Game
nextMove()
public void ensureCapacity(int minCapacity)
ensureCapacity
in interface Game
minCapacity
- Minimal capacity request in number of movesjava.lang.IllegalStateException
- If minCapacity
is above
the maximum possible capacity for the objectGame.makeMove(int)