public class MazeSolver extends Object
Modifier and Type | Class and Description |
---|---|
static class |
MazeSolver.MazeSolvedException
Exception thrown when path is complete
|
Constructor and Description |
---|
MazeSolver() |
Modifier and Type | Method and Description |
---|---|
static boolean |
findPath(int row,
int col)
This method calls itself recursively to find a path from the leprechaun to the pot of gold.
|
(package private) static void |
loadMaze(String filename)
Reads a maze file into the 2-dimensional array declared as a class variable.
|
static void |
main(String[] args)
This is the starting point for your program.
|
public static void main(String[] args) throws FileNotFoundException
loadMaze(String)
method first,
if correctly implemented the user interface should display it correctly.
findPath(int, int)
.
findPath(int, int)
,
no other code in the main method is needed.
args
- set run configurations to either choose or change the maze you are usingFileNotFoundException
- exception thrown when program unable to recognize file namestatic void loadMaze(String filename) throws FileNotFoundException
filename
- the name of the maze file.FileNotFoundException
- exception thrown when program unable to recognize file namepublic static boolean findPath(int row, int col) throws MazeSolver.MazeSolvedException
It also notifies the user interface about the path it is searching.
Here is a list of the actions taken in findPath, based on the square it is searching:
UserInterface.sendStatus(CallbackInterface.SearchStatus, int, int)
with CallbackInterface.SearchStatus.PATH_COMPLETE
and throw the MazeSolver.MazeSolvedException
to terminate execution.
UserInterface.sendStatus(CallbackInterface.SearchStatus, int, int)
with
CallbackInterface.SearchStatus.PATH_VALID
then recursively call findPath
with the row and column of the surrounding squares, in order: UP, RIGHT, DOWN, and LEFT.
UserInterface.sendStatus(CallbackInterface.SearchStatus, int, int)
with
CallbackInterface.SearchStatus.PATH_INVALID
, and return false.
row
- the current row of the leprechauncol
- the current column of the leprechaunMazeSolver.MazeSolvedException
- exception thrown when maze is complete