org.jscience.computing.game
Class BookPlayer

java.lang.Object
  extended by org.jscience.computing.game.BookPlayer
All Implemented Interfaces:
java.io.Serializable, Player

public class BookPlayer
extends java.lang.Object
implements Player, java.io.Serializable

BookPlayer is a Player wrapper that can significantly improve normal Player performance by predefining move selections. This is achieved by internally using a Hashtable object as a book. When asked to select a move in a game, the BookPlayer first checks its book (Hashtable) to see whether a given game is present as a key; If so, it will return the GameMove object stored as the associated value to that key (which is assumed to be the desired move earlier put in the book (which is the Hashtable). Only if the GameBook doesn't contain the game in question, the selection is passed on to the embedded Player object for standard procedure, as all other requests defined in the Player interface are routed to the embedded player as well. Naturally, the BookPlayer relies on a properly maintained book to perform well.

See Also:
Serialized Form

Constructor Summary
BookPlayer(Player player)
          Creates a new BookPlayer object.
BookPlayer(java.lang.String name, Player player)
          allows the BookPlayer to have a name different from the embedded player
 
Method Summary
 int bookHits()
          returns the number of times that this BookPlayer had a hit on the embedded GameBook while processing a move selection
 boolean canPlayGame(GamePlay game)
          DOCUMENT ME!
 void changePlayer(Player player)
          DOCUMENT ME!
 double evaluate(GamePlay game, GameMove move, int[] role, int level, long milliseconds)
          DOCUMENT ME!
 java.util.Hashtable getBook()
          allows access to the embedded book to add/remove GamePlay-GameMove pairs
 Player getPlayer()
          DOCUMENT ME!
 java.lang.String getPlayerName()
          DOCUMENT ME!
 double heuristic(GamePlay game, GameMove move, int[] role)
          DOCUMENT ME!
 boolean pruneMove(GamePlay game, GameMove move, int[] role)
          DOCUMENT ME!
 GameMove selectMove(GamePlay game, int[] role, int level, long milliseconds)
          first checks the embedded book for a pre-stored move
 void setBook(java.util.Hashtable<GamePlay,GameMove> book)
          Sets the internal book used by this BookPlayer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BookPlayer

public BookPlayer(Player player)
Creates a new BookPlayer object.

Parameters:
player - DOCUMENT ME!

BookPlayer

public BookPlayer(java.lang.String name,
                  Player player)
allows the BookPlayer to have a name different from the embedded player

See Also:
getPlayerName()
Method Detail

getPlayerName

public java.lang.String getPlayerName()
DOCUMENT ME!

Specified by:
getPlayerName in interface Player
Returns:
DOCUMENT ME!

canPlayGame

public boolean canPlayGame(GamePlay game)
DOCUMENT ME!

Specified by:
canPlayGame in interface Player
Parameters:
game - DOCUMENT ME!
Returns:
DOCUMENT ME!

pruneMove

public boolean pruneMove(GamePlay game,
                         GameMove move,
                         int[] role)
DOCUMENT ME!

Specified by:
pruneMove in interface Player
Parameters:
game - DOCUMENT ME!
move - DOCUMENT ME!
role - DOCUMENT ME!
Returns:
DOCUMENT ME!

evaluate

public double evaluate(GamePlay game,
                       GameMove move,
                       int[] role,
                       int level,
                       long milliseconds)
DOCUMENT ME!

Specified by:
evaluate in interface Player
Parameters:
game - DOCUMENT ME!
move - DOCUMENT ME!
role - DOCUMENT ME!
level - DOCUMENT ME!
milliseconds - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
GameUtils, TemplatePlayer, GamePlay.getResult(int)

heuristic

public double heuristic(GamePlay game,
                        GameMove move,
                        int[] role)
DOCUMENT ME!

Specified by:
heuristic in interface Player
Parameters:
game - DOCUMENT ME!
move - DOCUMENT ME!
role - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
TemplatePlayer

selectMove

public GameMove selectMove(GamePlay game,
                           int[] role,
                           int level,
                           long milliseconds)
first checks the embedded book for a pre-stored move

Specified by:
selectMove in interface Player
Parameters:
game - DOCUMENT ME!
role - DOCUMENT ME!
level - DOCUMENT ME!
milliseconds - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
TemplatePlayer

bookHits

public int bookHits()
returns the number of times that this BookPlayer had a hit on the embedded GameBook while processing a move selection

Returns:
DOCUMENT ME!

setBook

public void setBook(java.util.Hashtable<GamePlay,GameMove> book)
Sets the internal book used by this BookPlayer. The given book is expected to have GamePlay objects as keys and a GameMove object (to be returned if selectMove() is called on an equal GamePlay object) as values, where the move is expected to be a legal move for each game.

Parameters:
book - DOCUMENT ME!

getBook

public java.util.Hashtable getBook()
allows access to the embedded book to add/remove GamePlay-GameMove pairs

Returns:
DOCUMENT ME!

changePlayer

public void changePlayer(Player player)
DOCUMENT ME!

Parameters:
player - DOCUMENT ME!

getPlayer

public Player getPlayer()
DOCUMENT ME!

Returns:
DOCUMENT ME!