473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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?
Mar 30 '10 #1
5 4705
jkmyoung
2,057 Expert 2GB
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).
Mar 30 '10 #2
Yes, I have a stack that I push unvisited cells to, when it reaches a dead end, it breaks.
Mar 30 '10 #3
jkmyoung
2,057 Expert 2GB
How are you checking for the dead end? code sample?
Mar 30 '10 #4
I'm not. I'm not sure how to
Mar 30 '10 #5
Code sample will be posted around 8:00pm EST. I'm in class now
Mar 30 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Bernard Fields | last post by:
Greets, all. As the title suggests, I'm trying to make a maze. Specifically, it's a top-down, 2-d maze, preferably randomly generated, though I'm willing to forego that particular aspect as...
2
by: Roger Douglass | last post by:
I've been working on this program for school and I just about got it before I had to turn it in. Here's my final code on it. I didn't finish it, but I think I'm pretty close. M is the starting...
4
by: Daniel | last post by:
I need to build the maze board(like 2d array) using a tree. But I find that my buildTree function doesn't work. Could anyone give me some hints on debugging it? Thanks bool BuildTree(TreeNodePtr...
3
by: yb | last post by:
Hi, I just started reading design patterns and looking at the Lexi example. I'm very new to this so please bear with me. I understand the Decorator pattern, but a bit confused by the Maze...
1
by: daneshjo | last post by:
Hi im an IT student.I have registered as a member of this site recently.I have a question about the solution of maze program. I want to write maze program in c++ .I want to solve the maze class...
2
by: dev24 | last post by:
Hi guys, I was looking at random maze generators on the web. I found this prims algorithm but everytime I run it, it doesnt display the random maze as it should. It just displays a blank applet....
5
by: Brosert | last post by:
I am writing (or trying to) a small program to draw a maze, that can then be traversed by a user. I have set up a grid of squares that can be either present (blocking the path) or not (allowing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.