Skip to content
Open
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 axelrod/moran.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def _matchup_indices(self) -> Set[Tuple[int, int]]:
else:
# birth-death is global
sources = sorted(self.locations)
for i, source in enumerate(sources):
for source in sources:
i = self.index[source]
for target in sorted(self.interaction_graph.out_vertices(source)):
j = self.index[target]
if (self.players[i] is None) or (self.players[j] is None):
Expand Down
25 changes: 25 additions & 0 deletions axelrod/tests/unit/test_moran.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,31 @@ def test_cycle_death_birth(self):
winner2 = mp.winning_strategy_name
self.assertEqual((winner == winner2), outcome)

def test_death_birth_matchup_indices_use_player_positions(self):
"""Regression test: in death-birth mode the matchup pairs must be
player positions, not positions in the dead node's neighbour list.

On a 5-cycle, when the player on vertex 2 dies its neighbours
(vertices 1 and 3) each play their own out-neighbours, so the
matchups are (1, 0) and (3, 4).
"""
N = 5
players = [axl.Cooperator(), axl.Defector(), axl.TitForTat(),
axl.Cooperator(), axl.Defector()]
mp = MoranProcess(
players,
interaction_graph=axl.graph.cycle(N),
mode="db",
seed=1,
)
# Reproduce the state __next__ creates before score_all()
mp.dead = 2
mp.players[2] = None
self.assertEqual(mp._matchup_indices(), {(1, 0), (3, 4)})
scores = mp.score_all()
# Only the two neighbours of the dead node and their opponents play
self.assertEqual(scores, [0.0, 5.0, 0, 0.0, 5.0])


class TestApproximateMoranProcess(unittest.TestCase):
"""A suite of tests for the ApproximateMoranProcess"""
Expand Down
Loading