org.pesullivan.game.game42
Interface Board

All Known Implementing Classes:
MillBoard

public interface Board

A game board interface that can form the basis of any deterministic 2 player strategy game middle tier. Classes that implement Board hold information about a specific game position. Once a class implements Board then the work of developing the game middle tier is complete because class Game supplies all logic required to calculate optimal moves.

See Also:
Game

Method Summary
 Board copy()
          Return a copy (ignoring move iterator state).
 int getActiveSide()
          Get an index identifying the active side (whose turn it is).
 int getAlteredLevelOfPlay(int requestedLevel)
          Return the number of turns the Game engine should look ahead.
 Move getFirstMove()
          Reset the board's move iterator and return the first move.
 int getGoodEnoughScore(int plannedScore, int levelOfPlay)
          Return a score which is good enough that a player need look no farther to see how much better it gets.
 Move getLastMoveExecuted()
          Return the last move that was executed.
 Board getNewBoard()
          Return a new board ready for a new game.
 Move getNextMove()
          Return the next move based on the board's move iterator.
 int getProgress()
          Return a measure of progress towards the game conclusion.
 int getRepetitionPenalty(int nRepeats)
          Get a score penalty for repeating a position so many times.
 int getScore()
          Express the position's merits as a scalar relative score.
 Move getUndefinedMove()
          Return a new move which has not yet been defined.
 void go(Move move)
          Execute the given move.
 boolean isSame(Board board)
          Compare board states (ignoring move iterator state).
 boolean isWon(int score)
          Return true if the given score means that either side won.
 void setFrom(Board board)
          Set the board state to that of board, (ignoring move iterator state).
 void setFromJSON(org.json.simple.JSONObject jsonBoard)
          Set this board based on the parameter.
 org.json.simple.JSONObject toJSONObject()
           
 

Method Detail

toJSONObject

org.json.simple.JSONObject toJSONObject()
Returns:
this board as a JSONObject.

setFromJSON

void setFromJSON(org.json.simple.JSONObject jsonBoard)
Set this board based on the parameter.


getNewBoard

Board getNewBoard()
Return a new board ready for a new game.


getUndefinedMove

Move getUndefinedMove()
Return a new move which has not yet been defined.


copy

Board copy()
Return a copy (ignoring move iterator state).


setFrom

void setFrom(Board board)
Set the board state to that of board, (ignoring move iterator state).

Parameters:
board - the original board to copy.

isSame

boolean isSame(Board board)
Compare board states (ignoring move iterator state).

Returns:
true if the board states are identical.

getActiveSide

int getActiveSide()
Get an index identifying the active side (whose turn it is).

Returns:
index 0 or 1.

getScore

int getScore()
Express the position's merits as a scalar relative score. A score of zero indicates that both sides have equal merit, while a score greater than zero indicates that the active side is winning. The score is calculated with respect to the current board state without looking ahead. You can improve Board's play by finding optimal weights (as with genetic algorithms) for getScore's criteria. Humans surpass computers in performance of this method.

Returns:
the score from the perspective of the active side.

getGoodEnoughScore

int getGoodEnoughScore(int plannedScore,
                       int levelOfPlay)
Return a score which is good enough that a player need look no farther to see how much better it gets. The Game engine optimizes by pruning move search tree branches using this score. The returned score should be just above what is probable based on plannedScore for optimal performance. Towards the end game the returned score should be far higher than what is probable. levelOfPlay is optionally used to set expectations for what is good enough.

Parameters:
plannedScore - expectations based on a previous search.
levelOfPlay - level of play requested by the Game engine.
Returns:
the score from the perspective of the side with plannedScore.

getRepetitionPenalty

int getRepetitionPenalty(int nRepeats)
Get a score penalty for repeating a position so many times. The Game engine uses this penalty to encourage the choice of a different position than one that has already occurred nRepeats times. This encourages variety of play and draw avoidance at the expense of good judgment.

Parameters:
nRepeats - the number of times this position has already occurred during this game.
Returns:
a positive score penalty.

getAlteredLevelOfPlay

int getAlteredLevelOfPlay(int requestedLevel)
Return the number of turns the Game engine should look ahead. Each turn has one move and possibly several "go again" moves, so the number of moves looked ahead may exceed the level of play. Even though the game engine may request a certain level of play, getAlteredLevelOfPlay() may arbitrarily override it at various stages of the game for performance reasons.

Parameters:
requestedLevel - the level of play requested.
Returns:
an integer greater than 0.

getFirstMove

Move getFirstMove()
Reset the board's move iterator and return the first move. The board's move iterator iterates all moves that are possible from the current position. Each move represents the smallest discrete decision a player can make, and each turn is comprised of 1 or more moves. Even a skipped turn is described by a non-null Move. For better performance return the most promising moves first.

Returns:
a readonly move or null if the game is over.

getNextMove

Move getNextMove()
Return the next move based on the board's move iterator.

Returns:
a readonly move or null if the board's move iterator is done.

getLastMoveExecuted

Move getLastMoveExecuted()
Return the last move that was executed.

Returns:
a readonly move or null if it is a new game.

go

void go(Move move)
Execute the given move. If the active side can't go again after the move is executed, the side is changed.

See Also:
getFirstMove(), getNextMove()

isWon

boolean isWon(int score)
Return true if the given score means that either side won.


getProgress

int getProgress()
Return a measure of progress towards the game conclusion. The Game engine uses this measure to encourage choice of a move which concludes the game sooner. Note that getGoodEnoughScore may subvert this method by pruning (and thus ignoring) moves which conclude the game sooner.

Returns:
a number that increases as the game progresses.