Skip to content

Commit

Permalink
Merge pull request #596 from Axelrod-Python/noise-fix
Browse files Browse the repository at this point in the history
Add back in noise parameter to tournament
  • Loading branch information
drvinceknight committed May 15, 2016
2 parents 37334d9 + 4e57e86 commit 80e0465
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions axelrod/tests/integration/test_tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,20 @@ def test_parallel_play(self):
scores = tournament.play(processes=2, progress_bar=False).scores
actual_outcome = sorted(zip(self.player_names, scores))
self.assertEqual(actual_outcome, self.expected_outcome)


class TestNoisyTournament(unittest.TestCase):
def test_noisy_tournament(self):
# Defector should win for low noise
players = [axelrod.Cooperator(), axelrod.Defector()]
tournament = axelrod.Tournament(players, turns=20, repetitions=10,
with_morality=False, noise=0.)
results = tournament.play()
self.assertEqual(results.ranked_names[0], "Defector")

# If the noise is large enough, cooperator should win
players = [axelrod.Cooperator(), axelrod.Defector()]
tournament = axelrod.Tournament(players, turns=20, repetitions=10,
with_morality=False, noise=0.75)
results = tournament.play()
self.assertEqual(results.ranked_names[0], "Cooperator")
4 changes: 2 additions & 2 deletions axelrod/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _run_serial(self, progress_bar=False):
progress_bar : bool
Whether or not to update the tournament progress bar
"""
chunks = self.match_generator.build_match_chunks()
chunks = self.match_generator.build_match_chunks(noise=self.noise)

for chunk in chunks:
results = self._play_matches(chunk)
Expand Down Expand Up @@ -167,7 +167,7 @@ def _run_parallel(self, processes=2, progress_bar=False):
done_queue = Queue()
workers = self._n_workers(processes=processes)

chunks = self.match_generator.build_match_chunks()
chunks = self.match_generator.build_match_chunks(noise=self.noise)
for chunk in chunks:
work_queue.put(chunk)

Expand Down

0 comments on commit 80e0465

Please sign in to comment.