|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.game.BookPlayer
public class BookPlayer
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.
| Constructor Summary | |
|---|---|
BookPlayer(Player player)
|
|
BookPlayer(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)
canPlayGame() returns true only if the Player provides an applicable heuristic for the type of game given. |
void |
changePlayer(Player player)
|
double |
evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds)
evaluate() asks the Player to rate a move in the context of a given game stage relative to its role (if the Player has multiple roles in the game, they will all be found in the role array - giving the Player maximum flexibility) while considering the game level for potential game tree search operations and then using heuristic() to evaluate the leaves of the game tree. |
Hashtable |
getBook()
allows access to the embedded book to add/remove GamePlay-GameMove pairs |
Player |
getPlayer()
|
String |
getPlayerName()
|
double |
heuristic(GamePlay game,
GameMove move,
int[] role)
This function - often used as a callback function - evaluates the given move in the context of the given game; it is expected to return quickly. |
boolean |
pruneMove(GamePlay game,
GameMove move,
int[] role)
This method allows the Player to prune a game tree branch by determining that a particular move is not to be considered for further recursive tree search; this method is expected to return quickly. |
GameMove |
selectMove(GamePlay game,
int[] role,
int level,
long milliseconds)
first checks the embedded book for a pre-stored move |
void |
setBook(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 |
|---|
public BookPlayer(Player player)
public BookPlayer(String name,
Player player)
getPlayerName()| Method Detail |
|---|
public String getPlayerName()
getPlayerName in interface Playerpublic boolean canPlayGame(GamePlay game)
Player
//Example:
if (game instanceof MyGameClass) return true; else return false;
// or:
if (game.getClass() == myFavoriteGame.getClass()) return true; else return false;
canPlayGame in interface Player
public boolean pruneMove(GamePlay game,
GameMove move,
int[] role)
PlayerBy default, this method should always return false unless there is a good reason found by a Player to dismiss the tree branch emerging from this move.
pruneMove in interface Player
public double evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds)
Player
evaluate in interface PlayerGameUtilities,
TemplatePlayer,
GamePlay.getResult(int)
public double heuristic(GamePlay game,
GameMove move,
int[] role)
Player
heuristic in interface PlayerTemplatePlayer
public GameMove selectMove(GamePlay game,
int[] role,
int level,
long milliseconds)
selectMove in interface PlayerTemplatePlayerpublic int bookHits()
public void setBook(Hashtable<GamePlay,GameMove> book)
public Hashtable getBook()
public void changePlayer(Player player)
public Player getPlayer()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||