public class ChompGame
extends java.lang.Object
Chomp
for a text-based interface to this class.
Note: While the toString() method builds a String, there should be no printing and no input/output in general in this implementation.Constructor and Description |
---|
ChompGame(int rows,
int cols)
Create an initial board with the given number of rows and columns with all positions unchomped.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkIfChomped(int row,
int col)
Return whether or not the board has been chomped at 0-based index position [row][col].
|
boolean |
chompAt(int row,
int col)
If a chomp at [row][col] is legal, then (1) chomp all positions in the rectangle of positions with [row][col] being the upper-left-most and [rows-1][cols-1] being the lower-right-most, (2) change the current player from 1 to 2 or vice versa, and (3) return true.
|
int |
getCols()
Get the number of columns in the board.
|
int |
getCurrentPlayer()
Return the current player number, initially 1 and alternating between 1 and 2 with each successive legal play.
|
int |
getRows()
Get the number of rows in the board.
|
boolean |
isGameOver()
Return whether or not the game is over, that is, whether or not position [0][0] has been chomped.
|
boolean |
isLegalChomp(int row,
int col)
Return whether or not a chomp at [row][col] would be a legal chomp, that is, would be both in bounds and not previously chomped.
|
java.lang.String |
toString()
Return the String representation of the board, such that each line is terminated with a newline, the first line consists of a space and the digits 0 through (cols-1)
and following lines consist of the row index digit followed by asterisks/spaces representing unchomped/chomped positions, respectively.
|
public ChompGame(int rows, int cols)
rows
- the number of rows in the boardcols
- the number of columns in the boardpublic boolean checkIfChomped(int row, int col)
row
- 0-based row indexcol
- 0-based column indexpublic boolean isLegalChomp(int row, int col)
row
- hypothetical chomp rowcol
- hypothetical chomp columnpublic boolean chompAt(int row, int col)
row
- row of attempted chompcol
- column of attempted chomppublic boolean isGameOver()
public int getRows()
public int getCols()
public int getCurrentPlayer()
chompAt(int row, int col)
method when a legal chomp move is made.public java.lang.String toString()
toString
in class java.lang.Object