I'm trying to figure out how to make a recursive maze solver, but I'm stuck at how to tell the maze to turn around and trace back its trail once it hits a dead end. Anyone able to help me?

7 Years
Discussion Span
Last Post by justaguy101

Any code so we can see exactly what's working so far?

(I personally don't like recursive functions)


Look up pathfinding algorithms, very common in games.

So you are in square 1 and you need to get to finish square. What you want is something like this:

1. Check if the square is the finish square. If it is then return True. If not go to step 2.

2. For every neighbour square(up, down, left and right) check if there is no wall or that you haven't already visited that square. If you have already been in every neighbour square or cant move there because of a wall return False meaning that this was a dead-end.

3. Call this function to every neighour square that you can move and if one of them returns True "paint" or mark this current tile as the right path.

Sooner or later you will get a string of functions each returning True and marking some square as the right path. You need some kind of a list to hold coordinates of the squares you have already visited.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.