|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectRandomMazeRunner
public class RandomMazeRunner
The RandomMazeRunner implements a naive search algorithm. At each location in the maze, we randomly pick a direction to go, until we find the donut. In all likelihood, if a path exists, the runner will find it, but it could take a very long time! Your implementations of BFS, DFS and BestFS will (hopefully!) be far more efficient.
| Nested Class Summary | |
|---|---|
private static class |
RandomMazeRunner.SolutionPathInfo
We can store some information in each cell of the maze to keep track of our solution path. |
| Field Summary | |
|---|---|
private static java.util.Random |
randSeq
A random number generator, which we use to choose the next direction at each step in our random search. |
| Constructor Summary | |
|---|---|
RandomMazeRunner()
|
|
| Method Summary | |
|---|---|
private MazeCell |
getRandomNeighbor(Maze maze,
MazeCell curCell)
A helper method that chooses a random neighboring node of the current cell. |
private static RandomMazeRunner.SolutionPathInfo |
getSolutionPathInfo(MazeCell curCell)
A helper method that returns a pointer to the SolutionPathInfo associated with a given cell. |
private void |
printSolution(Maze maze,
int cellsVisited,
java.io.PrintWriter writer)
Print the solution path and mark each cell on the path as ON_SOLUTION_PATH. |
void |
solveMaze(Maze maze,
java.io.PrintWriter writer)
Tries to find a solution to the given maze. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static java.util.Random randSeq
| Constructor Detail |
|---|
public RandomMazeRunner()
| Method Detail |
|---|
private static RandomMazeRunner.SolutionPathInfo getSolutionPathInfo(MazeCell curCell)
curCell - The cell for which to get the SolutionPathInfo
public void solveMaze(Maze maze,
java.io.PrintWriter writer)
solveMaze in interface MazeRunnermaze - the maze to solve.writer - the PrintWriter on which to output the solution.
private void printSolution(Maze maze,
int cellsVisited,
java.io.PrintWriter writer)
maze - the Maze being solved.cellsVisited - the total number of cells visited while searching.writer - the PrintWriter on which to output the solution.
private MazeCell getRandomNeighbor(Maze maze,
MazeCell curCell)
maze - The maze that we are solvingcurCell - The current cell we are on. We choose a random neighbor of
this cell in the previous maze.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||