Skip to content

Commit b9b006b

Browse files
rhttpike3
authored andcommitted
solara trading sugarscape: Use coord_iter
1 parent a361ab1 commit b9b006b

File tree

1 file changed

+12
-13
lines changed
  • examples/sugarscape_g1mt

1 file changed

+12
-13
lines changed

examples/sugarscape_g1mt/app.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@ def portray(g):
1515
"trader": {"x": [], "y": [], "c": "tab:red", "marker": "o", "s": 10},
1616
}
1717

18-
for i in range(g.width):
19-
for j in range(g.height):
20-
content = g._grid[i][j]
21-
for agent in content:
22-
if isinstance(agent, Trader):
23-
layers["trader"]["x"].append(i)
24-
layers["trader"]["y"].append(j)
18+
# TODO update to Mesa 2.0 API
19+
for content, i, j in g.coord_iter():
20+
for agent in content:
21+
if isinstance(agent, Trader):
22+
layers["trader"]["x"].append(i)
23+
layers["trader"]["y"].append(j)
24+
else:
25+
# Don't visualize resource with value <= 1.
26+
value = agent.amount if agent.amount > 1 else np.nan
27+
if isinstance(agent, Sugar):
28+
layers["sugar"][i][j] = value
2529
else:
26-
# Don't visualize resource with value <= 1.
27-
value = agent.amount if agent.amount > 1 else np.nan
28-
if isinstance(agent, Sugar):
29-
layers["sugar"][i][j] = value
30-
else:
31-
layers["spice"][i][j] = value
30+
layers["spice"][i][j] = value
3231
return layers
3332

3433
fig = Figure()

0 commit comments

Comments
 (0)