Skip to content

Commit 94e000b

Browse files
committed
Fix strategy to run for five defections
1 parent 74aac23 commit 94e000b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

axelrod/strategies/titfortat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,9 @@ def __init__(self):
696696
def strategy(self, opponent: Player) -> Action:
697697
if not self.history:
698698
return C
699-
if self.is_defector or opponent.history[-5:] == [D] * 5:
699+
if not (self.is_defector) and opponent.defections >= 5:
700700
self.is_defector = True
701+
if self.is_defector:
701702
return D
702703
return opponent.history[-1]
703704

axelrod/tests/strategies/test_titfortat.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,7 @@ def test_strategy(self):
642642
match_attributes={"length": -1})
643643

644644
# Becomes defector after 5 defections
645-
opponent = axelrod.MockPlayer(actions=[C, D, D, D, D, D, C, C])
646-
actions = [(C, C), (C, D), (D, D), (D, D),
645+
opponent = axelrod.MockPlayer(actions=[D, C, D, D, D, D, C, C])
646+
actions = [(C, D), (D, C), (C, D), (D, D),
647647
(D, D), (D, D), (D, C), (D, C)]
648-
self.versus_test(opponent, expected_actions=actions,
649-
attrs={"is_defector": True})
648+
self.versus_test(opponent, expected_actions=actions)

0 commit comments

Comments
 (0)