Skip to content

Commit 28f4265

Browse files
committed
Add BurnBothEnds strategy
1 parent 9975924 commit 28f4265

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
Alexei,
253253
AntiTitForTat,
254254
Bully,
255+
BurnBothEnds,
255256
ContriteTitForTat,
256257
DynamicTwoTitsForTat,
257258
EugineNier,
@@ -314,6 +315,7 @@
314315
BackStabber,
315316
BetterAndBetter,
316317
Bully,
318+
BurnBothEnds,
317319
BushMosteller,
318320
Calculator,
319321
Capri,

axelrod/strategies/titfortat.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,3 +919,35 @@ def strategy(self, opponent: Player) -> Action:
919919

920920
self.act_random = True
921921
return opponent.history[-1]
922+
923+
924+
class BurnBothEnds(Player):
925+
"""
926+
Plays like TitForTat except it cooperates after opponent cooperation with probability 9/10.
927+
928+
Names:
929+
930+
- BurnBothEnds (BBE): Marinoff [Marinoff1992]_
931+
"""
932+
933+
name = "Burn Both Ends"
934+
classifier = {
935+
"memory_depth": 1,
936+
"stochastic": True,
937+
"long_run_time": False,
938+
"inspects_source": False,
939+
"manipulates_source": False,
940+
"manipulates_state": False,
941+
}
942+
943+
def strategy(self, opponent):
944+
# First move
945+
if not opponent.history:
946+
# Make sure we cooperate first turn
947+
return C
948+
# BBE modification
949+
if opponent.history[-1] == C:
950+
# Cooperate with 0.9
951+
return self._random.random_choice(0.9)
952+
# Else TFT. Opponent played D, so play D in return.
953+
return D

axelrod/tests/strategies/test_titfortat.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,3 +1316,28 @@ def test_deterministic_classification(self):
13161316
for p in [0, 1]:
13171317
player = axl.RandomTitForTat(p=p)
13181318
self.assertFalse(axl.Classifiers["stochastic"](player))
1319+
1320+
1321+
class TestBurnBothEnds(TestPlayer):
1322+
name = "Burn Both Ends"
1323+
player = axl.BurnBothEnds
1324+
expected_classifier = {
1325+
"memory_depth": 1,
1326+
"stochastic": True,
1327+
"makes_use_of": set(),
1328+
"inspects_source": False,
1329+
"manipulates_source": False,
1330+
"manipulates_state": False,
1331+
}
1332+
1333+
def test_vs_cooperator(self):
1334+
actions = [(C, C), (C, C), (C, C), (D, C), (C, C)]
1335+
self.versus_test(axl.Cooperator(), expected_actions=actions, seed=1)
1336+
1337+
def test_vs_cooperator2(self):
1338+
actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
1339+
self.versus_test(axl.Cooperator(), expected_actions=actions, seed=2)
1340+
1341+
def test_vs_defector(self):
1342+
actions = [(C, D), (D, D), (D, D), (D, D), (D, D)]
1343+
self.versus_test(axl.Defector(), expected_actions=actions)

docs/how-to/classify_strategies.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ strategies::
5757
... }
5858
>>> strategies = axl.filtered_strategies(filterset)
5959
>>> len(strategies)
60-
87
60+
88
6161

6262
Or, to find out how many strategies only use 1 turn worth of memory to
6363
make a decision::
@@ -67,7 +67,7 @@ make a decision::
6767
... }
6868
>>> strategies = axl.filtered_strategies(filterset)
6969
>>> len(strategies)
70-
32
70+
33
7171

7272
Multiple filters can be specified within the filterset dictionary. To specify a
7373
range of memory_depth values, we can use the 'min_memory_depth' and
@@ -79,7 +79,7 @@ range of memory_depth values, we can use the 'min_memory_depth' and
7979
... }
8080
>>> strategies = axl.filtered_strategies(filterset)
8181
>>> len(strategies)
82-
56
82+
57
8383

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

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Count the number of available players::
5353

5454
>>> import axelrod as axl
5555
>>> len(axl.strategies)
56-
239
56+
240
5757

5858
Create matches between two players::
5959

docs/reference/bibliography.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ documentation.
4343
.. [Li2014] Li, J. and Kendall, G. (2014). The Effect of Memory Size on the Evolutionary Stability of Strategies in Iterated Prisoner's Dilemma. IEEE Transactions on Evolutionary Computation, 18(6) 819-826
4444
.. [LiS2014] Li, Siwei. (2014). Strategies in the Stochastic Iterated Prisoner's Dilemma. Available at: http://math.uchicago.edu/~may/REU2014/REUPapers/Li,Siwei.pdf
4545
.. [Luis2008] Luis R. Izquierdo and Segismundo S. Izquierdo (2008). Dynamics of the Bush-Mosteller Learning Algorithm in 2x2 Games, Reinforcement Learning, Cornelius Weber, Mark Elshaw and Norbert Michael Mayer (Ed.), InTech, DOI: 10.5772/5282. Available from: https://www.intechopen.com/books/reinforcement_learning/dynamics_of_the_bush-mosteller_learning_algorithm_in_2x2_games
46-
.. [Mathieu2015] Mathieu, P. and Delahaye, J. (2015). New Winning Strategies
47-
for the Iterated Prisoner's Dilemma. Proceedings of the 2015
48-
International Conference on Autonomous Agents and Multiagent Systems.
46+
.. [Marinoff1992] Marinoff, Louis. (1992). Maximizing expected utilities in the prisoner's dilemma. Journal of Conflict Resolution 36.1: 183-216.
47+
.. [Mathieu2015] Mathieu, P. and Delahaye, J. (2015). New Winning Strategies for the Iterated Prisoner's Dilemma. Proceedings of the 2015 International Conference on Autonomous Agents and Multiagent Systems.
4948
.. [Mittal2009] Mittal, S., & Deb, K. (2009). Optimal strategies of the iterated prisoner’s dilemma problem for multiple conflicting objectives. IEEE Transactions on Evolutionary Computation, 13(3), 554–565. https://doi.org/10.1109/TEVC.2008.2009459
5049
.. [Murase2020] Murase, Y., & Baek, S.K. (2020). Five Rules for Friendly Rivalry in Direct Reciprocity. Scientific Reports 10:16904 https://doi.org/10.1038/s41598-020-73855-x
5150
.. [Nachbar1992] Nachbar J., Evolution in the finitely repeated prisoner’s dilemma, Journal of Economic Behavior & Organization, 19(3): 307-326, 1992.

0 commit comments

Comments
 (0)