Algorithm
Development Kit 1.0

algs.model.problems.tictactoe.model
Class RandomPlayer

java.lang.Object
  extended by algs.model.problems.tictactoe.model.Player
      extended by algs.model.problems.tictactoe.model.RandomPlayer
All Implemented Interfaces:
IPlayer

public class RandomPlayer
extends Player

Randomly makes moves given the logic of the TicTacToe variation.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Field Summary
 
Fields inherited from class algs.model.problems.tictactoe.model.Player
logic, mark, OMARK, score, XMARK
 
Constructor Summary
RandomPlayer(char mark)
          Construct a Random player who determines a move randomly from available open cells.
 
Method Summary
 IGameMove decideMove(IGameState state)
          Randomly make a move based upon the available logic of the game.
 java.util.Collection<IGameMove> validMoves(IGameState state)
          Return the valid moves for this player given the game state.
 
Methods inherited from class algs.model.problems.tictactoe.model.Player
eval, getMark, getOpponentMark, hashCode, logic, logic, score, score, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RandomPlayer

public RandomPlayer(char mark)
Construct a Random player who determines a move randomly from available open cells.

Parameters:
mark - Mark to be used for the player.
Method Detail

decideMove

public IGameMove decideMove(IGameState state)
Randomly make a move based upon the available logic of the game.

Specified by:
decideMove in class Player
Parameters:
state - Current board state
Returns:
random valid Move to make, or null if none is available.

validMoves

public java.util.Collection<IGameMove> validMoves(IGameState state)
Return the valid moves for this player given the game state.

Specified by:
validMoves in interface IPlayer
Overrides:
validMoves in class Player
Parameters:
state - Current game state position

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.