|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.computing.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,
GameUtils,
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 |
levelOverwrite
|
protected java.util.Vector<Monitor> |
monitors
|
protected boolean |
orderMoves
|
protected java.lang.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 overwrite. |
|
TemplatePlayer(java.lang.String playerName)
instanciates a Player with no game tree search option, disabled tracking and no game level overwrite |
|
TemplatePlayer(java.lang.String playerName,
int searchOption,
boolean trackingEnabled)
instanciates a player with the given playerName, searchOption and tracking; game level overwrite 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 |
getLevelOverwrite()
This method returns 0 by default, meaning there is no level overwrite 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) |
java.lang.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 overwritten, 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 |
setLevelOverwrite(int levelOverwrite)
This method enables to overwrite 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(java.lang.String name)
|
void |
setSearchOption(int searchOption)
This function sets the search algorithm used in selectMove() and evaluate(). |
void |
setTracking(boolean enable)
|
java.lang.String |
statsAsString()
returns a String with the Player's statistics for logging/printing |
java.lang.String |
toString()
overwritten 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 org.jscience.computing.game.Player |
|---|
canPlayGame, heuristic |
| Field Detail |
|---|
public static final int SEARCH_MINMAX
public static final int SEARCH_ALPHABETA
protected java.lang.String playerName
protected int searchOption
protected int levelOverwrite
protected boolean orderMoves
protected transient java.util.Vector<Monitor> monitors
| Constructor Detail |
|---|
public TemplatePlayer()
public TemplatePlayer(java.lang.String playerName)
public TemplatePlayer(java.lang.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 java.lang.IllegalStateException
java.lang.IllegalStateException - if tracking is disabled
public long totalTimeTaken()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if tracking is disabled
public int numberOfPositionsSearched()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if tracking is disabled
public float performanceRatio()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if tracking is disabled
protected Monitor[] getMonitors()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if tracking is disabledMonitorpublic int getSearchOption()
public void setSearchOption(int searchOption)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if searchOption is unknownpublic int getLevelOverwrite()
setLevelOverwrite(int)public void setLevelOverwrite(int levelOverwrite)
getLevelOverwrite()public boolean getOrderMoves()
public void setOrderMoves(boolean enable)
public java.lang.String getPlayerName()
getPlayerName in interface Playerpublic void setPlayerName(java.lang.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)
GameUtils.minMaxSearch(GamePlay,GameMove,Player,int[],int,Monitor),
GameUtils.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 java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String statsAsString()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||