|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectState
This is the class for representing a single state of the rush hour puzzle. Methods are provided for constructing a state, for accessing information about a state, for printing a state, and for expanding a state (i.e., obtaining a list of all states immediately reachable from it).
Every car is constrained to only move horizontally or vertically. Therefore, each car has one dimension along which it is fixed, and another dimension along which it can be moved. This variable dimension is stored here as part of the state. A link to the puzzle with which this state is associated is also stored. Note that the goal car is always assigned index 0.
To make it easier to use State objects with some of the data structures provided as part of the Standard Java Platform, we also have provided hashCode and equals methods. You probably will not need to access these methods directly, but they are likely to be used implicitly if you take advantage of the Java Platform. These methods define two State objects to be equal if they refer to the same Puzzle object, and if they indicate that the cars have the identical variable positions in both states. The hashcode is designed to satisfy the general contract of the Object.hashCode method that it overrides, with regard to the redefinition of equals.
Constructor Summary | |
State(Puzzle puzzle,
int[] varPos)
The main constructor for constructing a state. |
Method Summary | |
boolean |
equals(java.lang.Object o)
Returns true if and only if this state is considered equal to the given object. |
State[] |
expand()
Computes all of the states immediately reachable from this state and returns them as an array of states. |
int[][] |
getGrid()
Computes a grid representation of the state. |
Puzzle |
getPuzzle()
Returns the puzzle associated with this state. |
int |
getVariablePosition(int v)
Returns the variable position of car v. |
int |
hashCode()
Returns a hash code value for this State object. |
boolean |
isGoal()
Returns true if and only if this state is a goal state. |
void |
print()
Prints to standard output a primitive text representation of the state. |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public State(Puzzle puzzle, int[] varPos)
puzzle
- the puzzle that this state is associated withvarPos
- the variable position of each of the cars in this stateMethod Detail |
public boolean isGoal()
public int getVariablePosition(int v)
public Puzzle getPuzzle()
public void print()
public int[][] getGrid()
public State[] expand()
public int hashCode()
public boolean equals(java.lang.Object o)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |