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 sources for some strategies. #1041

Merged
merged 15 commits into from
Jun 8, 2017
Merged
8 changes: 7 additions & 1 deletion axelrod/strategies/alternator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@


class Alternator(Player):
"""A player who alternates between cooperating and defecting."""
"""
A player who alternates between cooperating and defecting.

Names

- Alternator: [Bendor1993]_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely there is an earlier description ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too but I struggled to find it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll put Axelrod's book in (it's what I did for Cooperator and Alternator). 👍

"""

name = 'Alternator'
classifier = {
Expand Down
17 changes: 10 additions & 7 deletions axelrod/strategies/ann.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""Artificial Neural Network based strategy.

# Original Source: https://gist.github.com/mojones/550b32c46a8169bb3cd89d917b73111a#file-ann-strategy-test-L60
# Original Author: Martin Jones, @mojones
"""

import numpy as np

from axelrod.actions import Actions, Action
Expand Down Expand Up @@ -146,7 +140,9 @@ def split_weights(weights: List[float], num_features: int, num_hidden: int) -> T


class ANN(Player):
"""A single layer neural network based strategy, with the following
"""Artificial Neural Network based strategy.

A single layer neural network based strategy, with the following
features:
* Opponent's first move is C
* Opponent's first move is D
Expand All @@ -165,6 +161,13 @@ class ANN(Player):
* Total player cooperations
* Total player defections
* Round number

Original Source: https://gist.github.com/mojones/550b32c46a8169bb3cd89d917b73111a#file-ann-strategy-test-L60


Names

- Artificial Neural Network based strategy: Original name by Martin Jones
"""
name = 'ANN'
classifier = {
Expand Down
14 changes: 8 additions & 6 deletions axelrod/strategies/apavlov.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

class APavlov2006(Player):
"""
APavlov as defined in http://www.cs.nott.ac.uk/~pszjl/index_files/chapter4.pdf
(pages 10-11).

APavlov attempts to classify its opponent as one of five strategies:
Cooperative, ALLD, STFT, PavlovD, or Random. APavlov then responds in a
manner intended to achieve mutual cooperation or to defect against
uncooperative opponents.

Names:

- Adaptive Pavlov 2006: [Li2007]_
"""

name = "Adaptive Pavlov 2006"
Expand Down Expand Up @@ -73,13 +74,14 @@ def reset(self):

class APavlov2011(Player):
"""
APavlov as defined in http://www.graham-kendall.com/papers/lhk2011.pdf, as
closely as can be determined.

APavlov attempts to classify its opponent as one of four strategies:
Cooperative, ALLD, STFT, or Random. APavlov then responds in a manner
intended to achieve mutual cooperation or to defect against
uncooperative opponents.

Names:

- Adaptive Pavlov 2007: [Li2011]_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2011?

"""

name = "Adaptive Pavlov 2011"
Expand Down
4 changes: 4 additions & 0 deletions axelrod/strategies/appeaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Appeaser(Player):

Switch the classifier every time the opponent plays 'D'.
Start with 'C', switch between 'C' and 'D' when opponent plays 'D'.

Names:

- Appeaser: Original Name by Jochen Müller
"""

name = 'Appeaser'
Expand Down
12 changes: 11 additions & 1 deletion axelrod/strategies/averagecopier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class AverageCopier(Player):
"""
The player will cooperate with probability p if the opponent's cooperation
ratio is p. Starts with random decision.

Names:

- Average Copier: Original name by Geraint Palmer
"""

name = 'Average Copier'
Expand All @@ -31,7 +35,13 @@ def strategy(self, opponent: Player) -> Action:


class NiceAverageCopier(Player):
"""Same as Average Copier, but always starts by cooperating."""
"""
Same as Average Copier, but always starts by cooperating.

Names:

- Average Copier: Original name by Owen Campbell
"""

name = 'Nice Average Copier'
classifier = {
Expand Down
8 changes: 8 additions & 0 deletions axelrod/strategies/backstabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class BackStabber(Player):
"""
Forgives the first 3 defections but on the fourth
will defect forever. Defects on the last 2 rounds unconditionally.

Names:

- Backstabber: Original name by Thomas Campbell
"""

name = 'BackStabber'
Expand All @@ -36,6 +40,10 @@ class DoubleCrosser(Player):
If 8 <= current round <= 180,
if the opponent did not defect in the first 7 rounds,
the player will only defect after the opponent has defected twice in-a-row.

Names:

- Double Crosser: Original name by Thomas Campbell
"""

name = 'DoubleCrosser'
Expand Down
5 changes: 5 additions & 0 deletions axelrod/strategies/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class Calculator(Player):
"""
Plays like (Hard) Joss for the first 20 rounds. If periodic behavior is
detected, defect forever. Otherwise play TFT.


Names:

- Calculator: Original name by Marc Harper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not mine -- it's in PRISON and likely predates it (it's in the file of classic strategies). Maybe one of the original Axelrod tournaments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I don't think it's one of the original tournaments I'll go with PRISON.

"""

name = "Calculator"
Expand Down
15 changes: 13 additions & 2 deletions axelrod/strategies/cooperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@


class Cooperator(Player):
"""A player who only ever cooperates."""
"""A player who only ever cooperates.

Names:

- Cooperator: [Axelrod1984]_
"""

name = 'Cooperator'
classifier = {
Expand All @@ -24,7 +29,13 @@ def strategy(opponent: Player) -> Action:


class TrickyCooperator(Player):
"""A cooperator that is trying to be tricky."""
"""
A cooperator that is trying to be tricky.

Names:

- Tricky Cooperator: Original name by Karol Langner
"""

name = "Tricky Cooperator"
classifier = {
Expand Down
49 changes: 48 additions & 1 deletion axelrod/strategies/cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class AntiCycler(Player):
"""
A player that follows a sequence of plays that contains no cycles:
CDD CD CCD CCCD CCCCD ...

Names:

- Anti Cycler: Original name by Marc Harper
"""

name = 'AntiCycler'
Expand Down Expand Up @@ -53,7 +57,13 @@ def reset(self):


class Cycler(Player):
"""A player that repeats a given sequence indefinitely."""
"""
A player that repeats a given sequence indefinitely.

Names:

- Cycler: Original name by Marc Harper
"""

name = 'Cycler'
classifier = {
Expand Down Expand Up @@ -94,7 +104,13 @@ def reset(self):


class CyclerDC(Cycler):
"""
Cycles D, C

Names:

- Cycler DC: Original name by Marc Harper
"""
name = 'Cycler DC'
classifier = copy.copy(Cycler.classifier)
classifier['memory_depth'] = 1
Expand All @@ -104,7 +120,13 @@ def __init__(self) -> None:


class CyclerCCD(Cycler):
"""
Cycles C, C, D

Names:

- Cycler CCD: Original name by Marc Harper
"""
name = 'Cycler CCD'
classifier = copy.copy(Cycler.classifier)
classifier['memory_depth'] = 2
Expand All @@ -114,7 +136,13 @@ def __init__(self) -> None:


class CyclerDDC(Cycler):
"""
Cycles D, D, C

Names:

- Cycler DDC: Original name by Marc Harper
"""
name = 'Cycler DDC'
classifier = copy.copy(Cycler.classifier)
classifier['memory_depth'] = 2
Expand All @@ -124,7 +152,13 @@ def __init__(self) -> None:


class CyclerCCCD(Cycler):
"""
Cycles C, C, C, D

Names:

- Cycler CCCD: Original name by Marc Harper
"""
name = 'Cycler CCCD'
classifier = copy.copy(Cycler.classifier)
classifier['memory_depth'] = 3
Expand All @@ -134,7 +168,13 @@ def __init__(self) -> None:


class CyclerCCCCCD(Cycler):
"""
Cycles C, C, C, C, C, D

Names:

- Cycler CCCD: Original name by Marc Harper
"""
name = 'Cycler CCCCCD'
classifier = copy.copy(Cycler.classifier)
classifier['memory_depth'] = 5
Expand All @@ -144,6 +184,13 @@ def __init__(self) -> None:


class CyclerCCCDCD(Cycler):
"""
Cycles C, C, C, D, C, D

Names:

- Cycler CCCDCD: Original name by Marc Harper
"""

name = 'Cycler CCCDCD'
classifier = copy.copy(Cycler.classifier)
Expand Down
27 changes: 16 additions & 11 deletions axelrod/strategies/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@


class Darwin(Player):
""" A strategy which accumulates a record (the 'genome') of what the most
favourable response in the previous round should have been, and naively
assumes that this will remain the correct response at the same round of
future trials.
"""
A strategy which accumulates a record (the 'genome') of what the most
favourable response in the previous round should have been, and naively
assumes that this will remain the correct response at the same round of
future trials.

This 'genome' is preserved between opponents, rounds and repetitions of
the tournament. It becomes a characteristic of the type and so a single
version of this is shared by all instances for each loading of the class.

As this results in information being preserved between tournaments, this
is classified as a cheating strategy!

This 'genome' is preserved between opponents, rounds and repetitions of
the tournament. It becomes a characteristic of the type and so a single
version of this is shared by all instances for each loading of the class.
If no record yet exists, the opponent's response from the previous round
is returned.

As this results in information being preserved between tournaments, this
is classified as a cheating strategy!
Names:

If no record yet exists, the opponent's response from the previous round
is returned.
- Darwin: Original name by Paul Slavin
"""

name = "Darwin"
Expand Down
5 changes: 3 additions & 2 deletions docs/reference/bibliography.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ documentation.
.. [Au2006] Au, T.-C. and Nau, D. S. (2006) Accident or intention: That is the question (in the iterated prisoner’s dilemma). In Proc. Int. Conf. Auton. Agents and Multiagent Syst. (AAMAS), pp. 561–568. http://www.cs.umd.edu/~nau/papers/au2006accident.pdf
.. [Axelrod1980] Axelrod, R. (1980). Effective Choice in the Prisoner’s Dilemma. Journal of Conflict Resolution, 24(1), 3–25.
.. [Axelrod1980b] Axelrod, R. (1980). More Effective Choice in the Prisoner’s Dilemma. Journal of Conflict Resolution, 24(3), 379-403.
.. [Axelrod1984] The Evolution of Cooperation. Basic Books. ISBN 0-465-02121-2.
.. [Axelrod1984] The Evolution of Cooperation. Basic Books. ISBN 0-465-02121-2.
.. [Axelrod1995] Wu, J. and Axelrod, R. (1995). How to cope with noise in the Iterated prisoner’s dilemma, Journal of Conflict Resolution, 39(1), pp. 183–189. doi: 10.1177/0022002795039001008.
.. [Banks1980] Banks, J. S., & Sundaram, R. K. (1990). Repeated games, finite automata, and complexity. Games and Economic Behavior, 2(2), 97–117. http://doi.org/10.1016/0899-8256(90)90024-O
.. [Bendor1993] Bendor, Jonathan, et al. “Cooperation Under Uncertainty: What Is New, What Is True, and What Is Important.” American Sociological Review, vol. 61, no. 2, 1996, pp. 333–338., www.jstor.org/stable/2096337.
.. [Bendor1993] Bendor, Jonathan. "Uncertainty and the Evolution of Cooperation." The Journal of Conflict Resolution, 37(4), 709–734.
.. [Beaufils1997] Beaufils, B. and Delahaye, J. (1997). Our Meeting With Gradual: A Good Strategy For The Iterated Prisoner’s Dilemma. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.42.4041
.. [Berg2015] Berg, P. Van Den, & Weissing, F. J. (2015). The importance of mechanisms for the evolution of cooperation. Proceedings of the Royal Society B-Biological Sciences, 282.
.. [Frean1994] Frean, Marcus R. “The Prisoner's Dilemma without Synchrony.” Proceedings: Biological Sciences, vol. 257, no. 1348, 1994, pp. 75–79. www.jstor.org/stable/50253.
.. [Hilde2013] Hilbe, C., Nowak, M.A. and Traulsen, A. (2013). Adaptive dynamics of extortion and compliance, PLoS ONE, 8(11), p. e77886. doi: 10.1371/journal.pone.0077886.
.. [Kraines1989] Kraines, D. & Kraines, V. Theor Decis (1989) 26: 47. doi:10.1007/BF00134056
.. [LessWrong2011] Zoo of Strategies (2011) LessWrong. Available at: http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/
.. [Li2007] Li, J, How to Design a Strategy to Win an IPD Tournament, in Kendall G., Yao X. and Chong S. (eds.) The iterated prisoner’s dilemma: 20 years on. World Scientific, chapter 4, pp. 29-40, 2007.
.. [Li2009] Li, J. & Kendall, G. (2009). A Strategy with Novel Evolutionary Features for the Iterated Prisoner’s Dilemma. Evolutionary Computation 17(2): 257–274.
.. [Li2011] Li, J., Hingston, P., Member, S., & Kendall, G. (2011). Engineering Design of Strategies for Winning Iterated Prisoner ’ s Dilemma Competitions, 3(4), 348–360.
.. [Li2016] Li, J. and Kendall, G. (2016). 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
Expand Down