Skip to content

Commit 79f3e55

Browse files
committed
Implemented Colbert, K51R from Axelrod's Second.
1 parent c16f196 commit 79f3e55

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Champion, Eatherley, Tester, Gladstein, Tranquilizer, MoreGrofman,
1212
Kluepfel, Borufsen, Cave, WmAdams, GraaskampKatzen, Weiner, Harrington,
1313
MoreTidemanAndChieruzzi, Getzler, Leyvraz, White, Black, RichardHufford,
14-
Yamachi)
14+
Yamachi, Colbert)
1515
from .backstabber import BackStabber, DoubleCrosser
1616
from .better_and_better import BetterAndBetter
1717
from .bush_mosteller import BushMosteller
@@ -118,6 +118,7 @@
118118
CautiousQLearner,
119119
Cave,
120120
Champion,
121+
Colbert,
121122
CollectiveStrategy,
122123
ContriteTitForTat,
123124
Cooperator,

axelrod/strategies/axelrod_second.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from axelrod.action import Action
1010
from axelrod.player import Player
1111
from axelrod.random_ import random_choice
12+
from axelrod.strategies.finite_state_machines import FSMPlayer
1213

1314
from axelrod.interaction_utils import compute_final_score
1415

@@ -1803,3 +1804,50 @@ def strategy(self, opponent: Player) -> Action:
18031804
self.count_them_us_them[(them_two_ago, us_last, D)]:
18041805
return self.try_return(C, opponent.defections)
18051806
return self.try_return(D, opponent.defections)
1807+
1808+
1809+
class Colbert(FSMPlayer):
1810+
"""
1811+
Strategy submitted to Axelrod's second tournament by William Colbert (K51R)
1812+
and came in eighteenth in that tournament.
1813+
1814+
In the first eight turns, this strategy Coopearates on all but the sixth
1815+
turn, in which it Defects. After that, the strategy responds to an
1816+
opponent Cooperation with a single Cooperation, and responds to a Defection
1817+
with a chain of responses: Defect, Defect, Cooperate, Cooperate. During
1818+
this chain, the strategy ignores opponent's moves.
1819+
1820+
Names:
1821+
1822+
- Colbert: [Axelrod1980b]_
1823+
"""
1824+
1825+
name = "Colbert"
1826+
classifier = {
1827+
'memory_depth': 4,
1828+
'stochastic': False,
1829+
'makes_use_of': set(),
1830+
'long_run_time': False,
1831+
'inspects_source': False,
1832+
'manipulates_source': False,
1833+
'manipulates_state': False
1834+
}
1835+
1836+
def __init__(self) -> None:
1837+
transitions = (
1838+
(0, C, 1, C), (0, D, 1, C), # First 8 turns are special
1839+
(1, C, 2, C), (1, D, 2, C),
1840+
(2, C, 3, C), (2, D, 3, C),
1841+
(3, C, 4, C), (3, D, 4, C),
1842+
(4, C, 5, D), (4, D, 5, D), # Defect on 6th turn.
1843+
(5, C, 6, C), (5, D, 6, C),
1844+
(6, C, 7, C), (6, D, 7, C),
1845+
1846+
(7, C, 7, C), (7, D, 8, D),
1847+
(8, C, 9, D), (8, D, 9, D),
1848+
(9, C, 10, C), (9, D, 10, C),
1849+
(10, C, 7, C), (10, D, 7, C)
1850+
)
1851+
1852+
super().__init__(transitions=transitions, initial_state=0,
1853+
initial_action=C)

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,3 +1161,31 @@ def test_strategy(self):
11611161
actions += [(D, D)] # Next turn, `portion_defect` = 0.5521
11621162
actions += [(D, D), (C, D), (D, C), (C, D)] # Takes a turn to fall back into the cycle.
11631163
self.versus_test(axelrod.Ripoff(), expected_actions=actions)
1164+
1165+
1166+
class TestColbert(TestPlayer):
1167+
name = 'Colbert'
1168+
player = axelrod.Colbert
1169+
expected_classifier = {
1170+
'memory_depth': 4,
1171+
'stochastic': False,
1172+
'makes_use_of': set(),
1173+
'long_run_time': False,
1174+
'inspects_source': False,
1175+
'manipulates_source': False,
1176+
'manipulates_state': False
1177+
}
1178+
1179+
def test_strategy(self):
1180+
actions = [(C, C)] * 5 + [(D, C)] + [(C, C)] * 30
1181+
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
1182+
1183+
actions = [(C, D)] * 5 + [(D, D)] + [(C, D)] * 2
1184+
actions += [(D, D), (D, D), (C, D), (C, D)] * 20
1185+
self.versus_test(axelrod.Defector(), expected_actions=actions)
1186+
1187+
opponent_actions = [C] * 8 + [C, C, D, C, C, C, C, C]
1188+
OddBall = axelrod.MockPlayer(actions=opponent_actions)
1189+
actions = [(C, C)] * 5 + [(D, C)] + [(C, C)] * 4
1190+
actions += [(C, D)] + [(D, C), (D, C), (C, C), (C, C)] + [(C, C)]
1191+
self.versus_test(OddBall, expected_actions=actions)

docs/tutorials/advanced/classification_of_strategies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ range of memory_depth values, we can use the 'min_memory_depth' and
6969
... }
7070
>>> strategies = axl.filtered_strategies(filterset)
7171
>>> len(strategies)
72-
56
72+
57
7373

7474
We can also identify strategies that make use of particular properties of the
7575
tournament. For example, here is the number of strategies that make use of the

0 commit comments

Comments
 (0)