Skip to content

Commit 63bcaa2

Browse files
committed
removed changes for cases that will not occur
1 parent 7841213 commit 63bcaa2

File tree

2 files changed

+7
-64
lines changed

2 files changed

+7
-64
lines changed

axelrod/strategies/grudger.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def __init__(self, n: int=1, d: int=4, c: int=2) -> None:
284284
self.n = n
285285
self.d = d
286286
self.c = c
287-
self.grudge = [D] * d + [C] * c
287+
self.grudge = [D] * (d - 1) + [C] * c
288288
self.grudged = False
289289
self.grudge_memory = 0
290290

@@ -294,17 +294,16 @@ def strategy(self, opponent: Player) -> Action:
294294
The punishment is in the form of 'd' defections followed by a penance of
295295
'c' consecutive cooperations.
296296
"""
297-
if self.grudge_memory == len(self.grudge):
298-
self.grudged = False
299-
self.grudge_memory = 0
300-
301-
if [D] * self.n == opponent.history[-self.n:] or self.n == 0:
302-
self.grudged = True
303-
304297
if self.grudged:
305298
strategy = self.grudge[self.grudge_memory]
306299
self.grudge_memory += 1
300+
if self.grudge_memory == len(self.grudge):
301+
self.grudged = False
302+
self.grudge_memory = 0
307303
return strategy
304+
elif [D] * self.n == opponent.history[-self.n:]:
305+
self.grudged = True
306+
return D
308307

309308
return C
310309

axelrod/tests/strategies/test_grudger.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -283,59 +283,3 @@ def test_strategy(self):
283283
self.versus_test(axl.MockPlayer(actions=[D, D, C, C]),
284284
expected_actions=actions,
285285
init_kwargs={"n": 1, "d": 1, "c": 1})
286-
287-
def test_edge_case_n_is_zero(self):
288-
# Always uses grudge response.
289-
init_kwargs = {'n': 0}
290-
grudge_response_d = [(D, D)] * 4 + [(C, D)] * 2
291-
grudge_response_c = [(D, C)] * 4 + [(C, C)] * 2
292-
293-
opponent = axl.Defector()
294-
actions = grudge_response_d * 5
295-
self.versus_test(opponent, expected_actions=actions,
296-
init_kwargs=init_kwargs)
297-
298-
opponent = axl.Cooperator()
299-
actions = grudge_response_c * 5
300-
self.versus_test(opponent, expected_actions=actions,
301-
init_kwargs=init_kwargs)
302-
303-
def test_edge_case_d_is_zero(self):
304-
# Grudge response is only C, so acts like Cooperator.
305-
init_kwargs = {'d': 0}
306-
307-
opponent = axl.Defector()
308-
actions = [(C, D)] * 5
309-
self.versus_test(opponent, expected_actions=actions,
310-
init_kwargs=init_kwargs)
311-
312-
opponent = axl.Alternator()
313-
actions = [(C, C), (C, D)] * 5
314-
self.versus_test(opponent, expected_actions=actions,
315-
init_kwargs=init_kwargs)
316-
317-
def test_edge_case_c_is_zero(self):
318-
# Grudge response is a set number of D's (defaults to 4)
319-
init_kwargs = {'c': 0}
320-
321-
opponent = axl.Defector()
322-
actions = [(C, D)] + [(D, D)] * 10
323-
self.versus_test(opponent, expected_actions=actions,
324-
init_kwargs=init_kwargs)
325-
326-
opponent_actions = [C] * 10 + [D]
327-
opponent = axl.MockPlayer(actions=opponent_actions)
328-
actions_start = [(C, C)] * 10 + [(C, D)]
329-
subsequent = [(D, C)] * 4 + [(C, C)] * 6 + [(C, D)]
330-
actions = actions_start + subsequent * 5
331-
self.versus_test(opponent, expected_actions=actions,
332-
init_kwargs=init_kwargs)
333-
334-
def test_repr(self):
335-
default_player = self.player()
336-
self.assertEqual(repr(default_player),
337-
"General Soft Grudger: n=1,d=4,c=2")
338-
339-
set_params_player = self.player(n=2, d=3, c=4)
340-
self.assertEqual(repr(set_params_player),
341-
"General Soft Grudger: n=2,d=3,c=4")

0 commit comments

Comments
 (0)