<p>Moving through the maze forward is pretty easy, but I can't seem to figure out how to back up through the maze to try a new route once you hit a dead end without going back too far?</p>

[{'answer_id': 40419, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 3, 'selected': True, 'text': '<p>Use <a href="http://www.cs.bu.edu/teaching/alg/maze/" rel="nofollow noreferrer">backtracking</a> by keeping a stack of previous direction decisions.</p>\n'}, {'answer_id': 40424, 'author': 'Lasse V. Karlsen', 'author_id': 267, 'author_profile': 'https://Stackoverflow.com/users/267', 'pm_score': 2, 'selected': False, 'text': "<p>The simplest (to implement) algorithm would be to just keep a stack of locations you've been at, and the route you took from each, unless backtracking gives you that information.</p>\n\n<p>To go back, just pop off old locations from the stack and check for more exits from that location until you find an old location with an untested exit.</p>\n\n<p>By consistently testing the exits in the same order each time, if you know that backtracking to a location comes from down (ie. last time you were at the old location you went down), then you simply pick the next direction after <em>down</em>.</p>\n\n<p>I am not entirely sure what you mean by <em>going back too far</em> though, I would assume you would want to go back to the previous place you have untested routes, is that not what you want?</p>\n\n<p>Note that unless you try to keep track of the path from the starting point to your current location, and avoiding those squares when you try to find new routes, you might end up going in circle, which would eventually make the stack too large.</p>\n\n<p>A simple recursive method which marks the path it takes and never enters areas that are marked can easily do this.</p>\n\n<p>Also, if your <em>thing</em> that moves through the maze is slightly smarter than just being able to move, and hit (stop at) walls, in that it can see from its current point in all directions, I have other algorithms that might help.</p>\n"}, {'answer_id': 40450, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 1, 'selected': False, 'text': '<p>Eric Lippert did a series of articles on creating a <a href="http://blogs.msdn.com/ericlippert/archive/tags/AStar/default.aspx" rel="nofollow noreferrer">C# implemention of A*</a>, which might be more efficient.</p>\n'}]
['https://Stackoverflow.com/questions/40413', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4298/']