|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectGomokuState
public class GomokuState
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 |
|---|
public static final int NONE
NONE - a constant indicating no player/piece
public static final int BLACK
BLACK - a constant indicating a black player/piece
public static final int WHITE
WHITE - a constant indicating a white player/piece
| Constructor Detail |
|---|
public GomokuState(int size)
GomokuState instance with an empty
size-by-size grid and black to play
size - an int value - grid size| Method Detail |
|---|
public int getSize()
getSize - returns the grid size
int value - grid size
public int getPiece(int row,
int column)
getPiece - given the row and
column, returns the piece (BLACK,
WHITE, or NONE) at that grid position
row - an int value - grid position rowcolumn - an int value - grid position column
int value - piece at given row and columnpublic int getPlayer()
getPlayer - returns the current player
(BLACK or WHITE)
int value - current player
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.
row - an int valuecolumn - an int value
boolean valuepublic 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.
int value - the winner
BLACK, WHITE, or NONE
(if there is no winner)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.
toString in class java.lang.ObjectString value - board text representationpublic 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.
clone in class java.lang.ObjectObject value - copy of this
GomokuState object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||