Class Configuration

java.lang.Object
  |
  +--Configuration

public class Configuration
extends java.lang.Object

A Configuration represents an arrangement of pieces within the box.


Field Summary
static int examined
           
static int maxDistance
          maximum required solution length found so far
static InputSpec spec
          the input specifications
 
Constructor Summary
Configuration()
          Make a new, empty configuration.
Configuration(Configuration config)
          Make a copy of an existing configuration.
 
Method Summary
 boolean equals(Configuration config)
          Does this configuration have the same piece shapes and locations as another configuration?
 boolean occupied(int x, int y)
          Is the square (x, y) occupied by any piece in this configuration, or by a box wall? (Anything outside the box count as a box wall too.)
 boolean placePiece(int shapeIndex, java.awt.Point where)
          Can a piece of a given shape be placed into this configuration with upper left corner at (x, y)? If so, place it there & return true.
 void prettyPrint()
          Print a configuration for human consumption, in a nice ASCII grid layout.
 void printSolution()
          Print the solution.
 void printSolution2()
           
 void puzzleSearch(int x, int y)
          Try all possible piece placements at (x, y) (including 'filling' it with empty space), and for each one, recursively try to fill the next spot in the box.
 void removePiece()
          Remove the last piece added to this configuration.
 void solve()
          Can this configuration be solved by making some sequence of moves? If so, and the minimum-length solution is longer than the longest found so far, print it out.
 boolean solved()
          Is this configuration solved? It's solved if the goal piece is in the goal location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

examined

public static int examined

spec

public static InputSpec spec
the input specifications

maxDistance

public static int maxDistance
maximum required solution length found so far
Constructor Detail

Configuration

public Configuration()
Make a new, empty configuration.

Configuration

public Configuration(Configuration config)
Make a copy of an existing configuration.
Method Detail

puzzleSearch

public void puzzleSearch(int x,
                         int y)
Try all possible piece placements at (x, y) (including 'filling' it with empty space), and for each one, recursively try to fill the next spot in the box. If we've thus filled the entire box, we have a candidate puzzle layout; see if it can be solved.

solve

public void solve()
Can this configuration be solved by making some sequence of moves? If so, and the minimum-length solution is longer than the longest found so far, print it out.

solved

public boolean solved()
Is this configuration solved? It's solved if the goal piece is in the goal location.

printSolution

public void printSolution()
Print the solution. We recursively call printSolution2 on all predecessor positions, until there are no more. Then we know we're at the starting configuration, and can print it. On the way back up the recursion stack, print out the move sequence, which we stored in the configurations. Successive shifts of the same piece are counted (and printed) as a single move.

printSolution2

public void printSolution2()

prettyPrint

public void prettyPrint()
Print a configuration for human consumption, in a nice ASCII grid layout.

placePiece

public boolean placePiece(int shapeIndex,
                          java.awt.Point where)
Can a piece of a given shape be placed into this configuration with upper left corner at (x, y)? If so, place it there & return true. Otherwise return false.

removePiece

public void removePiece()
Remove the last piece added to this configuration.

occupied

public boolean occupied(int x,
                        int y)
Is the square (x, y) occupied by any piece in this configuration, or by a box wall? (Anything outside the box count as a box wall too.)

equals

public boolean equals(Configuration config)
Does this configuration have the same piece shapes and locations as another configuration?