Skip to content

Commit

Permalink
Merge pull request #1041 from Axelrod-Python/225
Browse files Browse the repository at this point in the history
Add sources for some strategies.
  • Loading branch information
meatballs committed Jun 8, 2017
2 parents fc8f01c + a2a98f4 commit 99d0e2e
Show file tree
Hide file tree
Showing 40 changed files with 641 additions and 147 deletions.
9 changes: 8 additions & 1 deletion axelrod/strategies/alternator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@


class Alternator(Player):
"""A player who alternates between cooperating and defecting."""
"""
A player who alternates between cooperating and defecting.
Names
- Alternator: [Axelrod1984]_
- Periodic player CD: [Mittal2009]_
"""

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 2011: [Li2011]_
"""

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
6 changes: 3 additions & 3 deletions axelrod/strategies/axelrod_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ class Joss(MemoryOnePlayer):
Names:
- Joss [Axelrod1980]_
- Hard Joss [Stewart2012]_
- Joss: [Axelrod1980]_
- Hard Joss: [Stewart2012]_
"""

name = "Joss"
Expand Down Expand Up @@ -504,7 +504,7 @@ class SteinAndRapoport(Player):
Names:
- SteinAndRapoport [Axelrod1980]_
- SteinAndRapoport: [Axelrod1980]_
"""

name = 'Stein and Rapoport'
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: [Prison1998]_
"""

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


class Cooperator(Player):
"""A player who only ever cooperates."""
"""A player who only ever cooperates.
Names:
- Cooperator: [Axelrod1984]_
- ALLC: [Press2012]_
- Always cooperate: [Mittal2009]_
"""

name = 'Cooperator'
classifier = {
Expand All @@ -24,7 +31,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
51 changes: 50 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,14 @@ def __init__(self) -> None:


class CyclerCCD(Cycler):
"""
Cycles C, C, D
Names:
- Cycler CCD: Original name by Marc Harper
- Periodic player CCD: [Mittal2009]_
"""
name = 'Cycler CCD'
classifier = copy.copy(Cycler.classifier)
classifier['memory_depth'] = 2
Expand All @@ -114,7 +137,14 @@ def __init__(self) -> None:


class CyclerDDC(Cycler):
"""
Cycles D, D, C
Names:
- Cycler DDC: Original name by Marc Harper
- Periodic player DDC: [Mittal2009]_
"""
name = 'Cycler DDC'
classifier = copy.copy(Cycler.classifier)
classifier['memory_depth'] = 2
Expand All @@ -124,7 +154,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 +170,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 +186,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
16 changes: 14 additions & 2 deletions axelrod/strategies/defector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@


class Defector(Player):
"""A player who only ever defects."""
"""A player who only ever defects.
Names:
- Defector: [Axelrod1984]_
- ALLD: [Press2012]_
- Always defect: [Mittal2009]_
"""

name = 'Defector'
classifier = {
Expand All @@ -24,7 +31,12 @@ def strategy(opponent: Player) -> Action:


class TrickyDefector(Player):
"""A defector that is trying to be tricky."""
"""A defector that is trying to be tricky.
Names:
- Tricky Defector: Original name by Karol Langner
"""

name = "Tricky Defector"
classifier = {
Expand Down
3 changes: 2 additions & 1 deletion axelrod/strategies/finite_state_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ class Pun1(FSMPlayer):
"""FSM player described in [Ashlock2006].
Names:
- Pun1 [Ashlock2006]_
- Pun1: [Ashlock2006]_
"""

name = 'Pun1'
Expand Down
Loading

0 comments on commit 99d0e2e

Please sign in to comment.