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

Add back in noise parameter to tournament #596

Merged
merged 2 commits into from
May 15, 2016
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
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