java.lang.ObjectEightPuzzle
public class EightPuzzle
| Constructor Summary | |
|---|---|
EightPuzzle()
Constructor for EightPuzzle. |
|
| Method Summary | |
|---|---|
void |
addAMove(int row,
int column)
Moves the number at the given row and column to the current empty row and column. |
void |
displayBoard()
Displays the board in this form (for example): |
boolean |
empty(int row,
int column)
Returns: true, if the square at row, column is empty. |
boolean |
gameWon()
Returns: True if there has been a win. |
int |
getMoves()
Returns: the number of moves. |
void |
help()
Provides "on-line" help to the user. |
void |
initBoard()
Initializes the board to numbers descending from 8 down to 1 in this configuration: |
boolean |
legalMove(int row,
int column)
Returns: true, if there is an adjacent square that is empty. |
int |
newColumn()
Returns: The current empty column (the "new" column that a piece would move to). |
int |
newRow()
Returns: The current empty row (the "new" row that a piece would move to). |
java.lang.String |
numberAt(int row,
int column)
Returns: the number at the row and column, as a string. |
void |
resetGame()
This re-initializes the board, and resets any necessary instance variables. |
int |
toInt(char ch)
Returns: The integer version of the character digit. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public EightPuzzle()
| Method Detail |
|---|
public void addAMove(int row,
int column)
public void displayBoard()
The current board: 8 | 7 | 6 ---------- 5 | 1 | 4 ---------- 2 | | 3
public boolean empty(int row,
int column)
public boolean gameWon()
public int getMoves()
public void help()
After the prompt "eightpuzzle>": Enter m directly followed by two digits (each 0, 1, or 2) to move. Enter q to quit. Enter n to start a new game. Enter h for help.
public void initBoard()
8 7 6 5 4 3 2 1
public boolean legalMove(int row,
int column)
public int newColumn()
public int newRow()
public java.lang.String numberAt(int row,
int column)
public void resetGame()
public int toInt(char ch)