Class Piece

java.lang.Object
  |
  +--Piece

public class Piece
extends java.lang.Object

A Piece represents an instance of a puzzle piece, with a location.


Field Summary
static InputSpec spec
          the input specifications
 
Constructor Summary
Piece(int whichShape, java.awt.Point w)
          Make a new piece of a given shape, in a given place.
Piece(Piece piece)
          Make a copy of a piece.
 
Method Summary
 boolean canSlide(int dir, Configuration config)
          Can this piece slide in the specified direction, in the given configuration? We must make sure that the squares the piece would slide into are vacant.
 boolean equals(Piece piece)
          Is this piece the same shape as and in the same location as another piece?
 boolean isGoal()
          Is this the goal piece?
 boolean occupies(int x, int y)
          Does this piece occupy the spot (x, y)?
 void print()
          Print out the piece info.
 Shape shape()
          What is this piece's shape?
 void shift(int dir)
          Shift the piece.
 boolean solved()
          Is this the goal piece, in the goal position?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spec

public static InputSpec spec
the input specifications
Constructor Detail

Piece

public Piece(int whichShape,
             java.awt.Point w)
Make a new piece of a given shape, in a given place.

Piece

public Piece(Piece piece)
Make a copy of a piece.
Method Detail

solved

public boolean solved()
Is this the goal piece, in the goal position?

isGoal

public boolean isGoal()
Is this the goal piece?

occupies

public boolean occupies(int x,
                        int y)
Does this piece occupy the spot (x, y)?

shape

public Shape shape()
What is this piece's shape?

canSlide

public boolean canSlide(int dir,
                        Configuration config)
Can this piece slide in the specified direction, in the given configuration? We must make sure that the squares the piece would slide into are vacant. Those are the ones that are in the given direction from the squares the piece occupies, except for those such squares that the piece itself currently occupies.

shift

public void shift(int dir)
Shift the piece.

print

public void print()
Print out the piece info.

equals

public boolean equals(Piece piece)
Is this piece the same shape as and in the same location as another piece?