Skip to content

Commit 67e61b7

Browse files
gaffney2010drvinceknight
authored andcommitted
Fix bug in Kluepfel strategy
1 parent ec8a6c3 commit 67e61b7

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

axelrod/strategies/axelrod_second.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,11 @@ def strategy(self, opponent: Player) -> Action:
540540
else:
541541
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
547-
) and self.cc_counts >= (
547+
) and self.dc_counts >= (
548548
self.dc_counts + self.cc_counts
549549
) / 2 - 0.75 * np.sqrt(
550550
self.dc_counts + self.cc_counts

axelrod/tests/strategies/test_axelrod_second.py

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

548548
def test_strategy(self):
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
549+
actions = [(C, C)] * 100 # Cooperate forever
555550
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
556551

557552
# Since never two in a row, will respond in kind with 70% if
@@ -603,22 +598,30 @@ def test_strategy(self):
603598
(D, C),
604599
(C, C),
605600
(C, D),
606-
(C, D),
601+
# Success detect random opponent for remaining turns.
602+
(D, D),
603+
(D, D),
604+
(D, D),
607605
(D, C),
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.
606+
(D, D),
612607
(D, C),
608+
(D, D),
613609
(D, C),
614610
(D, D),
611+
(D, C),
612+
(D, C),
613+
(D, D),
614+
(D, D),
615+
(D, C),
616+
(D, C),
617+
(D, C),
618+
(D, C),
615619
(D, D),
616620
(D, C),
617621
(D, C),
618622
(D, C),
619623
(D, C),
620624
(D, D),
621-
(D, C)
622625
]
623626
self.versus_test(axelrod.Random(0.5), expected_actions=actions, seed=10)
624627

0 commit comments

Comments
 (0)