Class Puzzle

java.lang.Object
  extended byPuzzle

public class Puzzle
extends java.lang.Object

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

Puzzle

public Puzzle(java.lang.String name,
              int gridSize,
              int numCars,
              boolean[] orient,
              int[] size,
              int[] x,
              int[] y)
The main constructor for constructing a puzzle. You probably will never need to use this constructor directly, since ordinarily puzzles will be constructed by reading them in from a datafile using the readPuzzlesFromFile method. It is assumed that the goal car is always assigned index 0.

Parameters:
name - the name of the puzzle
gridSize - the size of one side of the puzzle grid
numCars - the number of cars on this puzzle
orient - the orientations of each car (true = vertical)
size - the sizes of each car
x - the x-coordinates of each car
y - the y-coordinates of each car
Method Detail

getNumCars

public int getNumCars()
Returns the number of cars for this puzzle.


getFixedPosition

public int getFixedPosition(int v)
Returns the fixed position of car v.


getCarSize

public int getCarSize(int v)
Returns the size (length) of car v.


getCarOrient

public boolean getCarOrient(int v)
Returns the orientation of car v, where true means that the car is vertically oriented.


incrementSearchCount

public void incrementSearchCount(int d)
Increments the search counter by d.


getSearchCount

public int getSearchCount()
Returns the current value of the search counter, which keeps a count of the number of nodes generated on the current search.


resetSearchCount

public void resetSearchCount()
Resets the search counter to 1 (for the initial node).


getName

public java.lang.String getName()
Returns the name of this puzzle.


getGridSize

public int getGridSize()
Returns the grid size of this puzzle, i.e., the length along each side.


getInitNode

public Node getInitNode()
Returns the initial (root) node of this puzzle.


readPuzzlesFromFile

public static Puzzle[] readPuzzlesFromFile(java.lang.String filename)
                                    throws java.io.FileNotFoundException,
                                           java.io.IOException
A static method for reading in a list of puzzles from the data file called filename. Each puzzle is described in the data file using the format described on the assignment. The set of puzzles is returned as an array of Puzzle's.

Throws:
java.io.FileNotFoundException
java.io.IOException