Transcribed TextTranscribed Text

Programming Assignment #10: Fire Background Information: As you have doubtless seen, computers are commonly used to simulate real life scenarios. One such common scenario is how fire spreads. This is super common in computer gaming to make games more realistic and interesting. However, it is also has many applications in preventing and controlling real life fires. Fire simulations are used for training for fire fighters. Trainers can’t go out and create a huge fire in order to train fire fighters but they also don’t want to send them into a fire with no practical training. Simulations are a great way to solve this problem. Fire simulations are also used to predict how fires will spread so that people in danger can be evacuated. In this assignment, you will create a simulation of fire spreading. How the program works: For this program, your world consists of a grid of squares, each representing a square meter of ground. Some of these squares will contain trees (or other burnable vegetation), some nothing and some fire. We will represent trees as green, nothing as yellow and fire as red. You can assume that all the squares on the edge of the grid will always contain nothing. Think of them as a firebreak (a section of land that has been cleared to prevent the further spread of fire). As your program runs, you will animate how the fire spreads from burning areas to areas with vegetation. Your simulation should continue until all fire has gone out. Program Behavior and Development Strategy: Step 1: populate the simulation grid When your program starts it should prompt the user for a file name. It should then read in the initial state of the land from this file. This file will contain a grid of 0, 1 and 2 characters separated by whitespace. You program should create a list of lists with the inner lists as long as the rows are wide and the outer list as long as the number of rows in the file. We have provided one sample input file, one.txt. You will need to create other input files to test your code. Step 2: spreading the fire The next step is to determine how the fire spreads. If a square is empty (0), it will stay empty no matter what. If a square is on fire (2), on the next time step it will become empty (0). If a square has a tree in it (1) you will need to look at its neighbors to determine its chances of catching fire. For this simulation we will be considering the neighbor right above (north), right below (south), to the right (east) and to the left (west). We will not be considering diagonal neighbors. If any of the north, south, east or west neighbors are on fire, generate a random number between 1 and 100 and if it is below 75 (the propagation percent) make that square on fire (2), otherwise leave it as a tree (1). Note that as you are doing this you will be changing your list of lists. This means that if you were to alter your original list, you would be comparing each square to some squares that were already updated and some that weren’t. To avoid this problem, create a new list of lists to store all of your changes in. When you finish a pass through the grid replace your original list of lists with this new list of lists. The square we north are looking at south west east 2 of 2 Step 4: Visualization In order to watch the simulation you will need to create a visualization on a drawing panel. Draw a grid on a drawing panel that is 10 times the length of each inner list and 10 times the height of the outer list. Make each square 10 by 10 pixels. Color the squares differently depending on whether they are fire, empty or tree. In this document we have used green, yellow and red but you may use whatever colors you would like. Step 5: Simulating Animate the simulation by updating the fire’s progress and redrawing every 100 milliseconds. Your simulation should continue until all fire has gone out. Remember, you can make your program pause by calling panel.sleep(number) where number is the number of milliseconds you want it to pause.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

from DrawingPanel import *
import random


Method to load grid from file
def loadGrid(file):
    grid = []
    for line in open(file):
       row = line.split()
       grid.append([int(x) for x in row])
    return grid

Method to draw grid to panel
def drawGrid(grid, panel):
    for y in range(len(grid)):
       for x in range(len(grid[y])):
            if grid[y][x] == 0:
                panel.canvas.create_rectangle(10*x,10*y,10*x+10,10*y+10, fill="yellow", width=0)
            elif grid[y][x] == 1:
                panel.canvas.create_rectangle(10*x,10*y,10*x+10,10*y+10, fill="green", width=0)
            elif grid[y][x] == 2:
                panel.canvas.create_rectangle(10*x,10*y,10*x+10,10*y+10, fill="red", width=0)

Method to obtain next grid from current grid
def nextGrid(grid):
    width = len(grid[0])
    height = len(grid)
    nextGrid = [row[:] for row in grid]
    for y in range(height):
       for x in range(width):
            if grid[y][x] == 1:
                nextToFire = False...

By purchasing this solution you'll be able to access the following files:

50% discount

$70.00 $35.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats