|
Algorithm Development Kit 1.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectalgs.model.problems.tictactoe.model.TicTacToeBoard
public class TicTacToeBoard
Represents the state of a 3x3 TicTacToe board. Each element within the board is a char, either 'x' or 'o'. Note that an empty square should be represented by the char ' ';
Field Summary | |
---|---|
protected char[][] |
cells
Store data as a 3x3 array of cells. |
static char |
EMPTY
Empty Marker. |
static Cell[][] |
filters
These will reflect the cell ordering. |
static int |
MaxC
Max number of columns. |
static int |
MaxR
Max number of rows. |
Constructor Summary | |
---|---|
TicTacToeBoard()
Constructor for TicTacToe Board. |
|
TicTacToeBoard(char[][] test)
Helper constructor for initializing boards to arbitrary configurations. |
|
TicTacToeBoard(TicTacToeBoard board)
Copy Constructor for TicTacToe Board. |
Method Summary | |
---|---|
void |
clear(int col,
int row)
Clears the cell at given location. |
boolean |
equals(java.lang.Object o)
|
boolean |
gameWon()
Determines whether game has been won. |
boolean |
gameWon(char mark)
Determines whether game has been won by given mark. |
char |
get(int col,
int row)
Returns marker at given spot. |
int |
hashCode()
To enable this board to be a key in a Hashtable. |
boolean |
isClear()
Return true if entire board is empty. |
boolean |
isClear(int col,
int row)
Determines if cell is empty. |
boolean |
isDraw()
Determine if a game is a draw because all cells are occupied but the game is not won. |
int |
numColumns()
Return the number of cells on the board. |
int |
numRows()
Return the number of rows on the board. |
boolean |
sameBoard(TicTacToeBoard board2)
Determine if two Boards are the same (including rotations and reflections). |
boolean |
set(int col,
int row,
char mark)
Sets the cell at given location to contain mark. |
java.lang.String |
toString()
Return the state of the board as a String. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected char[][] cells
public static final char EMPTY
public static final int MaxC
public static final int MaxR
public static final Cell[][] filters
Constructor Detail |
---|
public TicTacToeBoard()
public TicTacToeBoard(char[][] test)
public TicTacToeBoard(TicTacToeBoard board)
Method Detail |
---|
public int numColumns()
public int numRows()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public boolean gameWon()
true
if some player has won game.public boolean gameWon(char mark)
mark
- character of player mark to be investigated.
true
if player with given mark has won game.public char get(int col, int row)
col
- desired columnrow
- desired row
public boolean isClear(int col, int row)
col
- desired columnrow
- desired row
true
if cell is empty; false
otherwisepublic boolean isDraw()
public void clear(int col, int row)
col
- column of cell to clearrow
- row of cell to clearpublic boolean set(int col, int row, char mark)
col
- column of cell to setrow
- row of cell to setmark
- mark to be inserted.
true
if cell was empty, otherwise returns false
.public boolean isClear()
true
if all cells are set to EMPTY.public boolean sameBoard(TicTacToeBoard board2)
board2
-
|
Algorithm Development Kit 1.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |