Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change pd_grid example to use create_agents #2545

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mesa/examples/advanced/pd_grid/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions mesa/examples/advanced/pd_grid/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ 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(
{
Expand Down
Loading