Backtrack in maze

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • randysimes
    New Member
    • Oct 2009
    • 54

    Backtrack in maze

    I have a maze setup by rows and columns.
    0 1 2 3 4 5
    6 7 8 9 10 11...

    Given a starting point and an ending point of say start = 0 and goal = 8

    Each cell has a list of its cells that it has access to, no walls between.

    I begin solving the maze by starting at start and going to its next possible cell, the lowest numbered one. So if cell 3 has access to 4 and 9, it goes to 4. I then 'mark' this cell as being visited, with a variable = 1. With this being said, if I run into a dead end, the loop terminates and the solution given is partially correct up to the dead end.

    My question is how can I backtrack to the first cell that had access to others?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Backtracking implies that you know how you got to your current state. I'm guessing you have kept track of your current state, but haven't implemented a method for tracking how you got there.
    Do you have a string or a stack that keeps track of the path? eg if you're keeping track of your route in a stack, pop off the last room marked. Unmark that room and go back into the previous room. Pass the last room you've backtracked from back to the search algorithm, so it knows where to start from. Based on where you just backtracked from, you'll be able to determine where you go next.

    This really seems to be more of an algorithm question...
    (reminds me of hunt the wumpus).

    Comment

    • randysimes
      New Member
      • Oct 2009
      • 54

      #3
      Yes, I have a stack that I push unvisited cells to, when it reaches a dead end, it breaks.

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        How are you checking for the dead end? code sample?

        Comment

        • randysimes
          New Member
          • Oct 2009
          • 54

          #5
          I'm not. I'm not sure how to

          Comment

          • randysimes
            New Member
            • Oct 2009
            • 54

            #6
            Code sample will be posted around 8:00pm EST. I'm in class now

            Comment

            Working...