Algorithm
Development Kit 1.0

algs.model.problems.tictactoe.model
Class Logic

java.lang.Object
  extended by algs.model.problems.tictactoe.model.Logic
Direct Known Subclasses:
StraightLogic

public abstract class Logic
extends java.lang.Object

Contains logic for a particular TicTacToe Variation about how to interpret the attempt to select a cell (Col, Row) as the desired move. Note: This will not capture all cases, but will get most.

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

Constructor Summary
Logic()
           
 
Method Summary
abstract  Logic copy()
          Each logic must implement 'copy' to properly be used when evaluating future moves.
 void initializeState(TicTacToeState state)
          Enable variations to instantiate the stored data with each game state.
abstract  Move interpretMove(IGameState board, int col, int row, Player player)
          Method to determine the type of move that the user has selected.
 int maxNumberMoves()
          Most TicTacToe variations are guaranteed to have a fixed number of moves before the game is either won, lost, or drawn.
abstract  java.lang.String rules()
          Return a description of the game and how it is to be played.
 IGameScore score()
          Each logic may have its own evaluation function to use, which would override the default evaluation stored with the game state.
 java.util.Collection<IGameMove> validMoves(IPlayer ip, IGameState state)
          Return the valid moves at this board state for the given player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Logic

public Logic()
Method Detail

interpretMove

public abstract Move interpretMove(IGameState board,
                                   int col,
                                   int row,
                                   Player player)
Method to determine the type of move that the user has selected. Subclasses should override this method so they will be able to properly construct the appropriate move given the context.

Parameters:
board - current board state
col - selected column
row - selected row
player - player making the move
Returns:
null if move is invalid; otherwise a valid Move object.

validMoves

public java.util.Collection<IGameMove> validMoves(IPlayer ip,
                                                  IGameState state)
Return the valid moves at this board state for the given player.


score

public IGameScore score()
Each logic may have its own evaluation function to use, which would override the default evaluation stored with the game state. Subclasses should only override this method, naturally, if there is a special evaluation function relevant for the logic.


copy

public abstract Logic copy()
Each logic must implement 'copy' to properly be used when evaluating future moves.

Returns:
a Copy of the Logic object.

maxNumberMoves

public int maxNumberMoves()
Most TicTacToe variations are guaranteed to have a fixed number of moves before the game is either won, lost, or drawn. However, to plan for some variations that are more extensive, this method determines (for the variation) the cut-off point at which a game must be considered a draw. We set a reasonable default, and allow variations to extend as needed.

Returns:
the maximum number of allowed moves at which time a draw must be determined if the game has not been won.

initializeState

public void initializeState(TicTacToeState state)
Enable variations to instantiate the stored data with each game state. Override by subclasses, as needed. Provide default null implementation here when not needed to simplify subclasses.


rules

public abstract java.lang.String rules()
Return a description of the game and how it is to be played.


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.