0% found this document useful (0 votes)
8 views

recursion_MazeSolver

Uploaded by

deepnm23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

recursion_MazeSolver

Uploaded by

deepnm23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

A+ Computer Science MAZE

SOLVER

Lab Goal : This lab was designed to teach you more about recursion.

Lab Description : A maze is a two dimensional structure with an entrance and sometimes an exit. The job for this
program is to determine if the given maze has an exit. All of the mazes will have the entrance point at the top left corner. The exit
point can be anywhere in the far right column. A valid path will be a continuous block of 1s that connect the top left corner to any
spot on the far right column. A valid path can only be connected horizontally or vertically. Diagonal connections are not legal. The
1s in the file represent the path and 0s represent the walls of the maze. Output exit found if there is a path leading to an exit
out of the maze. Output exit not found if there is not a path leading out of the maze. Also, print out the maze.

Helpful Hints / Assumptions:


All input will be 1s and 0s. The 1s represent the path and 0s show that there is no path in that area. Open maze.dat to see
the input format.

Sample Output :
1 0 0 0 1
1 1 1 1 0
0 0 1 0 1
0 1 1 1 0 Files Needed ::
0 0 0 0 1 Maze.java
exit not found
MazeRunner.java
1 0 0 0 0 1 1 maze.dat
1 1 1 1 0 1 0
0 0 1 0 0 1 0
0 1 1 1 0 1 0
0 1 0 1 0 1 0
0 1 0 1 1 1 0 algorithm help
0 1 0 1 0 0 1
exit found if ( r and c are in bounds and current spot is a 1 )
1 0 0 0 0 1 0 mark spot as visited
1 1 1 1 0 1 0 if we are at the exit
0 0 1 0 0 1 0 mark exit found as true
0 1 1 1 0 1 0
0 1 0 1 0 1 0 else
0 1 0 1 1 1 0 4 recursive calls up down left right
0 1 0 1 0 1 0
exit not found

1 0 1 1 0 1 0
1 1 1 1 1 1 0 BONUS OPTION 1
0 0 1 0 0 0 1 Output the number of steps for the shortest path.
0 1 1 1 1 1 1 exit found – 20 STEPS
0 1 0 1 0 1 0
1 1 1 1 1 1 0
0 1 0 1 0 1 0 BONUS OPTION 2
exit found Output the shortest path distance and the path itself.
1 0 1 1 0 1 0 1 1 1
exit found – 8 STEPS
1 1 1 1 1 1 0 1 0 1 P 0 0 0 1
0 0 1 0 0 0 1 1 1 1 P P P 1 0
0 1 1 1 1 1 1 1 0 1 0 0 P 0 1
0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 0 1 1 1 0 1 P P P
0 1 0 1 0 1 0 0 0 1 0 0 0 0 0
0 1 1 1 0 1 0 0 0 0
0 1 0 1 0 1 0 1 1 1
0 1 1 1 1 1 0 1 1 1
exit found

1 0 1 1 0 1 1 1 1 0
1 1 1 1 1 1 0 1 0 1
0 0 1 0 0 0 1 1 1 0
0 1 1 1 1 1 1 1 0 1
0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 0 1 1 0
0 1 0 1 0 1 0 0 0 0
0 1 1 1 0 1 0 0 1 1
© A+ Computer Science – Recursion - www.apluscompsci.com
0 1 0 1 0 1 0 1 1 1
0 1 1 1 1 1 0 1 1 1
exit not found

1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
exit found

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
exit not found

© A+ Computer Science – Recursion - www.apluscompsci.com

You might also like