|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectPuzzle
This is the class for representing a particular rush hour puzzle. Methods are provided for accessing information about a puzzle, and also for reading in a list of puzzles from a data file. In addition, this class maintains a counter of the number of search nodes that have been expanded for this puzzle. Methods for accessing, incrementing or resetting this counter are also provided.
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. The fixed dimension is stored here as part of the puzzle. Also stored here are the sizes and orientations of the cars, the size of the puzzle grid, the name of the puzzle and the initial (root) search node of the puzzle.
The goal car is always assigned index 0.
Constructor Summary | |
Puzzle(java.lang.String name,
int gridSize,
int numCars,
boolean[] orient,
int[] size,
int[] x,
int[] y)
The main constructor for constructing a puzzle. |
Method Summary | |
boolean |
getCarOrient(int v)
Returns the orientation of car v, where true means that the car is vertically oriented. |
int |
getCarSize(int v)
Returns the size (length) of car v. |
int |
getFixedPosition(int v)
Returns the fixed position of car v. |
int |
getGridSize()
Returns the grid size of this puzzle, i.e., the length along each side. |
Node |
getInitNode()
Returns the initial (root) node of this puzzle. |
java.lang.String |
getName()
Returns the name of this puzzle. |
int |
getNumCars()
Returns the number of cars for this puzzle. |
int |
getSearchCount()
Returns the current value of the search counter, which keeps a count of the number of nodes generated on the current search. |
void |
incrementSearchCount(int d)
Increments the search counter by d. |
static Puzzle[] |
readPuzzlesFromFile(java.lang.String filename)
A static method for reading in a list of puzzles from the data file called filename. |
void |
resetSearchCount()
Resets the search counter to 1 (for the initial node). |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Puzzle(java.lang.String name, int gridSize, int numCars, boolean[] orient, int[] size, int[] x, int[] y)
name
- the name of the puzzlegridSize
- the size of one side of the puzzle gridnumCars
- the number of cars on this puzzleorient
- the orientations of each car (true = vertical)size
- the sizes of each carx
- the x-coordinates of each cary
- the y-coordinates of each carMethod Detail |
public int getNumCars()
public int getFixedPosition(int v)
public int getCarSize(int v)
public boolean getCarOrient(int v)
public void incrementSearchCount(int d)
public int getSearchCount()
public void resetSearchCount()
public java.lang.String getName()
public int getGridSize()
public Node getInitNode()
public static Puzzle[] readPuzzlesFromFile(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |