public interface Game
This interface defines a state machine on which adding a moves
to the game transitions the machine to a new state. After calling
the method makeMove
the game object must transition to a new
state, and calling the method unmakeMove
must revert the
the object to the previous state it had. An implementation of this
interface stores the performed moves of a match and provides methods
for the generation of legal moves and the evaluation of the current
game state.
Modifier and Type | Field and Description |
---|---|
static int |
DRAW
Returned when the game ended in a draw
|
static int |
DRAW_SCORE
The draw score for the utility function
|
static int |
NORTH
North player identifier
|
static int |
NULL_MOVE
Null move identifier
|
static int |
SOUTH
South player identifier
|
Modifier and Type | Method and Description |
---|---|
void |
endMatch()
Sets the internal board to the endgame position.
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of the game object if necessary.
|
boolean |
hasEnded()
Checks if the game has ended on the current position
|
long |
hash()
Returns an unique hash code for the current position.
|
boolean |
isLegal(int move)
Check if a move may be performed on the current position.
|
int[] |
legalMoves()
Returns all the legal moves that can be performed on the current
game position.
|
int |
length()
Returns the number of moves performed on this game.
|
void |
makeMove(int move)
Performs a move on the internal board.
|
int[] |
moves()
Returns all the performed moves till the current position.
|
int |
nextMove()
Returns the next legal move for the current position and turn.
|
int |
outcome()
Returns an utility evaluation of the current position.
|
java.lang.Object |
position()
Returns a representation of the current position.
|
int |
score()
Returns an heuristic evaluation of the current position.
|
void |
setStart(java.lang.Object position,
int turn)
Sets a new initial position and turn for the game.
|
int |
turn()
Returns the playing turn for the current game position
|
void |
unmakeMove()
Undoes the last performed move on the internal board.
|
int |
winner()
Returns an identifier for the player that won the game on the
current position.
|
static final int DRAW
static final int SOUTH
static final int NORTH
static final int NULL_MOVE
static final int DRAW_SCORE
int length()
int[] moves()
null
if
no moves have been performedint turn()
Game.SOUTH
or Game.NORTH
java.lang.Object position()
void setStart(java.lang.Object position, int turn)
position
- A representation of a positionturn
- The player to move on the position. Must be
either Game.SOUTH
or Game.NORTH
.java.lang.IllegalArgumentException
- if turn
is not valid or
postion
is not a valid position representationvoid endMatch()
boolean hasEnded()
true
if the game ended or
false
otherwiseint winner()
Game.SOUTH
, Game.NORTH
or
Game.DRAW
if the game ended in a draw or
hasn't ended yetint score()
The heuristic score must be a value between the minimum and
the maximum scores returned by the method outcome
and
must predict how close to the end of the match the game is.
A position must be evaluated always from the point of view of south's player. Thus, this method must return increasing positive numbers as the south player approaches winning the game, and decreasing negative numbers if north has the advantage.
outcome()
int outcome()
The score returned must be computed always from the south player
point of view. Thus, it should return the maximum possible score if
south wins; the minimum possible score if north wins and Game.DRAW_SCORE
if the game ended in a draw or hasn't ended yet.
score()
long hash()
boolean isLegal(int move)
move
- A move identifiertrue
if the move is legalmakeMove(int)
void makeMove(int move)
This method must be as efficient as possible; it must not check the legality of the performed move or assert that the game object has enough capacity to store the move.
move
- The move to perform on the internal boardunmakeMove()
void unmakeMove()
makeMove
was called.makeMove(int)
int nextMove()
This method is provided for efficiency, so it is not necessary
to generate all the legal moves on a given position till they
are needed. Legal moves are iterated based on the internal move
generation status. Note that after a call to unmakeMove
the last generation status must be restored to the previous state
it had before calling the method makeMove
.
A good move ordering is likely to improve the engine performance. So its always a good idea to return the moves that are possibly best for the player to move first.
NULL_MOVE
if no
more moves can be returnedlegalMoves()
int[] legalMoves()
Note that the order of the moves on the result array it's likely to improve/decresase the engine performance. So it may be a good idea to store the best moves first.
nextMove()
void ensureCapacity(int minCapacity)
minCapacity
- capacity specified in number of movesjava.lang.IllegalStateException
- if minCapacity
is above
the maximum possible capacity for the objectmakeMove(int)