[Java/HW] A recusively self-solving maze with bread-crumbs: suggestions desperately needed on how to remove bread crumbs!
I have the algorithm to get the maze to solve itself, but I'm having trouble getting it to remove breadcrumbs from paths it visited that weren't the correct one.
Here's what prints when the search is done: http://i.imgur.com/L14Or.jpg
I circled in red the breadcrumbs which the TertiarySearchTree's removeNode() method failed to remove. This is the expected result right now, though, because I just don't know how to loop over removeNode() to get rid of the extra bread crumbs.
removeNode() is only used when the attempted path hits a "dead end" and can't move anymore. RemoveNode then turns the current node into an X (filtered out when the final maze renders) to mark where it's been, and the returns the next node in the stack. I know this isn't right, but other things I've tried have failed miserably. At least this one allows the maze to finish solving itself.
I just need to figure out how to run removeNode() until it's re-traced its way back to the main path (as marked by the parent node).
I've tried:
-
Making it remove nodes starting with the node that hit a wall until the current node's coordinates in the 2d array equals the parent node's coords of the next node popped out of the stack, but this ends up deleting half of the correct trail. The parent node is defined as the node that is a part of the main solution's path that's next to the stack's popped node.
-
Just removing all "renegade" paths of '+' before rendering the solution of the maze, as defined by having a ' ' on one end of the '+' path and no 'E' or 'S' on the other. This fails when the "renegade" incorrect path is attached to the start, and changing the 'S' condition just makes it delete half to he main path, too.
I've also tried tons of variations of the above to no/weird effects.
Do I need to retrace backwards through the maze once I've found the solution and redefine the correct path with a different symbol, then delete all of the non-correct path's symbols with blanks?
I'm so frustrated...
Posted Dec 2, 2012, 4:12 PM UTC