Skip to content

Commit

Permalink
Merge pull request projectmesa#981 from rht/refactor
Browse files Browse the repository at this point in the history
forest_fire: Remove unnecessary code
  • Loading branch information
Corvince authored Jan 29, 2021
2 parents d376920 + 8136712 commit 8d9d3cf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
15 changes: 5 additions & 10 deletions examples/forest_fire/Forest Fire Model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@
" height, width: The size of the grid to model\n",
" density: What fraction of grid cells have a tree in them.\n",
" '''\n",
" # Initialize model parameters\n",
" self.height = height\n",
" self.width = width\n",
" self.density = density\n",
" \n",
" # Set up model objects\n",
" self.schedule = RandomActivation(self)\n",
" self.grid = Grid(height, width, torus=False)\n",
Expand All @@ -141,7 +136,7 @@
" # Place a tree in each cell with Prob = density\n",
" for x in range(self.width):\n",
" for y in range(self.height):\n",
" if self.random.random() < self.density:\n",
" if self.random.random() < density:\n",
" # Create a tree\n",
" new_tree = TreeCell(self, (x, y))\n",
" # Set all trees in the first column on fire.\n",
Expand Down Expand Up @@ -584,9 +579,9 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [conda env:mesa]",
"display_name": "Python 3",
"language": "python",
"name": "conda-env-mesa-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -598,13 +593,13 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.8.6"
},
"widgets": {
"state": {},
"version": "1.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
3 changes: 0 additions & 3 deletions examples/forest_fire/forest_fire/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ def step(self):
if neighbor.condition == "Fine":
neighbor.condition = "On Fire"
self.condition = "Burned Out"

def get_pos(self):
return self.pos
7 changes: 1 addition & 6 deletions examples/forest_fire/forest_fire/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ def __init__(self, height=100, width=100, density=0.65):
height, width: The size of the grid to model
density: What fraction of grid cells have a tree in them.
"""
# Initialize model parameters
self.height = height
self.width = width
self.density = density

# Set up model objects
self.schedule = RandomActivation(self)
self.grid = Grid(height, width, torus=False)
Expand All @@ -38,7 +33,7 @@ def __init__(self, height=100, width=100, density=0.65):

# Place a tree in each cell with Prob = density
for (contents, x, y) in self.grid.coord_iter():
if self.random.random() < self.density:
if self.random.random() < density:
# Create a tree
new_tree = TreeCell((x, y), self)
# Set all trees in the first column on fire.
Expand Down
2 changes: 1 addition & 1 deletion examples/forest_fire/forest_fire/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def forest_fire_portrayal(tree):
if tree is None:
return
portrayal = {"Shape": "rect", "w": 1, "h": 1, "Filled": "true", "Layer": 0}
(x, y) = tree.get_pos()
(x, y) = tree.pos
portrayal["x"] = x
portrayal["y"] = y
portrayal["Color"] = COLORS[tree.condition]
Expand Down

0 comments on commit 8d9d3cf

Please sign in to comment.