File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed
examples/sugarscape_g1mt/sugarscape_g1mt Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change 11import mesa
22
33from .model import SugarscapeG1mt
4- from .resource_agents import Spice , Sugar
4+ from .resource_agents import Resource
55from .trader_agents import Trader
66
77sugar_dic = {4 : "#005C00" , 3 : "#008300" , 2 : "#00AA00" , 1 : "#00F800" }
@@ -21,9 +21,18 @@ def Agent_portrayal(agent):
2121 "Color" : "#FF0A01" ,
2222 }
2323
24- elif isinstance (agent , Sugar ):
25- color = sugar_dic [agent .amount ] if agent .amount != 0 else "#D6F5D6"
26- layer = 1 if agent .amount > 2 else 0
24+ elif isinstance (agent , Resource ):
25+ resource_type = "sugar" if agent .max_sugar > agent .max_spice else "spice"
26+ if resource_type == "sugar" :
27+ color = (
28+ sugar_dic [agent .sugar_amount ] if agent .sugar_amount != 0 else "#D6F5D6"
29+ )
30+ layer = 1 if agent .sugar_amount > 2 else 0
31+ else :
32+ color = (
33+ spice_dic [agent .spice_amount ] if agent .spice_amount != 0 else "#D6F5D6"
34+ )
35+ layer = 1 if agent .spice_amount > 2 else 0
2736 return {
2837 "Color" : color ,
2938 "Shape" : "rect" ,
@@ -33,18 +42,6 @@ def Agent_portrayal(agent):
3342 "h" : 1 ,
3443 }
3544
36- elif isinstance (agent , Spice ):
37- color = spice_dic [agent .amount ] if agent .amount != 0 else "#D6F5D6"
38- layer = 1 if agent .amount > 2 else 0
39- return {
40- "Color" : color ,
41- "Shape" : "rect" ,
42- "Filled" : "true" ,
43- "Layer" : 0 ,
44- "w" : 1 ,
45- "h" : 1 ,
46- }
47-
4845 return {}
4946
5047
You can’t perform that action at this time.
0 commit comments