2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by WaltP
0

Keep track of each move. When you generate the next location, add a 'pointer' back to the previous location.

0

I don't really get how that would help me. I believe that I will need to modify my Cell class for that to help. Maybe add linked list?

I know that the BFS grows like a tree and it goes through the k-th level of the tree before the k+1 level. So what I have done is that I have a distance variable for each Cells.

For a 5x5 maze, the distance between the exit and the entrance is 10. When I do this, I can start from the exit and go all the way up to a Cell with distance of 0 which will be the entrance. This way seems to work okay, but it doesn't seem to be as elegant as I have hoped it to be. Once the BFS algorithm finishes, I will need to go back into the maze and check if the Cell with the distance of 9 is the Cell that will lead to the entrance. I still have walls and such. I'll show an illustration

8 _9_ <--- wall under top nine (not valid Cell)
9 10

Is there some other way that I don't need to go back into the maze for a second run?

Edited by red999: n/a

0

Yes.

Keep track of each move. When you generate the next location, add a 'pointer' back to the previous location.

If you know where you came from at each 'node', you can backtrack straight to the beginning. You have your solution.

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.