diff --git a/mesa/examples/advanced/pd_grid/agents.py b/mesa/examples/advanced/pd_grid/agents.py index 4890b74905b..eb559361562 100644 --- a/mesa/examples/advanced/pd_grid/agents.py +++ b/mesa/examples/advanced/pd_grid/agents.py @@ -4,7 +4,7 @@ class PDAgent(CellAgent): """Agent member of the iterated, spatial prisoner's dilemma model.""" - def __init__(self, model, starting_move=None): + def __init__(self, model, starting_move=None, cell=None): """ Create a new Prisoner's Dilemma agent. @@ -15,6 +15,7 @@ def __init__(self, model, starting_move=None): """ super().__init__(model) self.score = 0 + self.cell = cell if starting_move: self.move = starting_move else: diff --git a/mesa/examples/advanced/pd_grid/model.py b/mesa/examples/advanced/pd_grid/model.py index 938ea54c107..864b1299cbd 100644 --- a/mesa/examples/advanced/pd_grid/model.py +++ b/mesa/examples/advanced/pd_grid/model.py @@ -32,11 +32,7 @@ def __init__( if payoffs is not None: self.payoff = payoffs - # Create agents - for x in range(width): - for y in range(height): - agent = PDAgent(self) - agent.cell = self.grid[(x, y)] + PDAgent.create_agents(self, len(self.grid.all_cells.cells), cell=self.grid.all_cells.cells) self.datacollector = mesa.DataCollector( {