Lab 1660 - Forest Fire

Description

There is a beautiful high-mountain forest near where Kiffaney and I live Colorado. Here is a map of one section of the forest just to the south of the little town of Blackhawk, showing the trees in green and open spaces in tan.

Sometimes in the summer, lightning strikes in the mountains start forest fires. I know the fire needs to go from tree to tree, and I wonder if a fire anywhere along the south side of this section of trees would make it to the northern border, where the town is.

Some forest configurations are too sparse and the fire will not make it to the city, as shown in this simulation run:

Other forest configurations provide a path, and the fire-fighters would like to know where to put their resources, as shown in this simulation run:

Assignment

Generate a "forest" with a .60 probablility of having a tree in any location. Then write a program to determine if there is a fire path from the bottom edge to the top edge. Fires can only go from tree to tree horizontally or vertically. If there is a path, display it in red including all trees that would be destroyed.

You must use recursion in your solution. Basically, set each tree on the southern border on fire. Recursively call a method that sets adjacent trees on fire. When the recursion is complete display the fire map. If a tree on the northern border is reported as on fire, print a message similar to "Fire reached city of Blackhawk, Colorado" otherwise print "The city of Blackhawk, Colorado was spared."

Files

Here are some files to get you started. These give you the framework for the project and should compile and run on their own (javac *java and then java Fire) though the code for recursively letting the fire spread is left as an exercise.

Fire.java main program, controller
FireCell.java dirt, a tree, or a burning tree
FireModel.java Fire model class
FireView.java Display fire map.

Copyright © 2010 by Asylum Computer Services LLC Return to CS Labs