I’m trying to solve a randomly generated maze in Java using recursion. What makes my situation different from others on this site is that I’m using bitwise operations to move through the maze rather than cells in a grid. When an area is clicked on the maze, my program should display a red path to the end. I cannot find out how to mark my tracks on a path in order to backtrack.
I’m using a method searchMaze(int row, int col, byte d) in order to move through the maze in my Main class:
http://pastie.org/3515632
Here are the other sources I’m using for maze generation/path handling:
http://pastie.org/3515624
http://pastie.org/3515627
How could I go about incorporating a backtracking function into my code?
For each cell, you need to somehow store the direction you came from. Then backtracking is simply a matter of following the arrows.
Alternatively, keep an incrementing count of cells visited. For each cell, store the value of the counter when it was visited. Then backtracking is simply a matter of following the downwards gradient.
Alternatively, if you’re really using recursion, then isn’t backtracking simply a matter of returning?