Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use resource agent for Sugarscape G1MT server.py #94

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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