|
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.TemplatePlayer
public abstract class TemplatePlayer
The TemplatePlayer provides a useful skeleton implementation for the Player interface. Inheriting Player classes only need to implement the following methods (at a minimum) to provide the necessary game domain specific knowlege:
- canPlayGame(GamePlay game)
- heuristic(GamePlay game, GameMove move, int[] role)
Player,
GameUtilities,
RandomPlayer,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
TemplatePlayer.MoveEvaluater
MoveEvaluater is used by the method selectMove() from the enclosing TemplatePLayer class in case of a time-limited search to allow each move to be examined efficiently in a separate thread. |
protected class |
TemplatePlayer.Synchronizer
Synchronizer is used consolidate the MoveEvaluater threads spanned off by the selectMove() method from the enclosing TemplatePlayer. |
| Field Summary | |
|---|---|
protected int |
levelOverride
|
protected Vector<Monitor> |
monitors
|
protected boolean |
orderMoves
|
protected String |
playerName
|
static int |
SEARCH_ALPHABETA
when used as searchOption, Alpha-Beta Search algorithm is used |
static int |
SEARCH_MINMAX
when used as searchOption, MinMax Search algorithm is used |
protected int |
searchOption
|
| Constructor Summary | |
|---|---|
TemplatePlayer()
This constructor instanciates a Player with the name "unnamed DefaultPlayer", no game tree search option, tracking disabled and no game level override. |
|
TemplatePlayer(String playerName)
instanciates a Player with no game tree search option, disabled tracking and no game level override |
|
TemplatePlayer(String playerName,
int searchOption,
boolean trackingEnabled)
instanciates a player with the given playerName, searchOption and tracking; game level override is set to 0; for searchOption values see #setSearchOption(). |
|
| Method Summary | |
|---|---|
void |
disableTracking()
Deprecated. use setTracking(boolean enable) instead |
void |
enableTracking()
Deprecated. use setTracking(boolean enable) instead |
double |
evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds)
This method will simply call the protected evaluate() method and in addition track the call if tracking is enabled. |
protected double |
evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds,
Monitor monitor)
Internal evaluate function called by public evaluate() and selectMove(). |
int |
getlevelOverride()
This method returns 0 by default, meaning there is no level override in place. |
protected Monitor[] |
getMonitors()
returns an array of all Monitors if tracking is enabled |
boolean |
getOrderMoves()
if enabled and Alpha-Beta tree search algorithm is used, the tree search employs ordering of the legal moves by their heuristic before the next level is searched (to enhance tree pruning) |
String |
getPlayerName()
|
int |
getSearchOption()
|
int |
numberOfPositionsSearched()
returns the sum of Monitor.getNumber() from all monitors tracked in this player during calls to selectMove() and evaluate() if tracking has been enabled |
int |
numberOfRequests()
returns the number of calls to evaluate() or selectMove() since tracking has been enabled |
float |
performanceRatio()
returns the quotient between numberOfPositionsSearched() and totalTimeTaken(); the result will be scaled to reflect how many positions have been searched per second. |
boolean |
pruneMove(GamePlay game,
GameMove move,
int[] role)
unless overridden, this method returns always false |
GameMove |
selectMove(GamePlay game,
int[] role,
int level,
long milliseconds)
This implementation selects the best move according to the given configuration. |
void |
setlevelOverride(int levelOverride)
This method enables to override the level parameter value given to selectMove() and/or evaluate(), so that the implementation will use this value instead of the level given by the parameters. |
void |
setOrderMoves(boolean enable)
If set to true, Alpha-Beta search algorithm - if used - will order the legal moves according to their heuristic before searching the next level. |
void |
setPlayerName(String name)
|
void |
setSearchOption(int searchOption)
This function sets the search algorithm used in selectMove() and evaluate(). |
void |
setTracking(boolean enable)
|
String |
statsAsString()
returns a String with the Player's statistics for logging/printing |
String |
toString()
overridden to return some information about the player |
long |
totalTimeTaken()
goes through all monitored requests and returns the sum of the elapsed time |
boolean |
trackingEnabled()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.antelmann.game.Player |
|---|
canPlayGame, heuristic |
| Field Detail |
|---|
public static final int SEARCH_MINMAX
public static final int SEARCH_ALPHABETA
protected String playerName
protected int searchOption
protected int levelOverride
protected boolean orderMoves
protected transient Vector<Monitor> monitors
| Constructor Detail |
|---|
public TemplatePlayer()
public TemplatePlayer(String playerName)
public TemplatePlayer(String playerName,
int searchOption,
boolean trackingEnabled)
| Method Detail |
|---|
@Deprecated public void enableTracking()
@Deprecated public void disableTracking()
public void setTracking(boolean enable)
public boolean trackingEnabled()
public int numberOfRequests()
throws IllegalStateException
IllegalStateException - if tracking is disabled
public long totalTimeTaken()
throws IllegalStateException
IllegalStateException - if tracking is disabled
public int numberOfPositionsSearched()
throws IllegalStateException
IllegalStateException - if tracking is disabled
public float performanceRatio()
throws IllegalStateException
IllegalStateException - if tracking is disabled
protected Monitor[] getMonitors()
throws IllegalStateException
IllegalStateException - if tracking is disabledMonitorpublic int getSearchOption()
public void setSearchOption(int searchOption)
throws IllegalArgumentException
IllegalArgumentException - if searchOption is unknownpublic int getlevelOverride()
setlevelOverride(int)public void setlevelOverride(int levelOverride)
getlevelOverride()public boolean getOrderMoves()
public void setOrderMoves(boolean enable)
public String getPlayerName()
getPlayerName in interface Playerpublic void setPlayerName(String name)
public boolean pruneMove(GamePlay game,
GameMove move,
int[] role)
pruneMove in interface Player
public double evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds)
throws CannotPlayGameException
evaluate in interface PlayerCannotPlayGameException - if the game cannot be played by the playerevaluate(GamePlay, GameMove, int[], int, long, Monitor)
protected double evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds,
Monitor monitor)
GameUtilities.minMaxSearch(GamePlay, GameMove, Player, int[], int, Monitor),
GameUtilities.alphaBetaSearch(GamePlay, GameMove, Player, int[], int, Monitor, boolean),
Monitor
public GameMove selectMove(GamePlay game,
int[] role,
int level,
long milliseconds)
selectMove in interface PlayerTemplatePlayer.Synchronizer,
TemplatePlayer.MoveEvaluaterpublic String toString()
toString in class Objectpublic String statsAsString()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||