public class RookJumpingMaze extends java.lang.Object implements State, java.lang.Cloneable
step() specification: Pick a non-goal grid position at random and change it to a different legal jump number.
undo() specification: Undo the change of the previous step() call. You may assume that there is at least one step() call between each undo() call, that is, you are only required to undo the most recent step.
energy() specification: Return the negated distance from the start position to the goal grid position.
If the goal is unreachable from the start, return the negated value of RookJumpingMaze.UNREACHED
.
clone() specification: Perform a deep clone of this RookJumpingMaze, such that changes to the copy do not affect the original or vice versa.
toString() specification: For each column, append the jump number and a trailing space. At the end of each row (after the final trailing space), append a newline character.
Modifier and Type | Field and Description |
---|---|
static int |
UNREACHED
low-value integer constant indicating that a grid position cannot be reached by search.
|
Constructor and Description |
---|
RookJumpingMaze(int size)
Construct a RookJumpingMaze that is a
size -by-size grid with random, legal jump numbers for each position. |
Modifier and Type | Method and Description |
---|---|
RookJumpingMaze |
clone() |
double |
energy() |
int |
getJump(int row,
int col)
Return the jump number for the given row and column.
|
int |
getSize()
Return the size of the square maze grid.
|
void |
step() |
java.lang.String |
toString() |
void |
undo() |
public static final int UNREACHED
public RookJumpingMaze(int size)
size
-by-size
grid with random, legal jump numbers for each position.
A legal jump number is a positive integer such that one can move exactly that many grid cells in at least one orthogonal direction
without going going out of bounds of the grid. For example, in a 5-by-5 grid, legal jumps along the edge cells range from 1 to 4,
whereas the center cell [2][2]
has legal jumps ranging from 1 to 2.
The start of the maze will be at [0][0]
, and the goal of the maze will be at [size-1][size-1]
.size
- - number of rows/columnspublic int getJump(int row, int col)
row
- the given rowcol
- the given columnpublic int getSize()
public RookJumpingMaze clone()
public java.lang.String toString()
toString
in class java.lang.Object