studentacct.tictactoe
Class TicTacToeState

java.lang.Object
  extended by studentacct.tictactoe.TicTacToeState
All Implemented Interfaces:
game.GameState, TicTacToeStateInterface

public class TicTacToeState
extends java.lang.Object
implements game.GameState, TicTacToeStateInterface

This represents the state of the Tic Tac Toe board and this class is written by the student.

Author:

Constructor Summary
TicTacToeState()
          Default constructor.
TicTacToeState(char[][] board)
          Constructor that sets the state of the board to a copy of the specified board.
 
Method Summary
 java.lang.Object clone()
          Returns a new TicTacToeState object whose contents is exactly the same as this instance.
 java.lang.String dump()
          Generates and returns a multi-line string representing a human-readable pretty version of the board.
 boolean equals(TicTacToeStateInterface state)
          Determines if the specified instance TicTacToeState has the same contents as this instance.
 char[][] getBoard()
          Returns a reference to the two-dimensional array storing the board state.
 java.lang.String toString()
          Generates and returns a single line string that must contain exactly nine characters representing the state of the board.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TicTacToeState

public TicTacToeState()
Default constructor. This should initialize the entire board to being unplayed (i.e., each cell should hold a space character.)


TicTacToeState

public TicTacToeState(char[][] board)
Constructor that sets the state of the board to a copy of the specified board. Note that you must not store a reference to the board that is passed in. Instead, you must allocate a new two-dimensional array and copy the contents from the parameter.

Parameters:
board - the board to copy
Method Detail

clone

public java.lang.Object clone()
Returns a new TicTacToeState object whose contents is exactly the same as this instance. Do not use Java's clone() method in the implementation of this method. Rather, just use your existing constructors and copy whatever state needs to be copied.

Specified by:
clone in interface game.GameState
Overrides:
clone in class java.lang.Object
Returns:
the new instance of TicTacToeState

equals

public boolean equals(TicTacToeStateInterface state)
Determines if the specified instance TicTacToeState has the same contents as this instance.

Parameters:
state - The other instance to check equality with
Returns:
true if the specified parameter is equal to this, or false otherwise

getBoard

public char[][] getBoard()
Returns a reference to the two-dimensional array storing the board state.

Specified by:
getBoard in interface TicTacToeStateInterface
Returns:
the board

dump

public java.lang.String dump()
Generates and returns a multi-line string representing a human-readable pretty version of the board. Generates and returns a multi-line string representing a human-readable pretty version of the board. This is like toString() in that it should return a String that represents the board. But while toString() has a very specific pre-defined single-line format, dump() can return a multi-line String in any format you wish. When you run the driver to test your game, this dump() method will be called to display the state of the game after each move, and so you should generate a string that will make it easy for you to understand the state of the game.

Specified by:
dump in interface game.GameState
Returns:
the string that represents the board

toString

public java.lang.String toString()
Generates and returns a single line string that must contain exactly nine characters representing the state of the board. The nine characters must each be space, 'O' or 'X', and must represent the layout of the board in in the order specified in the project description of the TicTacToeState class.

Overrides:
toString in class java.lang.Object