I need help figuring out how to write a program with recursive functions in order to identify the path to a given maze. The maze is read in from a file and then when the path is found the maze is printed with the path shown.

The read in maze will look like this:

000000000000000
011111111011110
010000001000010
011111001111110
010001001000000
011111001000000
000100001111110
000100000001010
000111111101010
010000001001010
010000001001000
011100001011110
000100001010000
0S11111110111F0
000000000000000

S- starting square
F-Finishing square
0-blocked square
1-square you can go through

I understand that I have to use 2D arrays and check all the square until I get to the S square and then check for 1s but I am not sure how to continue finding the 1s to get the path of the maze. Please help!!

Thanks :)

First hint:

create an enumerated set like below

enum Direction {Left, Right, Top, Bottom};

Use these values to inform the recursive function where its being called from. This keeps the direction moving down the path and not doubling back.

oh ok! That makes sense... but I'm having trouble with the recursive code. I think I know how to do it but I'm getting some error messages. Thanks!!

I'm bumping this thread because I would like to see a solution for it..I thought it was a simple problem but then I realized that the array path had an internal loop which really complicates things.

So does anyone have any pointers on how to solve this problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.