Class Maze

java.lang.Object
  extended by Maze

public class Maze
extends java.lang.Object

Contains the maze struture, which is just an array of MazeCells. Also contains the algorithms for generating and solving the maze.


Constructor Summary
Maze(int rows, int cols)
          Creates a maze that has the given number of rows and columns.
 
Method Summary
 MazeCell getCell(int row, int col)
          Returns the cell in the maze at the given coordinates.
 int getCols()
          Accessor that returns the number of columns in the maze.
 MazeCell getEndCell()
          Accessor that returns the end cell for the maze.
 int getRows()
          Accessor that returns the number of rows in the maze.
 MazeCell getStartCell()
          Accessor that returns the start cell for the maze.
 void setEndCell(MazeCell cell)
          Accessor that sets the end cell for the maze.
 void setStartCell(MazeCell cell)
          Accessor that sets the start cell for the maze.
 void setViewer(MazeViewer viewer)
          Accessor that sets the MazeViewer variable for the maze.
 void solveBestBinaryMaze()
          Solves the maze by best first search, with a binary heap.
 void solveBestThreeMaze()
          Solves the maze by best first search, with a three heap.
 void solveBFSMaze()
          Solves the maze by breadth first search.
 void solveDFSMaze()
          Solves the maze by depth first search.
 void solveMaze(java.lang.String method)
          Solve maze driver.
 void solveRandomMaze()
          Solves the maze by randomly choosing a neighboring cell to explore.
 void visualize(MazeCell cell)
          Tells the viewer to show the maze again, with any changes to cells updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Maze

public Maze(int rows,
            int cols)
Creates a maze that has the given number of rows and columns. Sets the neighbors of each cell.

Parameters:
rows - Number of rows in the maze.
cols - Number of columns in the maze.
Method Detail

setViewer

public void setViewer(MazeViewer viewer)
Accessor that sets the MazeViewer variable for the maze. When the viewer is not set, no visualization takes place.

Parameters:
viewer - Visual display place for the maze.

setStartCell

public void setStartCell(MazeCell cell)
Accessor that sets the start cell for the maze.

Parameters:
cell - Start cell for the maze.

setEndCell

public void setEndCell(MazeCell cell)
Accessor that sets the end cell for the maze.

Parameters:
cell - End cell for the maze.

getStartCell

public MazeCell getStartCell()
Accessor that returns the start cell for the maze.

Returns:
Start cell for the maze.

getEndCell

public MazeCell getEndCell()
Accessor that returns the end cell for the maze.

Returns:
End cell for the maze.

getRows

public int getRows()
Accessor that returns the number of rows in the maze.

Returns:
The number of rows in the maze.

getCols

public int getCols()
Accessor that returns the number of columns in the maze.

Returns:
The number of columns in the maze.

getCell

public MazeCell getCell(int row,
                        int col)
Returns the cell in the maze at the given coordinates.

Parameters:
row - The row in the maze of the cell.
col - The column in the maze of the cell.
Returns:
The cell at (row, col)

visualize

public void visualize(MazeCell cell)
Tells the viewer to show the maze again, with any changes to cells updated. The current cell will be colored in the viewer. If the viewer is null, this method does nothing.

Parameters:
cell - Current cell, that the viewer will color.

solveMaze

public void solveMaze(java.lang.String method)
Solve maze driver. The input parameter is guaranteed to be one of "dfs", "bfs", "best2", "best3", or "random".

Parameters:
method - The method for solving the maze; one of "dfs" = depth first search, "bfs" = breadth first search, "best2" = best first search with a binary heap, "best3" = best first search with a 3-heap, or "random" = random walk.

solveRandomMaze

public void solveRandomMaze()
Solves the maze by randomly choosing a neighboring cell to explore. This method takes a very long time to complete.


solveDFSMaze

public void solveDFSMaze()
Solves the maze by depth first search.


solveBFSMaze

public void solveBFSMaze()
Solves the maze by breadth first search.


solveBestBinaryMaze

public void solveBestBinaryMaze()
Solves the maze by best first search, with a binary heap.


solveBestThreeMaze

public void solveBestThreeMaze()
Solves the maze by best first search, with a three heap.