Skip to content

Commit

Permalink
Fix a small bug in Gladstein.
Browse files Browse the repository at this point in the history
I have tested this locally with axelrod_fortran and this strategy now
agrees with the fortran version against all basic strategies.

Closes #1112
  • Loading branch information
drvinceknight committed Aug 5, 2017
1 parent bb951aa commit 027d7df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion axelrod/strategies/axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions axelrod/tests/strategies/test_axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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})

0 comments on commit 027d7df

Please sign in to comment.