The objective of this assignment is to write a program for finding the shortest path through a maze using the breadth-first search algorithm described in class. It's a lot of fun but do start early.
Here's a major sanity-preserving tip: Build this program incrementally. After each increment, test what you've done (perhaps by writing a simple testing program) to give you confidence that this part works. This is the SECRET TO ALL HAPPINESS! For example, you will need to implement a class defining a queue of points. Write that class and test it before moving on. Then, in MazeBFS, write just a bit of code and then test it before moving on.
Here are the parts that you'll need to get this program working:For debugging purposes, it may be very helpful to you to print out the contents of the point queue during each iteration of the breadth-first search. It may be useful to add other output statements to aid in debugging. Do remove these debugging aids once your program works and you are ready to submit it.
In the directory /cs/cs60/assignments/assignment2 you will also find three sample 10 by 10 mazes called test1.maze, test2.maze, and test3.maze. You can run your program on these mazes by typing java MazeBFS test1.maze, for example. You can also create your own mazes by creating a text file with 10 lines of characters, each of which has exactly 10 characters (no extra spaces at the end of any line!).
Please submit ALL of the java files that your program uses except for the Gridpoint and MazeElement classes which we have supplied for you. Be sure to call the MazeBFS class MazeBFS.java. Our grading scripts look for exactly this file name.
For optional extra credit (5 bonus points) after submitting MazeBFS.java, take a look at the provided loadMaze method in MazeBFS.java and generalize it and the rest of the program to handle rectangular mazes of arbitrary height and width (not just 10 by 10). You should assume that the file will contain a rectangular maze of some height and some width, but the height and width will not be specified explicitly in the file (that is, the file will not contain numbers with the height and width; your program will need to infer the height and width by itself!) Submit this class in a file called MazeBFSExtra.java.
Hint: Notice the variable inStream in the loadMaze method. This variable is of type FileInputStream and FileInputStream has a method called available() which returns an integer representing the number of symbols in the file. Play with this to see if white space and carriage returns are counted as symbols! In any case, this method is the secret to all happiness.
In general, how do you find out about the built-in "features" in Java? A great place to look is the official Java Specification web site. You can also find the link from the "Reference Guides and Software Information" link on the CS 60 homepage.
Last modified January 2004 by Ran Libeskind-Hadas