@@ -67,12 +67,12 @@ def strategy(self, opponent: Player) -> Action:
67
67
self .grudge_memory = 0
68
68
self .grudged = False
69
69
70
+ if not self .grudged and D in opponent .history [- 1 :]:
71
+ self .grudged = True
72
+
70
73
if self .grudged :
71
74
self .grudge_memory += 1
72
75
return D
73
- elif D in opponent .history [- 1 :]:
74
- self .grudged = True
75
- return D
76
76
return C
77
77
78
78
def reset (self ):
@@ -206,9 +206,9 @@ def strategy(self, opponent: Player) -> Action:
206
206
"""Begins by playing C, then plays Alternator for the remaining rounds
207
207
if the opponent ever plays D."""
208
208
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
212
212
213
213
214
214
class EasyGo (Player ):
@@ -240,13 +240,14 @@ def strategy(opponent: Player) -> Action:
240
240
return C
241
241
return D
242
242
243
+
243
244
class GeneralSoftGrudger (Player ):
244
245
"""
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.
250
251
251
252
Names:
252
253
@@ -268,11 +269,11 @@ def __init__(self, n: int=1, d: int=4, c: int=2) -> None:
268
269
"""
269
270
Parameters
270
271
----------
271
- n, int
272
+ n: int
272
273
The number of defections by the opponent to trigger punishment
273
- d, int
274
+ d: int
274
275
The number of defections to punish the opponent
275
- c, int
276
+ c: int
276
277
The number of cooperations in the 'penance' stage
277
278
278
279
Special Cases
0 commit comments