@@ -63,16 +63,16 @@ def __init__(self) -> None:
6363 def strategy (self , opponent : Player ) -> Action :
6464 """Begins by playing C, then plays D for mem_length rounds if the
6565 opponent ever plays D."""
66- if self .grudge_memory > = self .mem_length :
66+ if self .grudge_memory = = self .mem_length :
6767 self .grudge_memory = 0
6868 self .grudged = False
6969
70+ if 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
214214class EasyGo (Player ):
@@ -240,13 +240,14 @@ def strategy(opponent: Player) -> Action:
240240 return C
241241 return D
242242
243+
243244class 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
@@ -303,6 +304,7 @@ def strategy(self, opponent: Player) -> Action:
303304 elif [D ] * self .n == opponent .history [- self .n :]:
304305 self .grudged = True
305306 return D
307+
306308 return C
307309
308310 def reset (self ):
0 commit comments