Homework 5: Solving Mazes

You will build on your solution to Homework 3 for this assignment.

Path solving

For this part of the program, you will not need to deal explicitly with the GUI. Create a class called MazeSolver. Its constructor should take a Maze object and a stack, a queue, or a heap as parameters. The second parameter is where the open list will be stored. You will need to create an interface to represent open lists, and this second parameter should have this interface as its type. Once you have created this interface, you will create three classes that implement this interface: a stack, a queue, and a heap.

The MazeSolver should have a method entitled nextStep() that performs one step of a search algorithm. The MazeSolver will require the following:

The constructor should add to the open list a Path consisting of the entrance square only. The nextStep() method should do the following: Write a main() method for the MazeSolver class. It should take two command-line arguments: a file containing a Maze, and the designation of the open list data structure. Once the Maze and OpenList are created, create a MazeSolver. Then write a loop that calls nextStep() repeatedly until the search is finished. Once the loop finishes, print out whether the search succeeded or failed. Then print out the Path that was most recently removed from the open list. Also report the number of nodes retrieved from the open list, the number of nodes created during the search, and the total length of the displayed path.

Using a Heap

Unlike a stack or queue, the ordering of the Path nodes in the heap requires additional effort to specify. Design your heap so that the top element is the minimum (a "min-heap"). Each element's value is the sum of the path length and the Manhattan Distance from the end of the Path to the maze exit. The Manhattan Distance is the sum of the differences of the x and y coordinates of two locations. Since this distance precludes the possibility of diagonal movement, it is named as an analogy for navigating a downtown area.

Path display

Add a feature to your user interface that allows the user to do the following: You should also add an area of the interface that displays the number of nodes created, the number of nodes retrieved, and the number of steps in the displayed path.

Analysis

Run the search algorithm, with each of a stack, a queue, and a heap, with at least five different randomized mazes.

Write a text document in which you answer the following questions:

Your document should include either screen shots or textual representations of each maze.