Skip to content

Commit 3f0cf2f

Browse files
committed
Dedupe mutation targets
1 parent 6b6031a commit 3f0cf2f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

axelrod/moran.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ def __init__(
122122
self._random = RandomGenerator(seed=seed)
123123
self._bulk_random = BulkRandomGenerator(self._random.random_seed_int())
124124
self.set_players()
125+
126+
# Dedupe initial players as mutation targets
127+
initial_players_by_name = {
128+
player.name: player for player in self.initial_players
129+
}
130+
self.mutation_targets = [pi for pi in initial_players_by_name.values()]
125131

126132
if interaction_graph is None:
127133
interaction_graph = complete_graph(len(players), loops=False)
@@ -211,7 +217,7 @@ def mutate(self, index: int) -> Player:
211217
# Choose another strategy at random from the initial population
212218
player = None
213219
while player is None or str(player) == str(self.players[index]):
214-
player = self._random.choice(self.initial_players)
220+
player = self._random.choice(self.mutation_targets)
215221
return player.clone()
216222

217223
def death(self, index: int = None) -> int:

0 commit comments

Comments
 (0)