Maze
Class MazeUtil

java.lang.Object
  |
  +--Maze.MazeUtil

public class MazeUtil
extends java.lang.Object

Utility methods for working with mazes using the Maze class.


Field Summary
static int BORDERED
          Represents the value of the type parameter to generate a bordered (box) maze.
static int EMPTY
          Represents the value of the type parameter to generate an empty maze.
static int GRIDDED
          Represents the value of the type parameter to generate a grid maze.
static int RANDOM
          Represents the value of the type parameter to generate a random maze.
static double WALL_WEIGHTING
          Represents the weighting of walls to doors in randomly generated mazes.
 
Constructor Summary
MazeUtil()
          Creates a new instance of MazeUtil
 
Method Summary
static Maze.Maze generate(int width, int height, int type)
          Generates a maze of a given width, height and type.
static Maze.Maze getMaze()
          Get the solved maze
static void main(java.lang.String[] args)
          Starts the class in a special testing mode.
static boolean optimize()
          Attempts to optimize the recommended path through the maze to minimize steps and the number of options available.
static int solve(Maze.Maze myMaze)
          Attempts to recursively solve the maze from (0,0) to (width - 1, height - 1)
static boolean verify(Maze.Maze myMaze)
          Verifies the maze as safe for solving.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final int EMPTY
Represents the value of the type parameter to generate an empty maze.

See Also:
Constant Field Values

RANDOM

public static final int RANDOM
Represents the value of the type parameter to generate a random maze.

See Also:
Constant Field Values

BORDERED

public static final int BORDERED
Represents the value of the type parameter to generate a bordered (box) maze.

See Also:
Constant Field Values

GRIDDED

public static final int GRIDDED
Represents the value of the type parameter to generate a grid maze.

See Also:
Constant Field Values

WALL_WEIGHTING

public static final double WALL_WEIGHTING
Represents the weighting of walls to doors in randomly generated mazes. Should be between 0 and 1, higher values indicate more walls.

See Also:
Constant Field Values
Constructor Detail

MazeUtil

public MazeUtil()
Creates a new instance of MazeUtil

Method Detail

generate

public static Maze.Maze generate(int width,
                                 int height,
                                 int type)
Generates a maze of a given width, height and type.

Parameters:
width - the number of columns in the maze
height - the number of rows in the maze
type - the type of maze to generate. Can be any of the constants EMPTY, RANDOM, BORDERED or GRIDDED.
Returns:
the generated maze

verify

public static boolean verify(Maze.Maze myMaze)
Verifies the maze as safe for solving. It tests whether it is closed at the boundaries and walls are consistent.

Parameters:
myMaze - the maze to be verified
Returns:
true if safe, false if there are errors.

solve

public static int solve(Maze.Maze myMaze)
Attempts to recursively solve the maze from (0,0) to (width - 1, height - 1)

Parameters:
myMaze - the maze to solve
Returns:
the number of steps to solve the maze, otherwise -1.

optimize

public static boolean optimize()
Attempts to optimize the recommended path through the maze to minimize steps and the number of options available. Uses last solved maze.

Returns:
the success or failure of the optimization.

getMaze

public static Maze.Maze getMaze()
Get the solved maze

Returns:
the last maze to be used in a solve operation.

main

public static void main(java.lang.String[] args)
Starts the class in a special testing mode. This mode is non-interactive and best used with the debugger. It generates random mazes until they are solvable and then optimizes it.

Parameters:
args - command line arguments (ignored)