From 027d7dff27e51dd057c66121b9d1c6d31e087d6b Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Sat, 5 Aug 2017 19:39:25 +0100 Subject: [PATCH] Fix a small bug in Gladstein. I have tested this locally with axelrod_fortran and this strategy now agrees with the fortran version against all basic strategies. Closes #1112 --- axelrod/strategies/axelrod_second.py | 2 +- axelrod/tests/strategies/test_axelrod_second.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/axelrod/strategies/axelrod_second.py b/axelrod/strategies/axelrod_second.py index 43a34a1e4..315cd90ec 100644 --- a/axelrod/strategies/axelrod_second.py +++ b/axelrod/strategies/axelrod_second.py @@ -197,7 +197,7 @@ def strategy(self, opponent: Player) -> Action: return C # Cooperate as long as the cooperation ratio is below 0.5 cooperation_ratio = self.cooperations / len(self.history) - if cooperation_ratio >= 0.5: + if cooperation_ratio > 0.5: return D return C else: diff --git a/axelrod/tests/strategies/test_axelrod_second.py b/axelrod/tests/strategies/test_axelrod_second.py index 5e27ed340..3e065b1b9 100644 --- a/axelrod/tests/strategies/test_axelrod_second.py +++ b/axelrod/tests/strategies/test_axelrod_second.py @@ -138,8 +138,8 @@ def test_strategy(self): self.versus_test(axelrod.Alternator(), expected_actions=actions, attrs={'patsy': False}) - # Cooperation ratio will always be less than or equal to 0.5 - actions = [(D, C), (C, C), (D, C), (C, C), (D, C)] + # Cooperation ratio will always be less than 0.5 + actions = [(D, C), (C, C), (C, C), (D, C), (C, C)] self.versus_test(axelrod.Cooperator(), expected_actions=actions, attrs={'patsy': True}) @@ -150,6 +150,11 @@ def test_strategy(self): # Ratio is 1/3 when MockPlayer defected for the first time. opponent = axelrod.MockPlayer(actions=[C, C, C, D, D]) - actions = [(D, C), (C, C), (D, C), (C, D), (C, D)] + actions = [(D, C), (C, C), (C, C), (D, D), (C, D)] + self.versus_test(opponent, expected_actions=actions, + attrs={'patsy': False}) + + opponent = axelrod.AntiTitForTat() + actions = [(D, C), (C, C), (C, D), (C, D), (D, D)] self.versus_test(opponent, expected_actions=actions, attrs={'patsy': False})