# Missing the Forest for the Trees

You’re (still) a data scientist.

For Modeling & Simulation (CPSC 420), I had to model the spread of a forest fire from a lightning strike. Here are the real specs:

- It will feature a 2-dimensional cellular automaton of dimensions 50×50.
- When the simulation begins, the far right edge of the grid will be populated with houses. Each far-right-edge-square should have a 40% chance of containing a house, and a 60% chance of being empty.
- When the simulation begins, the remainder of the grid (
*i.e.*, all squares except those at the far right) will be filled with trees at a rate of`FOREST_DENSITY`. This parameter will be a number between 0 and 1, giving the (independent) probability of each square on the grid (not including the far-right edge) containing a tree. Start with a .7 value for this parameter. Other squares will be empty. - Assume that the forest boundaries are a barren wilderness;
*i.e.*all “squares” beyond the edges are empty squares. - At each time step of the simulation, there will be a
`PROB_LIGHTNING`probability of a lightning strike somewhere*in the left-half of the grid*. Initially set your`PROB_LIGHTNING`to .1. When lightning strikes, choose a random square on the**left half**of the grid. If it is an empty square, the lightning does nothing (except make a bright flash and loud boom). If the square contains a tree, the tree will catch on fire. - At each time step of the simulation, if any tree has a burning tree within its Von Neumann neighborhood (of distance 1), it will stay unburnt with probability
`PROB_TREE_IMMUNE`(initially set to .25). Otherwise, it will catch fire from the neighboring tree. (Note that this “immunity” is a*per-generation*immunity; trees which have burning neighbors and which prove to be immune for one generation are not necessarily also immune the next generation if their neighbors are still burning then.) - At each time step of the simulation, if any house has a burning tree (or house) within its Von Neumann neighborhood (of distance 1), it will stay unburnt with probability
`PROB_HOUSE_IMMUNE`(initially set to .5). Otherwise, it will catch fire from the neighboring square. (Ditto comments about the duration of “immunity,” above.) - Trees and houses both burn for
`TIME_TO_BURN`time steps, after which they are consumed and become empty squares. - The simulation should run for 200 iterations and then stop.
- When it runs, your program should show an animation of the forest over time. Use the color
`green`, and the marker “`^`” for trees. Use the color`orange`and the marker “`D`” for burning squares. Use the color`brown`and the marker “`p`” for (non-burning) houses.The key measure of your simulation (dependent variable) will be**the fraction of houses that burn down**.

Building this thing was a blast. I had the opportunity to start from scratch, so I started from the ground up with an object-oriented approach; each cell in the grid is considered as its own object.

If I had the opportunity to do it again, I think I’d decide against the object-oriented approach. I have no problems with using it, I’d just be interested to see how I could code the same simulations using a functional schema as opposed to an object-oriented one.