Algorithm
Development Kit 1.0

algs.model.problems.tictactoe.model
Class Move

java.lang.Object
  extended by algs.model.problems.tictactoe.model.Move
All Implemented Interfaces:
IGameMove
Direct Known Subclasses:
PlaceMark

public abstract class Move
extends java.lang.Object
implements IGameMove

Represents a Move on the TicTacToe Board.

At this level of abstraction, we cannot define an Abstraction Function because there is no known representation.

However, we must state unequivocally that each Move object must define a proper toString() because otherwise the hashCode method defined here will not work.

Also, the equals(Object o) method must be implemented by all subclasses.

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

Constructor Summary
Move()
           
 
Method Summary
abstract  boolean execute(IGameState board)
          Makes the move on the given TicTacToe Board.
 int hashCode()
          Ensure that we can use Move objects within hashtables by simplying calculating hashCode values based upon toString() for the Move subclasses.
abstract  boolean isValid(IGameState board)
          Determines if move can be made on the given TicTacToe Board.
abstract  boolean undo(IGameState board)
          Removes the effect of the move from the TicTacToe Board.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Move

public Move()
Method Detail

isValid

public abstract boolean isValid(IGameState board)
Determines if move can be made on the given TicTacToe Board. REQUIRES: board != null

Specified by:
isValid in interface IGameMove
Parameters:
board - game tree state to be inspected by move
Returns:
true if the move can be made; false, otherwise.

execute

public abstract boolean execute(IGameState board)
Makes the move on the given TicTacToe Board. REQUIRES: board != null MODIFIES: board EFFECTS: board state is updated as appropriate for the given move.

Specified by:
execute in interface IGameMove
Parameters:
board - game tree state to be updated by this move
Returns:
true if the move was valid given the board configuration.

undo

public abstract boolean undo(IGameState board)
Removes the effect of the move from the TicTacToe Board. REQUIRES: (board != null) and (this was most recent move on board) MODIFIES: board EFFECTS: board state is updated as if this move had not happened.

Specified by:
undo in interface IGameMove
Parameters:
board - game tree state to be undone one move

hashCode

public int hashCode()
Ensure that we can use Move objects within hashtables by simplying calculating hashCode values based upon toString() for the Move subclasses.

Overrides:
hashCode in class java.lang.Object

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.