Class GameState

java.lang.Object
  |
  +--GameState

public class GameState
extends java.lang.Object

An object of this class represents the state of the game, including the current board position (accessible using the square method) and whose turn it is (accessible using the turn method). A new game position can be generated using the applyMove method. Squares are indexed by pairs x,y where each is 0, 1 or 2. Players are encoded as +1 or -1, with +1 moving first.


Constructor Summary
GameState()
          Constructs a new game state with no pieces on the board, and +1's turn.
GameState(int[][] squares, int turn)
          Constructs a new game state with pieces on board as specified by squares; the player whose turn it is is specified by turn.
 
Method Summary
 GameState applyMove(Move m)
          Constructs and returns a new game state obtained from this game state by applying the given Move object to this GameState.
 boolean equals(java.lang.Object o)
          Compares the specified object to this game state for equality.
 int hashCode()
          Returns the hash code for this game position.
 int square(int x, int y)
          Returns the contents of square x,y on the current board position.
 java.lang.String toLongString(int indentBy)
          Produces a multi-line string description of the GameState object indented indentBy spaces.
 java.lang.String toString()
          Produces a one line string description of the GameState object.
 int turn()
          Returns the player (+1 or -1) whose turn it is.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GameState

public GameState()
Constructs a new game state with no pieces on the board, and +1's turn.


GameState

public GameState(int[][] squares,
                 int turn)
Constructs a new game state with pieces on board as specified by squares; the player whose turn it is is specified by turn.

Parameters:
squares - squares[x][y] specifies the contents of the square x,y. +1 or -1 indicates that one of the players has a piece in this square. 0 indicates that the square is empty.
Method Detail

square

public int square(int x,
                  int y)
Returns the contents of square x,y on the current board position.


turn

public int turn()
Returns the player (+1 or -1) whose turn it is.


applyMove

public GameState applyMove(Move m)
Constructs and returns a new game state obtained from this game state by applying the given Move object to this GameState. No error checking is done to be sure that such a move is legal or possible.

Parameters:
m - Move to be applied
Returns:
new game state

hashCode

public int hashCode()
Returns the hash code for this game position. This method is provided so that GameState objects can be reliably inserted into hash tables and other data structures provided with the Standard Java Platform.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Compares the specified object to this game state for equality. Returns true if the object is also a game state, and if it represents an identical board position, and it is the same player's turn.

Overrides:
equals in class java.lang.Object
Parameters:
o - object to be compared

toString

public java.lang.String toString()
Produces a one line string description of the GameState object.

Overrides:
toString in class java.lang.Object

toLongString

public java.lang.String toLongString(int indentBy)
Produces a multi-line string description of the GameState object indented indentBy spaces.