Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BurnBothEnds strategy #1410

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
Alexei,
AntiTitForTat,
Bully,
BurnBothEnds,
ContriteTitForTat,
DynamicTwoTitsForTat,
EugineNier,
Expand Down Expand Up @@ -314,6 +315,7 @@
BackStabber,
BetterAndBetter,
Bully,
BurnBothEnds,
BushMosteller,
Calculator,
Capri,
Expand Down
32 changes: 32 additions & 0 deletions axelrod/strategies/titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,3 +919,35 @@ def strategy(self, opponent: Player) -> Action:

self.act_random = True
return opponent.history[-1]


class BurnBothEnds(Player):
"""
Plays like TitForTat except it cooperates after opponent cooperation with probability 9/10.

Names:

- BurnBothEnds (BBE): Marinoff [Marinoff1992]_
"""

name = "Burn Both Ends"
classifier = {
"memory_depth": 1,
"stochastic": True,
"long_run_time": False,
"inspects_source": False,
"manipulates_source": False,
"manipulates_state": False,
}

def strategy(self, opponent):
# First move
if not opponent.history:
# Make sure we cooperate first turn
return C
# BBE modification
if opponent.history[-1] == C:
# Cooperate with 0.9
return self._random.random_choice(0.9)
# Else TFT. Opponent played D, so play D in return.
return D
25 changes: 25 additions & 0 deletions axelrod/tests/strategies/test_titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,3 +1316,28 @@ def test_deterministic_classification(self):
for p in [0, 1]:
player = axl.RandomTitForTat(p=p)
self.assertFalse(axl.Classifiers["stochastic"](player))


class TestBurnBothEnds(TestPlayer):
name = "Burn Both Ends"
player = axl.BurnBothEnds
expected_classifier = {
"memory_depth": 1,
"stochastic": True,
"makes_use_of": set(),
"inspects_source": False,
"manipulates_source": False,
"manipulates_state": False,
}

def test_vs_cooperator(self):
actions = [(C, C), (C, C), (C, C), (D, C), (C, C)]
self.versus_test(axl.Cooperator(), expected_actions=actions, seed=1)

def test_vs_cooperator2(self):
actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
self.versus_test(axl.Cooperator(), expected_actions=actions, seed=2)

def test_vs_defector(self):
actions = [(C, D), (D, D), (D, D), (D, D), (D, D)]
self.versus_test(axl.Defector(), expected_actions=actions)
6 changes: 3 additions & 3 deletions docs/how-to/classify_strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ strategies::
... }
>>> strategies = axl.filtered_strategies(filterset)
>>> len(strategies)
87
88

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

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

We can also identify strategies that make use of particular properties of the
tournament. For example, here is the number of strategies that make use of the
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Count the number of available players::

>>> import axelrod as axl
>>> len(axl.strategies)
239
240

Create matches between two players::

Expand Down
5 changes: 2 additions & 3 deletions docs/reference/bibliography.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ documentation.
.. [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
.. [LiS2014] Li, Siwei. (2014). Strategies in the Stochastic Iterated Prisoner's Dilemma. Available at: http://math.uchicago.edu/~may/REU2014/REUPapers/Li,Siwei.pdf
.. [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
.. [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.
.. [Marinoff1992] Marinoff, Louis. (1992). Maximizing expected utilities in the prisoner's dilemma. Journal of Conflict Resolution 36.1: 183-216.
.. [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.
.. [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
.. [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
.. [Nachbar1992] Nachbar J., Evolution in the finitely repeated prisoner’s dilemma, Journal of Economic Behavior & Organization, 19(3): 307-326, 1992.
Expand Down