views:

142

answers:

1

I am working on a project that i must traverse a maze using the left-hand rule and based upon the intersections the program comes upon i need to create a node to connect to a graph that I will then determine the shortest path. The goal is for the program to run through the maze then close out the program and read from a file that contains the graph and determines the shortest path to the finish. what i have done is i can traverse the maze using the left-hand rule. what im thinking to do is create a node when i find the intersection and there after every time the program moves i increase the cost of that path by one. on a side note do you need to have an adjacency matrix when use dijkstra's algorithm?

+2  A: 

Try something like this, it should work:

0 - create an empty "solution path" stack of location objects.

1 - if current position is maze exit, return "solution path" stack.

2 - wall in front? turn left and repeat 2, else continue to 3.

3 - if current position is at top of "solution path" stack, 
       pop it off of the stack
       else push it onto the stack 

4 - move forward.

When you're checking the top of the stack for the current position, you might need to check the element just before the very last one, since the last one will be the position you just left.

no
wow thats actually a good idea you dont need to use a graph to actually find the shortest path.
Zieklecknerizer
Step 2's not quite right, should turn left even if you can go straight... turn left or go straight or turn right and push, or go back and pop... gotta run though, no time to update it :)
no
yeah the idea you have works unfortunately i need to find the shortest path using graphs and diijkstas algorithm... any ideas how to do that im kind of at a loss. I thought that maybe i could set up the graph by adding an edge every time the program gets to an intersection. then every time you move between there and another intersection. but that is not working... maybe im not implementing it correctly or something.(not very graph savvy haha) ill add some code to show what im doing if i make any progress!
Zieklecknerizer