|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--edu.lhup.ai.tictactoe.Board
A concrete board implementation that implements the rules of tic-tac-toe.
This software is for educational purposes only.
| Field Summary | |
(package private) static int |
OTURN
|
(package private) static int |
OWINS
|
(package private) static int |
TIE
|
(package private) static int |
XTURN
|
(package private) static int |
XWINS
|
| Constructor Summary | |
Board()
Creates an empty Board object w/o players |
|
Board(Board other)
Creates a new Board object based on an existing Board object. |
|
Board(IMove[] moves,
IPlayer[] players)
Creates a new Board object from an array of moves. |
|
Board(IPlayer[] players)
Creates an empty Board object. |
|
| Method Summary | |
(package private) static StringBuffer |
createStringBuffer()
|
(package private) static IPiece |
emptyPiece()
|
boolean |
equals(Object other)
|
IPiece[][] |
getBoard()
|
String |
getDescription()
|
(package private) static Move |
getMove(IPiece piece,
int row,
int col)
|
IPlayer[] |
getPlayers()
|
String |
getShortDescription()
|
int |
getState()
|
IPlayer |
getWinner()
|
int |
hashCode()
|
Iterator |
moveIterator()
|
void |
moves(Collection col)
Populates the specified Collection with the set of all
currently legal moves. |
(package private) static IPiece |
oPiece()
|
IMove |
peekMove()
|
Iterator |
playerIterator()
|
IMove |
popMove()
Removes the last move from this board's stack. |
void |
pushMove(IMove move)
Adds the specified move to this board's stack. |
void |
pushMove(String strMove)
Adds the specified move to this board's stack. |
void |
resetState()
Returns this board to its initial state so it will be ready for a new game. |
void |
setPlayers(IPlayer[] players)
Specifies the players that will be playing this game. |
String |
toString()
|
(package private) static IPiece |
xPiece()
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
static final int XWINS
static final int OWINS
static final int TIE
static final int XTURN
static final int OTURN
| Constructor Detail |
public Board()
public Board(IPlayer[] players)
throws StateException
public Board(IMove[] moves,
IPlayer[] players)
throws StateException
public Board(Board other)
throws StateException
| Method Detail |
public void setPlayers(IPlayer[] players)
throws StateException
IBoardplayers that will be playing this game.
setPlayers in interface IBoardplayers - an array of players that will be playing
the game.
StateException - if the specified number of type of players cannot
play this game.public IPlayer[] getPlayers()
getPlayers in interface IBoardpublic Iterator playerIterator()
playerIterator in interface IBoardIterator of the players currently
playing this game. The players will be iterated in the order in which
they are allowed to take their turns. The iterator will be empty if
this game has ended.public IPlayer getWinner()
getWinner in interface IBoardplayer that has won this game, or
null if there is currently no winner, or if this game
has ended in a tie.public IMove peekMove()
peekMove in interface IBoard
public void pushMove(String strMove)
throws StateException
move to this board's stack.
The move is specified using a string representation
of the move. For example the move "2,1" would place a piece at
row 2, column 1. The piece placed on the board will be the piece
that is assocated with the player whos turn is next. For example,
if it is the "X player's" turn then an X piece will be placed on the
board.
The first move must be made by the "X player". Moves must alternate between the "X player" and the "O player". Finally, moves can only be made on an empty space.
pushMove in interface IBoardstrMove - the move that will be added to the stack.
StateException - if the specified move is illegal.
public void pushMove(IMove move)
throws StateException
move to this board's stack.
The first move must be made by the "X player". Moves
must alternate between the "X player" and the "O player". Finally,
moves can only be made on an empty space.
pushMove in interface IBoardStateException - if the specified move is illegal.public IMove popMove()
IBoardmove from this board's stack.
popMove in interface IBoardpublic IPiece[][] getBoard()
getBoard in interface IBoardpublic int getState()
getState in interface IBoardpublic void resetState()
IBoard
resetState in interface IBoardpublic Iterator moveIterator()
moveIterator in interface IBoardIterator of the set of all
currently legal moves.public void moves(Collection col)
IBoardCollection with the set of all
currently legal moves.
moves in interface IBoardcol - the Collection that will be populated with the set of
all currently legal moves.public String getDescription()
getDescription in interface IBoardpublic String getShortDescription()
getShortDescription in interface IBoardpublic String toString()
toString in class Objectpublic boolean equals(Object other)
equals in class Objectpublic int hashCode()
hashCode in class Objectstatic IPiece emptyPiece()
static IPiece xPiece()
static IPiece oPiece()
static StringBuffer createStringBuffer()
static Move getMove(IPiece piece,
int row,
int col)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||