Skip to content

Commit ec8a6c3

Browse files
gaffney2010drvinceknight
authored andcommitted
Fix bug in Kluepfel strategy
1 parent 9d5a0f9 commit ec8a6c3

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

axelrod/strategies/axelrod_second.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,11 @@ def strategy(self, opponent: Player) -> Action:
536536
self.dd_counts += 1
537537
else:
538538
if opponent.history[-1] == C:
539-
self.dc_counts += 1
540-
else:
541539
self.cc_counts += 1
540+
else:
541+
self.dc_counts += 1
542542

543-
# Check for randomness
543+
# Check for "randomness"
544544
if len(self.history) > 26:
545545
if self.cd_counts >= (self.cd_counts + self.dd_counts) / 2 - 0.75 * np.sqrt(
546546
self.cd_counts + self.dd_counts

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,12 @@ class TestKluepfel(TestPlayer):
546546
}
547547

548548
def test_strategy(self):
549-
actions = [(C, C)] * 100 # Cooperate forever
549+
actions = [(C, C)] * 27 # Cooperate at first
550+
# After this point, the strategy will always detect false, becasue the
551+
# two checks become:
552+
# 0 >= 0, and
553+
# cc_counts >= (cc_counts)/2 - 0.75*sqrt(cc_counts)
554+
actions += [(D, C)] * 100
550555
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
551556

552557
# Since never two in a row, will respond in kind with 70% if
@@ -598,16 +603,12 @@ def test_strategy(self):
598603
(D, C),
599604
(C, C),
600605
(C, D),
601-
# Success detect random opponent for remaining turns.
602-
(D, D),
603-
(D, D),
604-
(D, D),
605-
(D, C),
606-
(D, D),
607-
(D, C),
608-
(D, D),
606+
(C, D),
609607
(D, C),
610-
(D, D),
608+
(C, C),
609+
(C, C),
610+
(D, D), # At this point cc_counts=10, cd_counts=10, dc_counts=10,
611+
# and dd_counts=5. Detect random and defect hereafter.
611612
(D, C),
612613
(D, C),
613614
(D, D),
@@ -617,11 +618,7 @@ def test_strategy(self):
617618
(D, C),
618619
(D, C),
619620
(D, D),
620-
(D, C),
621-
(D, C),
622-
(D, C),
623-
(D, C),
624-
(D, D),
621+
(D, C)
625622
]
626623
self.versus_test(axelrod.Random(0.5), expected_actions=actions, seed=10)
627624

0 commit comments

Comments
 (0)