A skeleton version of the program will appear when you run update21 in a terminal window. The program handin21 will only submit files in this directory.
There are some optional components that allow you to further practice your skills in Python. These optional components will not be graded, but may be interesting for those wanting some extra challenges.
Fighting fires is a very risky job, and proper training is essential. In the United States, the National Fire Academy offers classes that are intended to enhance the ability of fire fighters to deal more effectively with forest fires. The Academy has worked with the U.S. Forest Service to develop a three-dimensional fire fighting training simulator. This simulator allows fire fighters to test out strategies under a variety of topographic settings and weather conditions, and to learn which approaches tend to be more successful. Using simulations to model real-world problems where it may be too difficult, time-consuming, costly or dangerous to perform experiments is a growing application of computer science. For this lab you will create your own two-dimensional fire simulator. The idea for this lab came from a 2007 SIGCSE Nifty Assignment suggested by Angela B. Shiflet of Wofford College.
The Terrain class models a forest as a rectangular grid of rows and columns. Each cell in the grid is in one of three possible states:
Examine the methods in the Terrain class by opening a Python shell, importing the Terrain module using from terrain import * and running help(Terrain). The sample code below shows how the methods might be used.
from terrain import * t = Terrain(10, 12) t.setEmpty(3,3) t.setBurning(1,2) t.update() t.close()The resulting Terrain is shown below. Note that cell in location (0,0) is in the lower left corner.
Be sure you understand how to use the Terrain class before going on.
The basic rules for updating the status each cell is as follows:
The image below shows the status of a fire after 10 steps:
def main(): f = FireSim(10, 12, .55) f.startFire() f.spread() print "This fire burned %0.2f%% of the Terrain in %d steps" \ % (f.percentBurned(), f.numSteps()) f.close()
A sample run of this function might print: This fire burned 69.17% of the Terrain in 18 steps.
You may have different method names with different parameters. Remember, the design is up to you as long as you implement all the requirements.
Be sure to test your class by creating some terrains with different sizes, changing the probability of burning, or starting fires in different locations.
if random() < prob: print "yes"
There are many extensions you could add to this program. You could modify how the fire spreads by adding additional rules or parameters. For example, perhaps the probability of catching on fire depends on the number of neighboring trees that are on fire. Perhaps you can add a wind direction and modify the probabilities such that trees down-wind of an active fire are more likely to burn. Perhaps you can create an initial grid with a few "fire lines" of empty cells to prevent fires from spreading. Add a feature where cells could randomly start burning even if no neighbors are burning (as happens with lightning). Allow fire to spread to cells that are more than one cell away. If you allow this feature, can you get a fire to jump a fire line? More complex models could factor in topography, soil moisture, smoldering fires, etc., and are actually used in some geographical information system (GIS) applications for predicting and modeling forest fire risk.
Once you are satisfied with your program, hand it in by typing handin21 in a terminal window.