org.jscience.computing.game.tictactoe
Class TickTackToe

java.lang.Object
  extended by org.jscience.computing.game.AbstractGame
      extended by org.jscience.computing.game.tictactoe.TickTackToe
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, GamePlay

public class TickTackToe
extends AbstractGame

This class implements the game TickTackToe. The board positions are represented as follows:

0 1 23 4 56 7 8

See Also:
Serialized Form

Constructor Summary
TickTackToe()
          Creates a new TickTackToe object.
TickTackToe(java.lang.String name)
          Creates a new TickTackToe object.
 
Method Summary
 java.lang.Object clone()
          making sure that the internal non-primitive board representation is properly cloned to allow the deep-copy required for spawnChild()
 boolean equals(java.lang.Object obj)
          required to allow recognizing the same game status even after serialization (to support network games, GameBooks, etc.).
 int[] getWinner()
          getWinner() is checking for a triple (three-in-a-row).
 int hashCode()
          It's just some number derived from a portion of the board; not guaranteed to be unique for every game, but guaranteed to always be the same for the same board.
protected  GameMove[] listLegalMoves()
          DOCUMENT ME!
 int nextPlayer()
          DOCUMENT ME!
protected  boolean popMove()
          DOCUMENT ME!
protected  boolean pushMove(GameMove move)
          DOCUMENT ME!
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class org.jscience.computing.game.AbstractGame
clearRedoList, gameOver, getGameName, getLastMove, getLastPlayer, getLegalMoves, getLegalMoves, getMoveHistory, getNumberOfRedoMoves, getRedoList, getResult, isLegalMove, isWinner, loadFromFile, makeMove, numberOfMoves, numberOfPlayers, redoMove, resetLegalMoves, resetLists, saveToFile, spawnChild, undoLastMove, undoMoves
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TickTackToe

public TickTackToe()
Creates a new TickTackToe object.


TickTackToe

public TickTackToe(java.lang.String name)
Creates a new TickTackToe object.

Parameters:
name - DOCUMENT ME!
Method Detail

nextPlayer

public int nextPlayer()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getWinner

public int[] getWinner()
getWinner() is checking for a triple (three-in-a-row). If found, it returns an array with the player role that has the triple. If the board is full (after 9 moves) and no triple is found, an empty array is returned to represent a draw (i.e. no winner). Otherwise, null is returned (when the game is still in progress).

Returns:
DOCUMENT ME!

listLegalMoves

protected GameMove[] listLegalMoves()
DOCUMENT ME!

Specified by:
listLegalMoves in class AbstractGame
Returns:
DOCUMENT ME!

pushMove

protected boolean pushMove(GameMove move)
DOCUMENT ME!

Specified by:
pushMove in class AbstractGame
Parameters:
move - DOCUMENT ME!
Returns:
DOCUMENT ME!

popMove

protected boolean popMove()
DOCUMENT ME!

Specified by:
popMove in class AbstractGame
Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class AbstractGame
Returns:
DOCUMENT ME!

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
making sure that the internal non-primitive board representation is properly cloned to allow the deep-copy required for spawnChild()

Specified by:
clone in interface GamePlay
Overrides:
clone in class AbstractGame
Returns:
DOCUMENT ME!
Throws:
java.lang.CloneNotSupportedException - DOCUMENT ME!
See Also:
AbstractGame.spawnChild(GameMove)

hashCode

public int hashCode()
It's just some number derived from a portion of the board; not guaranteed to be unique for every game, but guaranteed to always be the same for the same board. (trading off performance vs. effectiveness - not really an issue for TickTackToe, but just to make a point ..)

Overrides:
hashCode in class java.lang.Object
Returns:
DOCUMENT ME!

equals

public boolean equals(java.lang.Object obj)
required to allow recognizing the same game status even after serialization (to support network games, GameBooks, etc.). A call to super.equals() is not needed here, as we only care about the board status and not the move history or anything else where the AbstractGame may differ.

Overrides:
equals in class java.lang.Object
Parameters:
obj - DOCUMENT ME!
Returns:
DOCUMENT ME!