diff --git a/examples/sugarscape_cg/sugarscape_cg/agents.py b/examples/sugarscape_cg/sugarscape_cg/agents.py index 0920c54ef9e..28a99095120 100644 --- a/examples/sugarscape_cg/sugarscape_cg/agents.py +++ b/examples/sugarscape_cg/sugarscape_cg/agents.py @@ -18,8 +18,10 @@ def get_distance(pos_1, pos_2): class SsAgent(mesa.Agent): - def __init__(self, pos, model, moore=False, sugar=0, metabolism=0, vision=0): - super().__init__(pos, model) + def __init__( + self, unique_id, pos, model, moore=False, sugar=0, metabolism=0, vision=0 + ): + super().__init__(unique_id, model) self.pos = pos self.moore = moore self.sugar = sugar @@ -73,8 +75,8 @@ def step(self): class Sugar(mesa.Agent): - def __init__(self, pos, model, max_sugar): - super().__init__(pos, model) + def __init__(self, unique_id, pos, model, max_sugar): + super().__init__(unique_id, model) self.amount = max_sugar self.max_sugar = max_sugar diff --git a/examples/sugarscape_cg/sugarscape_cg/model.py b/examples/sugarscape_cg/sugarscape_cg/model.py index 8487ed8d6c5..b27566e96f2 100644 --- a/examples/sugarscape_cg/sugarscape_cg/model.py +++ b/examples/sugarscape_cg/sugarscape_cg/model.py @@ -44,9 +44,11 @@ def __init__(self, width=50, height=50, initial_population=100): import numpy as np sugar_distribution = np.genfromtxt("sugarscape_cg/sugar-map.txt") + agent_id = 0 for _, x, y in self.grid.coord_iter(): max_sugar = sugar_distribution[x, y] - sugar = Sugar((x, y), self, max_sugar) + sugar = Sugar(agent_id, (x, y), self, max_sugar) + agent_id += 1 self.grid.place_agent(sugar, (x, y)) self.schedule.add(sugar) @@ -57,7 +59,8 @@ def __init__(self, width=50, height=50, initial_population=100): sugar = self.random.randrange(6, 25) metabolism = self.random.randrange(2, 4) vision = self.random.randrange(1, 6) - ssa = SsAgent((x, y), self, False, sugar, metabolism, vision) + ssa = SsAgent(agent_id, (x, y), self, False, sugar, metabolism, vision) + agent_id += 1 self.grid.place_agent(ssa, (x, y)) self.schedule.add(ssa)