Algorithm
Development Kit 1.0

algs.model.problems.tictactoe.model
Class PlaceMark

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

public class PlaceMark
extends Move

Place a mark on the TicTacToe Board.

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

Field Summary
protected  int col
          The column to contain the mark.
protected  Player player
          The player making the move.
protected  int row
          The row to contain the mark.
 
Constructor Summary
PlaceMark(int col, int row, Player player)
          Construct a placeMark move with given (col,row) and mark to be placed.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determine equality based on structure.
 boolean execute(IGameState gameState)
          Place a mark on the TicTacToeBoard.
 int getColumn()
          Return the column for this move.
 Player getPlayer()
          Return the player for this move.
 int getRow()
          Return the row for this move.
 boolean isValid(IGameState gameState)
          Determines if move is valid.
 java.lang.String toString()
          Return object in readable form.
 boolean undo(IGameState gameState)
          Undoes the given move and returns true, or returns false if unable to undo.
 
Methods inherited from class algs.model.problems.tictactoe.model.Move
hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

col

protected int col
The column to contain the mark. Available to subclasses.


row

protected int row
The row to contain the mark. Available to subclasses.


player

protected Player player
The player making the move. Available to subclasses.

Constructor Detail

PlaceMark

public PlaceMark(int col,
                 int row,
                 Player player)
Construct a placeMark move with given (col,row) and mark to be placed.

REQUIRES: player.mark != ' ' AND 0 <= col < # of columns in board AND 0 <= row < # of rows in board.

Method Detail

isValid

public boolean isValid(IGameState gameState)
Determines if move is valid. PlaceMark is valid if board is empty at desired location.

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

execute

public boolean execute(IGameState gameState)
Place a mark on the TicTacToeBoard. If move is invalid, then false is returned, otherwise the board state is updated and true is returned.

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

undo

public boolean undo(IGameState gameState)
Undoes the given move and returns true, or returns false if unable to undo.

Specified by:
undo in interface IGameMove
Specified by:
undo in class Move
Parameters:
gameState - game tree state to be undone one move
See Also:
Move.undo(IGameState)

equals

public boolean equals(java.lang.Object o)
Determine equality based on structure.

Overrides:
equals in class java.lang.Object
Parameters:
o - Object of class PlaceMark against which equality is being evaluated.

getColumn

public int getColumn()
Return the column for this move.


getRow

public int getRow()
Return the row for this move.


getPlayer

public Player getPlayer()
Return the player for this move.


toString

public java.lang.String toString()
Return object in readable form.

Overrides:
toString 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.