Skip to content

Commit

Permalink
fix: Use resource agent for Sugarscape G1MT server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Jan 29, 2024
1 parent 479eaf3 commit 4bca8b5
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions examples/sugarscape_g1mt/sugarscape_g1mt/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mesa

from .model import SugarscapeG1mt
from .resource_agents import Spice, Sugar
from .resource_agents import Resource
from .trader_agents import Trader

sugar_dic = {4: "#005C00", 3: "#008300", 2: "#00AA00", 1: "#00F800"}
Expand All @@ -21,9 +21,18 @@ def Agent_portrayal(agent):
"Color": "#FF0A01",
}

elif isinstance(agent, Sugar):
color = sugar_dic[agent.amount] if agent.amount != 0 else "#D6F5D6"
layer = 1 if agent.amount > 2 else 0
elif isinstance(agent, Resource):
resource_type = "sugar" if agent.max_sugar > agent.max_spice else "spice"
if resource_type == "sugar":
color = (
sugar_dic[agent.sugar_amount] if agent.sugar_amount != 0 else "#D6F5D6"
)
layer = 1 if agent.sugar_amount > 2 else 0
else:
color = (
spice_dic[agent.spice_amount] if agent.spice_amount != 0 else "#D6F5D6"
)
layer = 1 if agent.spice_amount > 2 else 0
return {
"Color": color,
"Shape": "rect",
Expand All @@ -33,18 +42,6 @@ def Agent_portrayal(agent):
"h": 1,
}

elif isinstance(agent, Spice):
color = spice_dic[agent.amount] if agent.amount != 0 else "#D6F5D6"
layer = 1 if agent.amount > 2 else 0
return {
"Color": color,
"Shape": "rect",
"Filled": "true",
"Layer": 0,
"w": 1,
"h": 1,
}

return {}


Expand Down

0 comments on commit 4bca8b5

Please sign in to comment.