From b36f27429c908fb2c5895aac39d0b14c586b6f40 Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Sun, 4 Dec 2016 14:10:35 +0000 Subject: [PATCH] Reclassify Random player if p is 0 or 1 - Add a test for stochastic classification of Random Closes #781 --- axelrod/strategies/rand.py | 2 ++ axelrod/tests/unit/test_rand.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/axelrod/strategies/rand.py b/axelrod/strategies/rand.py index 0a7593039..077b5a048 100644 --- a/axelrod/strategies/rand.py +++ b/axelrod/strategies/rand.py @@ -36,6 +36,8 @@ def __init__(self, p=0.5): """ Player.__init__(self) self.p = p + if p in [0, 1]: + self.classifier['stochastic'] = False def strategy(self, opponent): return random_choice(self.p) diff --git a/axelrod/tests/unit/test_rand.py b/axelrod/tests/unit/test_rand.py index 38983bd3e..3b7829f44 100644 --- a/axelrod/tests/unit/test_rand.py +++ b/axelrod/tests/unit/test_rand.py @@ -28,3 +28,9 @@ def test_strategy(self): self.first_play_test(C, random_seed=1) self.first_play_test(D, random_seed=2) self.responses_test(response_1, response_2, [C], random_seed=1) + + def test_deterministic_classification(self): + """Test classification when p is 0 or 1""" + for p in [0, 1]: + player = axelrod.Random(p) + self.assertFalse(player.classifier['stochastic'])