Skip to content

Commit d2ed293

Browse files
committed
grudger: changed ForgetfulGrudger. tests now use self.versus_test
1 parent b2953c8 commit d2ed293

File tree

2 files changed

+187
-128
lines changed

2 files changed

+187
-128
lines changed

axelrod/strategies/grudger.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ def strategy(self, opponent: Player) -> Action:
6767
self.grudge_memory = 0
6868
self.grudged = False
6969

70+
if not self.grudged and D in opponent.history[-1:]:
71+
self.grudged = True
72+
7073
if self.grudged:
7174
self.grudge_memory += 1
7275
return D
73-
elif D in opponent.history[-1:]:
74-
self.grudged = True
75-
return D
7676
return C
7777

7878
def reset(self):
@@ -206,9 +206,9 @@ def strategy(self, opponent: Player) -> Action:
206206
"""Begins by playing C, then plays Alternator for the remaining rounds
207207
if the opponent ever plays D."""
208208
if opponent.defections:
209-
if self.history[-1] == Actions.C:
210-
return Actions.D
211-
return Actions.C
209+
if self.history[-1] == C:
210+
return D
211+
return C
212212

213213

214214
class EasyGo(Player):
@@ -240,13 +240,14 @@ def strategy(opponent: Player) -> Action:
240240
return C
241241
return D
242242

243+
243244
class GeneralSoftGrudger(Player):
244245
"""
245-
A generalization of the SoftGrudger strategy. SoftGrudger punishes by playing:
246-
D, D, D, D, C, C. after a defection by the opponent. GeneralSoftGrudger
247-
only punishes after its opponent defects a specified amount of times consecutively.
248-
The punishment is in the form of a series of defections followed by a 'penance' of
249-
a series of consecutive cooperations.
246+
A generalization of the SoftGrudger strategy. SoftGrudger punishes by
247+
playing: D, D, D, D, C, C. after a defection by the opponent.
248+
GeneralSoftGrudger only punishes after its opponent defects a specified
249+
amount of times consecutively. The punishment is in the form of a series of
250+
defections followed by a 'penance' of a series of consecutive cooperations.
250251
251252
Names:
252253
@@ -268,11 +269,11 @@ def __init__(self, n: int=1, d: int=4, c: int=2) -> None:
268269
"""
269270
Parameters
270271
----------
271-
n, int
272+
n: int
272273
The number of defections by the opponent to trigger punishment
273-
d, int
274+
d: int
274275
The number of defections to punish the opponent
275-
c, int
276+
c: int
276277
The number of cooperations in the 'penance' stage
277278
278279
Special Cases

0 commit comments

Comments
 (0)