-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Simplify Sugarscape resource agents
This combines the Sugar and Spice resources into 1 resource class.
- Loading branch information
Showing
3 changed files
with
31 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 10 additions & 27 deletions
37
examples/sugarscape_g1mt/sugarscape_g1mt/resource_agents.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,26 @@ | ||
import mesa | ||
|
||
|
||
class Sugar(mesa.Agent): | ||
class Resource(mesa.Agent): | ||
""" | ||
Sugar: | ||
- contains an amount of sugar | ||
Resource: | ||
- contains an amount of sugar and spice | ||
- grows 1 amount of sugar at each turn | ||
""" | ||
|
||
def __init__(self, unique_id, model, pos, max_sugar): | ||
super().__init__(unique_id, model) | ||
self.pos = pos | ||
self.amount = max_sugar | ||
self.max_sugar = max_sugar | ||
|
||
def step(self): | ||
""" | ||
Sugar growth function, adds one unit of sugar each step until | ||
max amount | ||
""" | ||
self.amount = min([self.max_sugar, self.amount + 1]) | ||
|
||
|
||
class Spice(mesa.Agent): | ||
""" | ||
Spice: | ||
- contains an amount of spice | ||
- grows 1 amount of spice at each turn | ||
""" | ||
|
||
def __init__(self, unique_id, model, pos, max_spice): | ||
def __init__(self, unique_id, model, pos, max_sugar, max_spice): | ||
super().__init__(unique_id, model) | ||
self.pos = pos | ||
self.amount = max_spice | ||
self.sugar_amount = max_sugar | ||
self.max_sugar = max_sugar | ||
self.spice_amount = max_spice | ||
self.max_spice = max_spice | ||
|
||
def step(self): | ||
""" | ||
Spice growth function, adds one unit of spice each step until | ||
Growth function, adds one unit of sugar and spice each step up to | ||
max amount | ||
""" | ||
self.amount = min([self.max_spice, self.amount + 1]) | ||
self.sugar_amount = min([self.max_sugar, self.sugar_amount + 1]) | ||
self.spice_amount = min([self.max_spice, self.spice_amount + 1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters