This assignment asks you to write a program that will find a path through a maze. You will need to implement two approaches: a depth-first approach using a stack and a breadth-first solution using a queue. You should save your programs in your cs35/homework/04 directory. For this assignment, you should work by yourself.
To create a new maze, your program should prompt the user for the maze dimension (number of rows and columns) and then ask the user to enter the grid locations of all internal walls as a set of (row, column) coordinates. Your maze class should be able to create a new maze from user input, print the maze to the terminal, find a path through the maze, and display the path if a solution exists. If no solution exists, your program should inform the user without crashing.
Below is a sample 6x6 maze with blue 1's indicating the location of walls and black 0's indicating open cells:
START--> 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 1 0 0 0 1 0 0 0 1 0 <--ENDA sample solution path from START to END is:
The red asterisks below show the path.
START--> * * * * * 0 1 1 1 1 * 1 1 * * * * 1 1 * 1 1 1 1 1 * 1 * * * 1 * * * 1 * <--END
This program will attempt to find a path through an m by n maze The program will first ask you for the dimensions of the maze and the location of the walls in the maze. It will then attempt to find a path in the maze and display the path if found. If no path exists, the program will inform the user. Enter number of rows: 5 Enter number of columns: 5 Enter the location of the maze walls as a list of row col pairs. Each pair should appear on a single line and be separated by a space. Type -1 on a line by itself to indicate the end of the list. The row value must be between 0 and 4 and the col value must be between 0 and 4 Enter your pairs now: 0 1 1 1 3 1 4 1 3 2 3 0 -1 Initial Maze: ---------- 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 Using a stack Path through maze: [(0,0),(1,0),(2,0),(2,1),(2,2),(2,3),(2,4),(3,4),(4,4)] Length: 9 Maze with path -------------- * 1 0 0 0 * 1 0 0 0 * * * * * 1 1 1 0 * 0 1 0 0 * Using a queue Path through maze: [(0,0),(1,0),(2,0),(2,1),(2,2),(2,3),(3,3),(4,3),(4,4)] Length: 9 Maze with path -------------- * 1 0 0 0 * 1 0 0 0 * * * * 0 1 1 1 * 0 0 1 0 * *
The search list can be implemented using either a stack or a queue. Each list will store PathPosition objects. You will need to think about what to store in the PathPosition class. You should be able to reconstruct a complete maze path given one or more PathPosition objects. Once you implement one version of the search algorithm, the other version can be implemented by modifying the first algorithm and replacing push/pops with enqueues/dequeues.