Class GomokuState

java.lang.Object
  extended by GomokuState
All Implemented Interfaces:
java.lang.Cloneable

public class GomokuState
extends java.lang.Object
implements java.lang.Cloneable

GomokuState - a representation of a basic Gomoku game state. See http://en.wikipedia.org/wiki/Gomoku for game rules.


Field Summary
static int BLACK
          BLACK - a constant indicating a black player/piece
static int NONE
          NONE - a constant indicating no player/piece
static int WHITE
          WHITE - a constant indicating a white player/piece
 
Constructor Summary
GomokuState(int size)
          Creates GomokuState instance with an empty size-by-size grid and black to play
 
Method Summary
 java.lang.Object clone()
          clone - returns a copy of this GomokuState object.
 int getPiece(int row, int column)
          getPiece - given the row and column, returns the piece (BLACK, WHITE, or NONE) at that grid position
 int getPlayer()
          getPlayer - returns the current player (BLACK or WHITE)
 int getSize()
          getSize - returns the grid size
 int getWinner()
          getWinner - returns BLACK, WHITE, or NONE, if black has won, white has won, or no player has won, respectively.
 boolean playPiece(int row, int column)
          playPiece - the current player tries to play a piece at the given position.
 java.lang.String toString()
          toString - returns a String representation of the board.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
NONE - a constant indicating no player/piece

See Also:
Constant Field Values

BLACK

public static final int BLACK
BLACK - a constant indicating a black player/piece

See Also:
Constant Field Values

WHITE

public static final int WHITE
WHITE - a constant indicating a white player/piece

See Also:
Constant Field Values
Constructor Detail

GomokuState

public GomokuState(int size)
Creates GomokuState instance with an empty size-by-size grid and black to play

Parameters:
size - an int value - grid size
Method Detail

getSize

public int getSize()
getSize - returns the grid size

Returns:
an int value - grid size

getPiece

public int getPiece(int row,
                    int column)
getPiece - given the row and column, returns the piece (BLACK, WHITE, or NONE) at that grid position

Parameters:
row - an int value - grid position row
column - an int value - grid position column
Returns:
an int value - piece at given row and column

getPlayer

public int getPlayer()
getPlayer - returns the current player (BLACK or WHITE)

Returns:
an int value - current player

playPiece

public boolean playPiece(int row,
                         int column)
playPiece - the current player tries to play a piece at the given position. If the move is illegal (e.g. out of bounds, already occupied), false is returned. Otherwise, the current player's piece is placed at the given row and column, the current player changes, and true is returned.

Parameters:
row - an int value
column - an int value
Returns:
a boolean value

getWinner

public int getWinner()
getWinner - returns BLACK, WHITE, or NONE, if black has won, white has won, or no player has won, respectively. A player wins by placing 5 pieces consecutively in a line horizontally, vertically, or diagonally.

Returns:
an int value - the winner BLACK, WHITE, or NONE (if there is no winner)

toString

public java.lang.String toString()
toString - returns a String representation of the board. A '.' denotes an empty grid position. A '*' denotes a black piece. A 'o' denotes a white piece.

Overrides:
toString in class java.lang.Object
Returns:
a String value - board text representation

clone

public java.lang.Object clone()
clone - returns a copy of this GomokuState object. This should be a deep clone. Changes to the copy should not alter the original, and vice versa.

Overrides:
clone in class java.lang.Object
Returns:
an Object value - copy of this GomokuState object