Tips for developing a06, BreadthFirstApplet. First, there was a slight error on the original handout, where it said that the search would be done in the Grid class. While this can be the case for a07, where the search itself will be hidden, for the present problem the search is best done in the BreadthFirstApplet class. Also AppletGrid.java will need to be modified to accomodate the new forms of drawing. It all should be doable in about 200 additional lines total. On to the tips ... ------------------------------------------------------------------------------- For debugging your code, start with initialSampleIndex set to a lower value, such as 0. This will get you to the error condition faster and you will have fewer possibilities to consider. Of course you may create still simpler examples than this 5x5 grid. Starting with small examples is a good idea, no matter what you are doing. ------------------------------------------------------------------------------- Even though your primary output is graphical, you can still use GOP (Good Ol' Print statements) for debugging. For example, if your search is going astray, you can print out the coordinates of the square you are examining and find out if they are changing, recurring, etc. ------------------------------------------------------------------------------- When using the appletviewer, the output of System.out.println will be in the usual place, the standard output. When using a browser it will be in the "Java Console". The location of the console differs from browser to browser and version to version. Some vendors are not happy unless they put it in a different place in each version, so you have to be willing to look around. Here are some known locations: Internet Explorer 5.2: Pull down the View Menu, and select Java Messages. (The last time I checked on the Mac version, this message window was cumulative and I could find no way of clearing it, so be prepared to view all the messages created by your applets since the beginning of time.) Netscape 7.0: Go to the Tools menu, select Web Development, then Java Console. Apple Safari: Let me know if you find it. ------------------------------------------------------------------------------- The Grid/Square classes are set up so that "marking" a Square is equated to "having a parent". If you use this, then the start Square of the search will need a parent. But it really doesn't have one, so make a bogus one, as Pair(-1, -1) for which you can test later. Similarly, you might want to make the spam Square found have a parent for purposes of reconstructing the path. ------------------------------------------------------------------------------- Enqueue coordinate pairs of Squares, not direct references to Squares. ------------------------------------------------------------------------------- The logic for deciding whether one of the four neighbors of a square should be enqueued is slightly complex, involving a number of tests. Rather than replicate this logic 4 times, make a method that carries it out for a generic pair of coordinates. Only if the tests are passed is the coresponding Square enqueued. So I call this method "maybeEnqueue". Then I call this method 4 times, one for each of the offset coordinate pairs. I have my method check for spam and return a boolean so indicating. But you can instead check when dequeuing. If you put it in the method, you probably should check for the start square containing spam as well. I do this by enqueuing the start square in the same method. But when we do the DESC in a07, the start square will never have spam, so it is not a big thing. ------------------------------------------------------------------------------- What do you do when you've found a path, or determined that none exists? Don't break out of step() or the run() method (in BaseApplet) that calls it. Rather, just set a boolean that tells you the path has been found. Test this method inside of step and devise your display to display one way or another depending on this flag. Because I display my path incrementally, I have a second flag indicating whether the path has been completely displayed. And I have a third display mode for when there is no path. If you want to just display the whole path at once non-incrementally, that is ok too. So your applet never really stops running (until you leave the page). If a new sample is selected, the search is reinitialized and starts all over. All the time the display is being driven by the run() method calling the start method. (If you really want to get out for some reason, you can over-ride the continue() method in BaseApplet.)