org.jscience.computing.game
Class RandomPlayer

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

public class RandomPlayer
extends TemplatePlayer

RandomPlayer provides a reference implementation of the Player interface. The RandomPlayer is a Player implementation that can play any game without further domain knowledge by providing either a purely random heuristic or heuristics that take advantage of the knowledge whether a GameMove can win or loose a given GamePlay. If the tree search options for its super class are set to a meaningful option and the getCheckForWin() is set to true, the RandomPlayer can actually play reasonably intelligent based on a given level when selecting moves (that is the RandomPlayer then ensures that if a win/loss situation can be seen within the given level, the prefered move by this RandomPlaye is the one that either wins or at least doesn't loose the game within the number of moves specified by the level).

See Also:
GamePlay, GameMove, TemplatePlayer, Player, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jscience.computing.game.TemplatePlayer
TemplatePlayer.MoveEvaluater, TemplatePlayer.Synchronizer
 
Field Summary
 
Fields inherited from class org.jscience.computing.game.TemplatePlayer
levelOverwrite, monitors, orderMoves, playerName, SEARCH_ALPHABETA, SEARCH_MINMAX, searchOption
 
Constructor Summary
RandomPlayer()
          calls RandomPlayer(System.currentTimeMillis())
RandomPlayer(long randomSeed)
          calls RandomPlayer("unnamed RandomPlayer")
RandomPlayer(java.lang.String name)
          creates a RandomPlayer with no tree search option, no win checking and takes System.currentTimeMillis() as random seed.
RandomPlayer(java.lang.String name, long randomSeed)
          calls RandomPlayer(name, randomSeed, false, 0, false)
RandomPlayer(java.lang.String name, long randomSeed, boolean checkForWin, int searchOption, boolean enableTracking)
          If checkForWin is set to true, heuristic() does preserve the knowledge about whether it wins or loses a game with the given move, in which case appropriate values (other than random ones) are returned.
 
Method Summary
 boolean canPlayGame(GamePlay game)
          always returns true, since the RandomPlayer can play any game
 boolean getCheckForWin()
          DOCUMENT ME!
 double heuristic(GamePlay game, GameMove move, int[] role)
          Preserves the knowlege of whether the move wins or looses the game only if getCheckForWin() returns true; return values are then randomized unless the random seed is set to 0.
 void setCheckForWin(boolean enable)
          if enabled, the RandomPlayer's heuristic checks whether a given move can win the game and returns values accordingly
 void setRandomSeed(long seed)
          if seed = 0, randomization is disabled
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class org.jscience.computing.game.TemplatePlayer
disableTracking, enableTracking, evaluate, evaluate, getLevelOverwrite, getMonitors, getOrderMoves, getPlayerName, getSearchOption, numberOfPositionsSearched, numberOfRequests, performanceRatio, pruneMove, selectMove, setLevelOverwrite, setOrderMoves, setPlayerName, setSearchOption, setTracking, statsAsString, totalTimeTaken, trackingEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RandomPlayer

public RandomPlayer()
calls RandomPlayer(System.currentTimeMillis())


RandomPlayer

public RandomPlayer(long randomSeed)
calls RandomPlayer("unnamed RandomPlayer")

Parameters:
randomSeed - DOCUMENT ME!

RandomPlayer

public RandomPlayer(java.lang.String name)
creates a RandomPlayer with no tree search option, no win checking and takes System.currentTimeMillis() as random seed.

Parameters:
name - DOCUMENT ME!

RandomPlayer

public RandomPlayer(java.lang.String name,
                    long randomSeed)
calls RandomPlayer(name, randomSeed, false, 0, false)

Parameters:
name - DOCUMENT ME!
randomSeed - DOCUMENT ME!

RandomPlayer

public RandomPlayer(java.lang.String name,
                    long randomSeed,
                    boolean checkForWin,
                    int searchOption,
                    boolean enableTracking)
If checkForWin is set to true, heuristic() does preserve the knowledge about whether it wins or loses a game with the given move, in which case appropriate values (other than random ones) are returned. If the searchOption is then set to one of the tree search options (see TemplatePlayer), the RandomPlayer can in fact play reasonably intelligent as to be able to seek a move that wins or does not loose within the number of moves given by the level.

See Also:
TemplatePlayer
Method Detail

canPlayGame

public boolean canPlayGame(GamePlay game)
always returns true, since the RandomPlayer can play any game

Parameters:
game - DOCUMENT ME!
Returns:
DOCUMENT ME!

setRandomSeed

public void setRandomSeed(long seed)
if seed = 0, randomization is disabled

Parameters:
seed - DOCUMENT ME!

setCheckForWin

public void setCheckForWin(boolean enable)
if enabled, the RandomPlayer's heuristic checks whether a given move can win the game and returns values accordingly

Parameters:
enable - DOCUMENT ME!

getCheckForWin

public boolean getCheckForWin()
DOCUMENT ME!

Returns:
DOCUMENT ME!

heuristic

public double heuristic(GamePlay game,
                        GameMove move,
                        int[] role)
Preserves the knowlege of whether the move wins or looses the game only if getCheckForWin() returns true; return values are then randomized unless the random seed is set to 0.

Parameters:
game - DOCUMENT ME!
move - DOCUMENT ME!
role - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
TemplatePlayer

toString

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

Overrides:
toString in class TemplatePlayer
Returns:
DOCUMENT ME!