From b24c6b10d4229b0e4bfd9e5c6215a319acbd31ef Mon Sep 17 00:00:00 2001 From: rht Date: Wed, 24 Jan 2024 13:56:09 -0500 Subject: [PATCH] fix: Use resource agent for Sugarscape G1MT server.py --- .../sugarscape_g1mt/sugarscape_g1mt/server.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/server.py b/examples/sugarscape_g1mt/sugarscape_g1mt/server.py index fbc10ce6..3ef00668 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/server.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/server.py @@ -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"} @@ -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", @@ -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 {}