public class RailroadRushHour
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
BLANK
character representation for an empty (blank) board space
|
char[][] |
board
characters are used to track the occupancy of grid cells
|
static int |
SIZE
number of interior grid squares on a side
|
Constructor and Description |
---|
RailroadRushHour(int goalRow,
int goalCol)
Create an empty board, ready for piece addition via addPiece(Piece).
|
Modifier and Type | Method and Description |
---|---|
void |
addPiece(Piece newPiece)
Add a piece to the board.
|
static RailroadRushHour |
expert40()
Return the last expert Railroad Rush Hour puzzle, the most difficult of the set.
|
java.util.ArrayList<PieceMove> |
getLegalMoves()
Return a list of legal moves for the current puzzle state.
|
boolean |
isSolved()
Return whether or not this puzzle is solved.
|
static RailroadRushHour |
junior1()
Return the first junior Railroad Rush Hour puzzle.
|
static RailroadRushHour |
junior10()
Return the last junior Railroad Rush Hour puzzle.
|
java.lang.String |
toString()
Return the String representation of the current puzzle state as a grid of characters that are either
(1) the character of the piece occupying the grid cell, or (2) a '+' if the grid cell is empty.
|
boolean |
tryMove(java.lang.String moveDescription)
Given a move description (a length 2 String with a piece character followed by a direction character),
attempt to make the move, and return whether or not it was legal and successful.
|
public static final int SIZE
public static final char BLANK
public char[][] board
public RailroadRushHour(int goalRow, int goalCol)
goalRow
- goal row for goal piecegoalCol
- goal column for goal piecepublic void addPiece(Piece newPiece)
newPiece
- new piece to be added to the boardpublic boolean tryMove(java.lang.String moveDescription)
moveDescription
- a length 2 String with a piece character followed by a direction characterpublic boolean isSolved()
public java.util.ArrayList<PieceMove> getLegalMoves()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public static RailroadRushHour junior1()
public static RailroadRushHour junior10()
public static RailroadRushHour expert40()