If I was attacking this problem I would create two functions. The first one would find the starting position and the second one would be my recursive function.
Also, will the path through the array have loops in it?
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Your original posting had a loop in the path which made solving it difficult. Try tracing
through this array and you'll find you have a loop where I indicated.
000000000000000
011111111011110
010000001000010
011111001111110//loop ends here
010001001000000//loop
011111001000000//loop starts here
000100001111110
000100000001010
000111111101010
010000001001010
010000001001000
011100001011110
000100001010000
0S11111110111F0
000000000000000
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Are you talking about a circle in the maze or in the program?
Yes, that circle makes solving your problem a very difficult task.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Wouldn't it not matter if you are only checking the next square from the one that it is at?
Because your only checking the next character for possible path directions you'll end up in an infinite loop when you encounter a path that loops back onto its self. If you think about it makes sense, you found this path once and nothing has changed so when you loop back you'll travel around again and again.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Well I have the program set so that once it goes through a box it places a X in the square so that if it runs into another X it says that it is blocked. But do you understand how to change directions that the program looks. Like it checks the up direction first but then I am not sure about how to make the program check the next direction.
I still see a problem with your approach. Consider a path that has a loop in it, as your program walks through, one element a time X'ing out elements, it may inadvertently close the path prematurely, especially if you have to navigate through that loop to get to F. I would get this problem working for the simpler 'non-loop' path first and then look at a looped path.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Well I have the program set so that once it goes through a box it places a X in the square so that if it runs into another X it says that it is blocked. But do you understand how to change directions that the program looks. Like it checks the up direction first but then I am not sure about how to make the program check the next direction.
After a full night's sleep I realized your right. If you handle the logic correctly you can navigate a path with loops using the X out method.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387