|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I need help with the Maze Driver that walks through a maze recursively
I need to navigate through a maze recursively giving a start and end point using row and column.
public class mazeDriver { public static void main(String[] args) { Maze maze = new Maze(4,6); maze.traverse(0,1); } } The values "4,6" (passed to the Maze constructor) represents the end point, which must correspond with the value one in the matrix. Similarly, the starting point, row/col (0,1) in this example, must also contain a one in the matrix. Note that the values "0,1" are parameters to the traverse routine, which is recursively called until a solution, in other words the exit, is found. The Maze class should configured in the following manner: public class Maze { . . . . . . public void traverse(. . .) { . . . . . . } private int[][] theMaze = { {0, 1, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 1, 0, 0}, {0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0} }; . . . . . . } ok the maze driver should look like this The following is a sample run, starting with the maze depicted above: % java mazeDriver 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 and when the solution is found it shoud look like this 0 7 0 0 0 0 0 0 7 0 1 1 0 0 0 7 7 7 0 0 0 0 0 0 7 0 0 0 0 3 3 7 7 7 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 The first matrix, containing just ones and zeros, is simply a print out of the original maze that is stored in the Maze class. The resulting matrix contains zeros, ones, threes, and sevens, representing how the program traversed the maze. The sevens, which replace ones, depict the path that the program traversed. The threes, which also replace ones, represent dead ends that the program "walked" and then turned around. The remaining ones are paths that the program did not travel on, and the zeros represent walls, that never change. Special Notes: - Although the maze depicted has the same number of rows and columns, your code should be able to handle any number of rows and columns above two, in each dimension, and work for any valid configuration, that is traversable through the maze. - The solution must be recursive in nature, i.e., use recursion. - The exit location is passed to the Maze constructor, and the start location is passed to the traverse method. - When debugging the program use simple mazes first, such as a straight path from the start to the finish. Next enhance the maze, and run your program again, until any valid maze is supported. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > I need help with the Maze Driver that walks through a maze recursively |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|