Holger's
Java API

com.antelmann.game
Class RandomPlayer

java.lang.Object
  extended by com.antelmann.game.TemplatePlayer
      extended by com.antelmann.game.RandomPlayer
All Implemented Interfaces:
Player, Serializable

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).

Author:
Holger Antelmann
See Also:
GamePlay, GameMove, TemplatePlayer, Player, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.antelmann.game.TemplatePlayer
TemplatePlayer.MoveEvaluater, TemplatePlayer.Synchronizer
 
Field Summary
 
Fields inherited from class com.antelmann.game.TemplatePlayer
levelOverride, monitors, orderMoves, playerName, SEARCH_ALPHABETA, SEARCH_MINMAX, searchOption
 
Constructor Summary
RandomPlayer()
          calls RandomPlayer(System.currentTimeMillis())
RandomPlayer(long randomSeed)
          calls RandomPlayer("unnamed RandomPlayer")
RandomPlayer(String name)
          creates a RandomPlayer with no tree search option, no win checking and takes System.currentTimeMillis() as random seed.
RandomPlayer(String name, long randomSeed)
          calls RandomPlayer(name, randomSeed, false, 0, false)
RandomPlayer(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()
           
 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
 String toString()
          overridden to return some information about the player
 
Methods inherited from class com.antelmann.game.TemplatePlayer
disableTracking, enableTracking, evaluate, evaluate, getlevelOverride, getMonitors, getOrderMoves, getPlayerName, getSearchOption, numberOfPositionsSearched, numberOfRequests, performanceRatio, pruneMove, selectMove, setlevelOverride, 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")


RandomPlayer

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


RandomPlayer

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


RandomPlayer

public RandomPlayer(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


setRandomSeed

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


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


getCheckForWin

public boolean getCheckForWin()

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.

See Also:
TemplatePlayer

toString

public String toString()
Description copied from class: TemplatePlayer
overridden to return some information about the player

Overrides:
toString in class TemplatePlayer


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads