Skip to content

Commit eeb74c4

Browse files
Spartan-71tpike3
authored andcommitted
chore: improved readability
1 parent aa9c131 commit eeb74c4

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

examples/termites/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Over time, these simple interactions lead to the formation of wood chip piles, i
1515

1616
## Installation
1717

18-
Make sure that you have installed the `latest` version of mesa i.e `3.2` onwards.
18+
Make sure that you have installed the `latest` version of mesa.
1919

2020
## Usage
2121

examples/termites/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def agent_portrayal(agent):
17-
return {"marker": ">", "color": "red" if agent.hasWoodChip else "black", "size": 10}
17+
return {"marker": ">", "color": "red" if agent.has_woodchip else "black", "size": 10}
1818

1919

2020
model_params = {

examples/termites/termites/agents.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Termite(CellAgent):
66
A Termite agent that has ability to carry woodchip.
77
88
Attributes:
9-
hasWoodChip(bool): True if the agent is carrying a wood chip.
9+
has_woodchip(bool): True if the agent is carrying a wood chip.
1010
"""
1111

1212
def __init__(self, model, cell):
@@ -17,15 +17,15 @@ def __init__(self, model, cell):
1717
"""
1818
super().__init__(model)
1919
self.cell = cell
20-
self.hasWoodChip = False
20+
self.has_woodchip = False
2121

2222
def wiggle(self):
2323
self.cell = self.model.random.choice(self.model.grid.all_cells.cells)
2424

2525
def search_for_chip(self):
2626
if self.cell.woodcell:
2727
self.cell.woodcell = False
28-
self.hasWoodChip = True
28+
self.has_woodchip = True
2929

3030
for _ in range(10):
3131
new_cell = self.cell.neighborhood.select_random_cell()
@@ -46,12 +46,12 @@ def find_new_pile(self):
4646
return True
4747

4848
def put_down_chip(self):
49-
if not self.hasWoodChip:
49+
if not self.has_woodchip:
5050
return True
5151

5252
if not self.cell.woodcell:
5353
self.cell.woodcell = True
54-
self.hasWoodChip = False
54+
self.has_woodchip = False
5555

5656
self.get_away()
5757
return True
@@ -77,7 +77,7 @@ def step(self):
7777
2. Find a new pile (a cell with a wood chip) if carrying a chip.
7878
3. Put down the chip if a suitable location is found.
7979
"""
80-
if not self.hasWoodChip:
80+
if not self.has_woodchip:
8181
while not self.search_for_chip():
8282
pass
8383

examples/termites/termites/model.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class TermiteModel(Model):
99
"""
10-
A simulation that depicts behavior of termite agents gathering wood chips into piles.
10+
A simulation that shows behavior of termite agents gathering wood chips into piles.
1111
"""
1212

1313
def __init__(
@@ -31,6 +31,8 @@ def __init__(
3131
self.wood_chips_layer = PropertyLayer(
3232
"woodcell", (width, height), default_value=False, dtype=bool
3333
)
34+
35+
# Randomly distribute wood chips, by directly modifying the layer's underlying ndarray
3436
self.wood_chips_layer.data = np.random.choice(
3537
[True, False],
3638
size=(width, height),
@@ -39,10 +41,11 @@ def __init__(
3941

4042
self.grid.add_property_layer(self.wood_chips_layer)
4143

44+
# Create agents and randomly distribute them over the grid
4245
Termite.create_agents(
43-
self,
44-
self.num_termites,
45-
self.random.sample(self.grid.all_cells.cells, k=self.num_termites),
46+
model = self,
47+
n = self.num_termites,
48+
cell = self.random.sample(self.grid.all_cells.cells, k=self.num_termites),
4649
)
4750

4851
def step(self):

0 commit comments

Comments
 (0)