de.caff.maze
Class RectangularMaze

java.lang.Object
  extended by de.caff.maze.MazePropertyOwner
      extended by de.caff.maze.AbstractBasicMaze
          extended by de.caff.maze.RectangularMaze
All Implemented Interfaces:
Maze

public class RectangularMaze
extends AbstractBasicMaze

A rectangular maze with square cells. This is what I used to draw on checkered paper when I was a child. Some of my friends loved to solve them and asked for bigger ones, so one day I made a really large one by using 8 DIN A4 papers with 5mm squares, resulting in a maze with approximately 18000 cells. Nobody was able to solve it, until 25 years later my own son took the time to do it. Drawing took some hours, but solving it took it lot more. Now you can do both (creating and solving) in mere seconds with this and other programs but I'm not convinced that this is really a progress.

 

Nested Class Summary
 
Nested classes/interfaces inherited from class de.caff.maze.AbstractBasicMaze
AbstractBasicMaze.DoubleDelayedPropertyInformation, AbstractBasicMaze.IntegerDelayedPropertyInformation
 
Nested classes/interfaces inherited from class de.caff.maze.MazePropertyOwner
MazePropertyOwner.BooleanPropertyInformation, MazePropertyOwner.EnumPropertyInformation, MazePropertyOwner.InfoPropertyDisplay, MazePropertyOwner.IntegerPropertyInformation, MazePropertyOwner.PaintPropertyInformation
 
Field Summary
static java.lang.String MAZE_TYPE
          The type of this maze (for storage).
static java.lang.String PROPERTY_HORIZONTAL_CELLS
          Property key for the settable number of horizontal cells property.
static java.lang.String PROPERTY_VERTICAL_CELLS
          Property key for the settable number of vertical cells property.
 
Fields inherited from class de.caff.maze.AbstractBasicMaze
BOX_SIZE, PROPERTY_CREATION_TIME, PROPERTY_MAZE, PROPERTY_NUMBER_CELLS, PROPERTY_SEED, PROPERTY_SOLUTION_LENGTH, PROPERTY_WAY, PROPERTY_WAY_POINTS
 
Constructor Summary
RectangularMaze(int horizontalCells, int verticalCells)
          Constructor.
 
Method Summary
protected  void doDraw(MazePainter painter, MazePaintPropertiesProvider properties)
          Do the actual drawing.
 MazeCell getCellAt(java.awt.geom.Point2D position)
          Get the cell at a given point.
 MazeCell getCellByID(int id)
          Get the cell with the given id.
 MazeCell[] getCells()
          Get the cells of this maze.
protected  AbstractBasicMaze getGeometryClone()
          Get a deep copy of this maze geometry.
 java.awt.Insets getInsets(MazePaintPropertiesProvider properties, float scaling)
          Get the necessary insets depending on the paint properties.
 java.lang.String getMazeType()
          Get a internally used string describing the maze type.
protected  java.awt.Shape getOuterBorder()
          Get the borders of the maze as a shape.
 float getPreferredAspectRatio()
          Get the preferred aspect ratio of this maze.
 java.util.Collection<PropertyInformation> getPropertyInformations()
          Get the property setters and displays for this maze.
 void loadPersistentData(DataStorage systemAccess)
          Load extra data defining the maze from the system access.
static void main(java.lang.String[] args)
          Test code.
protected  void recreateFromDelayedSetters()
          This is called during the call of AbstractBasicMaze.setFromSetters() and should be used to recreate the geometry of the maze from the setters of the geometric properties.
 void reset()
          Resets the internal data.
 void setDefaultWayPoints()
          Set some useful default way points.
 void storePersistentData(DataStorage systemAccess)
          Store extra data defining the maze to the system access.
 
Methods inherited from class de.caff.maze.AbstractBasicMaze
addMazeFinishedListener, arg2int, createMaze, createMaze, createMaze, draw, drawBackgroundAndWay, getClone, getCreationTimeMillis, getInfo, getSeed, getWay, getWayEnd, getWayStart, isDuringRecreation, loadSeedWayAndVersion, recreateMaze, removeMazeFinishedListener, setFromSetters, setProgressShower, setWayEnd, setWayPoints, setWayStart, solve, storeSeedWayAndVersion
 
Methods inherited from class de.caff.maze.MazePropertyOwner
addPropertyChangeListener, firePropertyChange, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAZE_TYPE

public static final java.lang.String MAZE_TYPE
The type of this maze (for storage).

See Also:
Constant Field Values

PROPERTY_HORIZONTAL_CELLS

public static final java.lang.String PROPERTY_HORIZONTAL_CELLS
Property key for the settable number of horizontal cells property.

See Also:
Constant Field Values

PROPERTY_VERTICAL_CELLS

public static final java.lang.String PROPERTY_VERTICAL_CELLS
Property key for the settable number of vertical cells property.

See Also:
Constant Field Values
Constructor Detail

RectangularMaze

public RectangularMaze(int horizontalCells,
                       int verticalCells)
Constructor.

Parameters:
horizontalCells - number of horizontal cells
verticalCells - number of vertical cells
Method Detail

reset

public void reset()
Resets the internal data. Should be overwritten, and overwritung methods should call this.

Specified by:
reset in interface Maze
Overrides:
reset in class AbstractBasicMaze

getGeometryClone

protected AbstractBasicMaze getGeometryClone()
Get a deep copy of this maze geometry.

Specified by:
getGeometryClone in class AbstractBasicMaze
Returns:
deep copy

getMazeType

public java.lang.String getMazeType()
Get a internally used string describing the maze type.

Specified by:
getMazeType in class AbstractBasicMaze
Returns:
maze type

getCells

public MazeCell[] getCells()
Get the cells of this maze.

Returns:
the cells of this maze

getCellByID

public MazeCell getCellByID(int id)
Get the cell with the given id.

Parameters:
id - cell id
Returns:
the cell with the given id or null if there is no such cell
See Also:
MazeCell.getID()

doDraw

protected void doDraw(MazePainter painter,
                      MazePaintPropertiesProvider properties)
Do the actual drawing. The call to this method is embedded in the the calls to MazePainter.startPaintingMaze(Maze) and MazePainter.endPaintingMaze().

Specified by:
doDraw in class AbstractBasicMaze
Parameters:
painter - painter to draw to
properties - access to properties for drawing (colors etc)

getPreferredAspectRatio

public float getPreferredAspectRatio()
Get the preferred aspect ratio of this maze.

Returns:
aspect ratio (width/height)

getInsets

public java.awt.Insets getInsets(MazePaintPropertiesProvider properties,
                                 float scaling)
Get the necessary insets depending on the paint properties. Usually the insets are necessary to allow for the thick border line to be drawn completely.

Parameters:
properties - paint properties
scaling - scaling used when painting
Returns:
insets

setDefaultWayPoints

public void setDefaultWayPoints()
Set some useful default way points.

Specified by:
setDefaultWayPoints in class AbstractBasicMaze

getPropertyInformations

public java.util.Collection<PropertyInformation> getPropertyInformations()
Get the property setters and displays for this maze. Overriding classes should include this collection first.

Overrides:
getPropertyInformations in class AbstractBasicMaze
Returns:
colletion of property setters

recreateFromDelayedSetters

protected void recreateFromDelayedSetters()
This is called during the call of AbstractBasicMaze.setFromSetters() and should be used to recreate the geometry of the maze from the setters of the geometric properties.

Specified by:
recreateFromDelayedSetters in class AbstractBasicMaze

getOuterBorder

protected java.awt.Shape getOuterBorder()
Get the borders of the maze as a shape.

Specified by:
getOuterBorder in class AbstractBasicMaze
Returns:
outer border

getCellAt

public MazeCell getCellAt(java.awt.geom.Point2D position)
Get the cell at a given point. This method uses the second worst algorithm (first checking the outer border of the maze, and if necessary checking each cell shape whether it contains the point), so extending classes are encouraged to use their better understanding of the underlying geometry to calculate the target cell faster.

Specified by:
getCellAt in interface Maze
Overrides:
getCellAt in class AbstractBasicMaze
Parameters:
position - cell position
Returns:
cell at position or null if there is no cell at the given position

loadPersistentData

public void loadPersistentData(DataStorage systemAccess)
Load extra data defining the maze from the system access.

Parameters:
systemAccess - system access

storePersistentData

public void storePersistentData(DataStorage systemAccess)
Store extra data defining the maze to the system access.

Parameters:
systemAccess - system access

main

public static void main(java.lang.String[] args)
Test code.

Parameters:
args - unused