Skip to content

Commit 2cc3d4d

Browse files
Merge pull request #1152 from Nikoleta-v3/fix-tideman-chieruzzi
fixes implementation error in TidemanAndChieruzzi
2 parents c6923d1 + 436e821 commit 2cc3d4d

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

axelrod/strategies/axelrod_first.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def strategy(self, opponent: Player) -> Action:
673673
std_deviation = (N ** (1 / 2)) / 2
674674
lower = N / 2 - 3 * std_deviation
675675
upper = N / 2 + 3 * std_deviation
676-
if self.defections <= lower or self.defections >= upper:
676+
if opponent.defections <= lower or opponent.defections >= upper:
677677
# Opponent deserves a fresh start
678678
self.last_fresh_start = current_round
679679
self._fresh_start()

axelrod/tests/strategies/test_axelrod_first.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -473,33 +473,34 @@ def test_strategy(self):
473473
'retaliation_length': 4,
474474
'retaliation_remaining': 3})
475475

476-
# A fresh starts occurs on round 14.
477476
opponent = axelrod.Cycler('DDCDD')
478477
actions = [(C, D), (D, D), (D, C), (D, D), (D, D),
479478
(D, D), (D, D), (D, C), (D, D), (D, D),
480-
(D, D), (D, D), (D, C), (C, D), (C, D),
481-
(D, D), (D, D), (D, C), (C, D), (D, D),
479+
(D, D), (D, D), (D, C), (D, D), (D, D),
482480
(D, D), (D, D), (D, C), (D, D), (D, D)]
483-
484481
self.versus_test(opponent, expected_actions=actions,
485-
attrs={'current_score': 40, 'opponent_score': 35,
486-
'last_fresh_start': 14,
487-
'retaliation_length': 4,
488-
'retaliation_remaining': 1})
482+
attrs={'current_score': 34, 'opponent_score': 19,
483+
'last_fresh_start': 0,
484+
'retaliation_length': 6,
485+
'retaliation_remaining': 2})
489486

490487
# When the length is given this strategy will not give a fresh start
491488
opponent = axelrod.Cycler('DDCDD')
492-
actions = [(C, D), (D, D), (D, C), (D, D), (D, D),
493-
(D, D), (D, D), (D, C), (D, D), (D, D),
494-
(D, D), (D, D), (D, C), (D, D), (D, D)]
489+
actions = [(C, D), (D, D), (D, C), (D, D), (D, D), (D, D), (D, D),
490+
(D, C), (D, D), (D, D), (D, D), (D, D), (D, C), (D, D),
491+
(D, D), (D, D), (D, D), (D, C), (D, D), (D, D), (D, D),
492+
(D, D), (D, C), (D, D), (D, D), (D, D), (D, D), (D, C),
493+
(C, D), (C, D)]
495494
self.versus_test(opponent, expected_actions=actions,
496-
match_attributes={'length': 15})
495+
match_attributes={'length': 50})
497496

498497
# When the length is not given this strategy will give a fresh start.
499498
opponent = axelrod.Cycler('DDCDD')
500-
actions = [(C, D), (D, D), (D, C), (D, D), (D, D),
501-
(D, D), (D, D), (D, C), (D, D), (D, D),
502-
(D, D), (D, D), (D, C), (C, D), (C, D)]
499+
actions = [(C, D), (D, D), (D, C), (D, D), (D, D), (D, D), (D, D),
500+
(D, C), (D, D), (D, D), (D, D), (D, D), (D, C), (D, D),
501+
(D, D), (D, D), (D, D), (D, C), (D, D), (D, D), (D, D),
502+
(D, D), (D, C), (D, D), (D, D), (D, D), (D, D), (D, C),
503+
(C, D), (C, D)]
503504
self.versus_test(opponent, expected_actions=actions,
504505
match_attributes={'length': float('inf')})
505506

@@ -522,4 +523,18 @@ def test_strategy(self):
522523
self.versus_test(opponent, expected_actions=actions,
523524
attrs={'fresh_start': False})
524525

526+
# check the fresh start condition: least 20 rounds since the last ‘fresh start’
527+
opponent = axelrod.Cycler('CCCCD')
528+
actions = [(C, C), (C, C), (C, C), (C, C), (C, D), (D, C), (C, C),
529+
(C, C), (C, C), (C, D), (D, C), (D, C), (C, C), (C, C),
530+
(C, D), (D, C), (D, C), (D, C), (C, C), (C, D), (D, C),
531+
(D, C), (D, C), (C, C), (C, D), (D, C), (C, C), (C, C),
532+
(C, C), (C, D), (D, C), (D, C), (C, C), (C, C), (C, D)]
533+
self.versus_test(opponent, expected_actions=actions,
534+
match_attributes={'length': 35},
535+
attrs={'current_score': 108, 'opponent_score': 78,
536+
'last_fresh_start': 24,
537+
'retaliation_length': 2,
538+
'retaliation_remaining': 0})
539+
525540

0 commit comments

Comments
 (0)