11:59.59pm, Sunday, March 1
Two good friends, Susie Queue and Hay Stack, found themselves trapped in an underground cavern. They need to find their way out of the cave, or determine if an exit is impossible so that they can radio for help.
Despite being the best of friends, Susie and Hay disagree on how they should look for the exit. Hay thinks that they should keep track of their path using a list of possible paths and always using the most recently seen ones first, while Susie thinks that they should also keep a list of possible paths but should use the ones seen earliest first.
They decide to go their own ways and plan to meet up at the exit. Having studied computer science, they know that both methods should eventually reach the exit if it is possible.
For this assignment you will be writing a program that is capable of solving a maze using two different algorithms -- one using a Stack and one using a Queue.
You will be creating a class MazeSolver that will find a path from the start to the exit of a maze using both a Stack and a Queue ADT to store the worklist (the list of paths to try).
You will also need to create a file called "README" that contains some answers to the questions listed below.
public class MyStack<T> extends LinkedList<T>
java MazeSolver filename
By extending a Collection class, the classes you create are also collections. This means that you'll have access to all of the standard methods like isEmpty() and size().
Include a main() method in MyStack and MyQueue that performs testing on your data structures. Don't forget to test the exceptions too.
I've supplied starting point code, including the mazes here: lab3.jar
Jesse Bradford created some large mazes you might want to try out once you have your program working: lab3-extra-mazes.zip
The maze files have the following format. The first line of the file contains two integers. The first indicates the number of rows (R), the second, the number of columns (C).
The rest of the file will be R rows of C integers. The value of the integers will be as follows:
0 - an empty space
1 - a wall
2 - where Susie and Hay start
3 - the exit
If you encounter a problem while reading in the file, you should print out a message and exit (System.exit() will quit your program).
In terms of coordinates, consider the upper left corner to be position [0,0] and the lower right to be [R-1,C-1]. The x-coordinate is going down, and y-coordinates go to the right.
Also in maze-2
7 13 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 2 1 0 0 1 3 0
Your program should present the following output:
_ - empty space
# - wall
S - Start
E - Exit
Also in maze-2.output
The maze to solve is:
---------------------
_ _ _ _ _ _ # _ _ _ _ _ _
# # _ # # # # # # # _ # _
_ # _ _ _ _ _ _ _ _ _ # _
_ # _ # # _ _ # # # _ # _
_ _ _ # _ _ _ _ _ # _ # _
_ # # # # # _ # _ # _ # _
_ _ _ _ _ _ S # _ _ # E _
Solving with a stack:
---------------------
Found a path of length 20:
[ 6, 6] -> [ 5, 6] -> [ 4, 6] -> [ 3, 6] -> [ 2, 6] ->
[ 2, 7] -> [ 2, 8] -> [ 2, 9] -> [ 2,10] -> [ 1,10] ->
[ 0,10] -> [ 0,11] -> [ 0,12] -> [ 1,12] -> [ 2,12] ->
[ 3,12] -> [ 4,12] -> [ 5,12] -> [ 6,12] -> [ 6,11]
The path is shown by +'s below:
_ _ _ _ _ _ # _ _ _ + + +
# # _ # # # # # # # + # +
_ # _ _ _ _ + + + + + # +
_ # _ # # _ + # # # _ # +
_ _ _ # _ _ + _ _ # _ # +
_ # # # # # + # _ # _ # +
_ _ _ _ _ _ S # _ _ # E +
Solving with a queue:
---------------------
Found a path of length 20:
[ 6, 6] -> [ 5, 6] -> [ 4, 6] -> [ 3, 6] -> [ 2, 6] ->
[ 2, 7] -> [ 2, 8] -> [ 2, 9] -> [ 2,10] -> [ 1,10] ->
[ 0,10] -> [ 0,11] -> [ 0,12] -> [ 1,12] -> [ 2,12] ->
[ 3,12] -> [ 4,12] -> [ 5,12] -> [ 6,12] -> [ 6,11]
The path is shown by +'s below:
_ _ _ _ _ _ # _ _ _ + + +
# # _ # # # # # # # + # +
_ # _ _ _ _ + + + + + # +
_ # _ # # _ + # # # _ # +
_ _ _ # _ _ + _ _ # _ # +
_ # # # # # + # _ # _ # +
_ _ _ _ _ _ S # _ _ # E +
You should implement the following algorithm for finding the path
You should first check to see that the user supplied an argument on the command line. The parameter "args" in the main method is where all command line arguments are passed.
You then should read in the maze from that file. I would suggest using a pair of Scanner objects to do so. Be sure to catch the exception that is raised if the user specifies an incorrect file and print out an appropriate error message when this occurs. Don't just let the program crash dumping the stack trace to the user.
In the jar file, I've included three classes for you to use. The MyStack and MyQueue classes are for your implementation. The Point class is a subclass of the java.awt.Point with only a change to toString() to make the outpu nicer. A point has an x and y coordinate, both of which are integers. Both are public fields, so you can access them directly.
I've included a number of sample mazes for you to try and included my output to maze-2 and maze-3
You should be using Javadoc style comments in your programs. You don't need to generate the HTML output, but you do need to be writing them.
In class we talked about the recursive backtracking strategy. If you have the time, you can try it out on the maze. (Help the third friend Rick Ursive find his way through the maze!) You can use a LinkedList of Point objects to keep track of the path through the maze.
Look through your programs and make sure you've included your name at the top of all of them.
You need to create a file called "README" that contains the following information:
If you adhered to the honor code in this assignment, add the following statement to your README file:
I have adhered to the Honor Code in this assignment.
You now just need to electronically handin all your files. Assignment is 3.
Don't forget to run lshand and verify that things were submitted.
This lab is intended to: