Class Maze

java.lang.Object
  |
  +--Maze

public class Maze
extends java.lang.Object


Field Summary
static int CLEAR
           
static int M
          Max number of rows in the Maze
static int MINDIM
          Minimum size of either dimension
static int N
          Max number of columns in the Maze
static int VISIT
           
static int WALL
           
 
Constructor Summary
Maze()
          Create Maze of the default size (M,N) with no walls (every (i,j) element is zero).
Maze(int rows, int columns, int srow, int scol, int erow, int ecol)
          Create Maze of size (max(M,rows),max(N,columns)) with no walls (every (i,j) element is zero).
 
Method Summary
 java.util.LinkedList breadthFirstPathSearch()
          Performs a Breadth-First Search for a path in through the maze form the entrance point to the exit point.
 void clearMaze()
          Clears all walls from the maze
 void clearWall(int i, int j)
          Clears a wall from the (i,j)th position of the maze
 java.util.LinkedList depthFirstPathSearch()
          Performs a Depth-First Search for a path in through the maze form the entrance point to the exit point.
 int getEndCol()
           
 int getEndRow()
           
 int getStartCol()
           
 int getStartRow()
           
 boolean isWall(int i, int j)
           
 int numColumns()
          get the number of columns in the current maze
 int numRows()
          get the number of rows in the current maze
 void putWall(int i, int j)
          Puts a wall in the (i,j)th position of the maze Will not put a wall at the entry or exit coordinates
 void setExitPosition(int new_i, int new_j)
          Set a new exit position in the maze
 void setStartPosition(int new_i, int new_j)
          Set a new start position in the maze
 java.lang.String toString()
          Converts mxn maze to String of 0's and 1's for printing
 java.lang.String withPathToString(java.util.LinkedList path)
          Converts mxn maze to String of 0's and 1's for printing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLEAR

public static final int CLEAR

WALL

public static final int WALL

VISIT

public static final int VISIT

M

public static final int M
Max number of rows in the Maze

N

public static final int N
Max number of columns in the Maze

MINDIM

public static final int MINDIM
Minimum size of either dimension
Constructor Detail

Maze

public Maze()
Create Maze of the default size (M,N) with no walls (every (i,j) element is zero).

Maze

public Maze(int rows,
            int columns,
            int srow,
            int scol,
            int erow,
            int ecol)
Create Maze of size (max(M,rows),max(N,columns)) with no walls (every (i,j) element is zero).
Parameters:
rows - number of rows in the maze, must be MINDIM or larger
columns - number of columns in the maze, must be MINDIM or larger
srow - i position of maze start point (default is 0)
scol - j position of maze start point (default is 0)
erow - i position of maze end point (default is m-1)
ecol - j position of maze end point (default is n-1)
Method Detail

setStartPosition

public void setStartPosition(int new_i,
                             int new_j)
Set a new start position in the maze

setExitPosition

public void setExitPosition(int new_i,
                            int new_j)
Set a new exit position in the maze

getStartRow

public int getStartRow()

getStartCol

public int getStartCol()

getEndRow

public int getEndRow()

getEndCol

public int getEndCol()

numRows

public int numRows()
get the number of rows in the current maze

numColumns

public int numColumns()
get the number of columns in the current maze

putWall

public void putWall(int i,
                    int j)
             throws java.lang.ArrayIndexOutOfBoundsException
Puts a wall in the (i,j)th position of the maze Will not put a wall at the entry or exit coordinates
Parameters:
i - : row coordinate
j - : column coordinate
Throws:
java.lang.ArrayIndexOutOfBoundsException - Exeception

clearWall

public void clearWall(int i,
                      int j)
               throws java.lang.ArrayIndexOutOfBoundsException
Clears a wall from the (i,j)th position of the maze
Parameters:
i - : row coordinate
j - : column coordinate
Throws:
java.lang.ArrayIndexOutOfBoundsException - Exeception

clearMaze

public void clearMaze()
Clears all walls from the maze

isWall

public boolean isWall(int i,
                      int j)
               throws java.lang.ArrayIndexOutOfBoundsException
Parameters:
i - : row coordinate
j - : column coordinate
Throws:
java.lang.ArrayIndexOutOfBoundsException - Exeception

withPathToString

public java.lang.String withPathToString(java.util.LinkedList path)
Converts mxn maze to String of 0's and 1's for printing
Parameters:
path: - coordinates representing a path through the maze

toString

public java.lang.String toString()
Converts mxn maze to String of 0's and 1's for printing
Overrides:
toString in class java.lang.Object

breadthFirstPathSearch

public java.util.LinkedList breadthFirstPathSearch()
Performs a Breadth-First Search for a path in through the maze form the entrance point to the exit point. Uses a queue to perform a neighbor search for a path through the maze.

depthFirstPathSearch

public java.util.LinkedList depthFirstPathSearch()
Performs a Depth-First Search for a path in through the maze form the entrance point to the exit point. Uses a stack to perform a neighbor search for a path through the maze.