|
|
#################### # # # ###### ########### # ### # # ######### ######## # ### # # ######## #################### |
#################### # # #H###### ########### # ### # # ######### ######## # ### # # ######## #################### |
|
|
| It is for educational reasons. ... I want only to print all routes from starting point (saved in a tree) |
findPaths(mazeStruct &maze, path &curPath)
{
// curPath is the path so far. Data structure TBD.
// store maze.x and maze.y
for each square neighboring the current position {
if (the square is a wall) continue;
if (the square is on the current path) continue;
// if you get here then the square is unoccupied
set maze.x and maze.y to the square
set maze.map[x][y] to indicate that it's on the path.
add x,y to curPath
findPaths(maze, curPath)
// now undo stuff to get it back to current state
// remove x,y from curPath
set maze.map[x][y] to indicate that it isn't on the path
}
If (you didn't find anywhere to move in the for loop) {
// You found a dead end
print the curPath. You might do this by just printing the maze since you marked
the path above.
}
restore maze.x and maze.y to their original values
} |