Hey all,
I've written a little maze script to solve a maze, however I'm trying to refine its result.
I have it so that it finds a path to the goal co-ordinates from a given starting position, however it outputs a path which occasionally backtracks itself in places. For example: -
south
west
west
[COLOR=Blue]west
west
north
north
south
south
east
east[/COLOR]
south
south
east
east
[COLOR=Blue]east
east
east
north
north
north
south
south
south
west
west
west[/COLOR]
south
south
In blue I have highlighted such paths, where it goes one direction, then steps back on itself. I understand that where these occurs, the opposite result is immediately after.. for example, north followed by south.
And I think this means that I can remove them in pairs, so as an example.. in the first block of blue above, I could remove the middle north/south.. which would leave west/north/south/east where I can then remove north/south and finally west/east.
That's the theory anyway!
But I'm stuck on how to implement it.. at the moment, the above list is using a stack.. however it could be anything, such as a string or array.. once I know the algorithm it should be easy to adapt to either.
Does anyone have any ideas that they can help me with please? 😃
Many thanks,
Ben