-
Notifications
You must be signed in to change notification settings - Fork 863
/
agent.py
39 lines (32 loc) · 1.01 KB
/
agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from mesa import Agent
class TreeCell(Agent):
"""
A tree cell.
Attributes:
x, y: Grid coordinates
condition: Can be "Fine", "On Fire", or "Burned Out"
unique_id: (x,y) tuple.
unique_id isn't strictly necessary here, but it's good
practice to give one to each agent anyway.
"""
def __init__(self, pos, model):
"""
Create a new tree.
Args:
pos: The tree's coordinates on the grid.
model: standard model reference for agent.
"""
super().__init__(pos, model)
self.pos = pos
self.condition = "Fine"
def step(self):
"""
If the tree is on fire, spread it to fine trees nearby.
"""
if self.condition == "On Fire":
for neighbor in self.model.grid.neighbor_iter(self.pos):
if neighbor.condition == "Fine":
neighbor.condition = "On Fire"
self.condition = "Burned Out"
def get_pos(self):
return self.pos