Skip to content

Commit

Permalink
Add all but 2 remaining strategies.
Browse files Browse the repository at this point in the history
Currently missing:

- Soft Joss. Soft Joss is GTFT with a different parameter. We need to
find the literature with that particular parameter.
- Also cannot find EXTORT-4
  • Loading branch information
drvinceknight committed Jun 6, 2017
1 parent 05dfbb4 commit 124359a
Show file tree
Hide file tree
Showing 27 changed files with 460 additions and 90 deletions.
1 change: 1 addition & 0 deletions axelrod/strategies/alternator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Alternator(Player):
Names
- Alternator: [Axelrod1984]_
- Periodic player CD: [Mittal2009]_
"""

name = 'Alternator'
Expand Down
1 change: 1 addition & 0 deletions axelrod/strategies/cooperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Cooperator(Player):
- Cooperator: [Axelrod1984]_
- ALLC: [Press2012]_
- Always cooperate: [Mittal2009]_
"""

name = 'Cooperator'
Expand Down
2 changes: 2 additions & 0 deletions axelrod/strategies/cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CyclerCCD(Cycler):
Names:
- Cycler CCD: Original name by Marc Harper
- Periodic player CCD: [Mittal2009]_
"""
name = 'Cycler CCD'
classifier = copy.copy(Cycler.classifier)
Expand All @@ -142,6 +143,7 @@ class CyclerDDC(Cycler):
Names:
- Cycler DDC: Original name by Marc Harper
- Periodic player DDC: [Mittal2009]_
"""
name = 'Cycler DDC'
classifier = copy.copy(Cycler.classifier)
Expand Down
8 changes: 7 additions & 1 deletion axelrod/strategies/defector.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Defector(Player):
- Defector: [Axelrod1984]_
- ALLD: [Press2012]_
- Always defect: [Mittal2009]_
"""

name = 'Defector'
Expand All @@ -30,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
8 changes: 8 additions & 0 deletions axelrod/strategies/forgiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Forgiver(Player):
"""
A player starts by cooperating however will defect if at any point
the opponent has defected more than 10 percent of the time
Names:
- Forgiver: Original name by Thomas Campbell
"""

name = 'Forgiver'
Expand Down Expand Up @@ -36,6 +40,10 @@ class ForgivingTitForTat(Player):
A player starts by cooperating however will defect if at any point, the
opponent has defected more than 10 percent of the time, and their most
recent decision was defect.
Names:
- Forgiving Tit For Tat: Original name by Thomas Campbell
"""

name = 'Forgiving Tit For Tat'
Expand Down
18 changes: 13 additions & 5 deletions axelrod/strategies/gambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Gambler(LookerUp):
"""
A stochastic version of LookerUp which will select randomly an action in
some cases.
Names:
- Gambler: Original name by Georgios Koutsovoulos
"""

name = 'Gambler'
Expand Down Expand Up @@ -47,7 +51,8 @@ class PSOGamblerMem1(Gambler):
Axelrod library.
Names:
- PSO Gambler Mem1: Original name by Marc Harper
- PSO Gambler Mem1: Original name by Marc Harper
"""

name = "PSO Gambler Mem1"
Expand All @@ -64,7 +69,8 @@ class PSOGambler1_1_1(Gambler):
A 1x1x1 PSOGambler trained with pyswarm.
Names:
- PSO Gambler 1_1_1: Original name by Marc Harper
- PSO Gambler 1_1_1: Original name by Marc Harper
"""

name = "PSO Gambler 1_1_1"
Expand All @@ -78,10 +84,12 @@ def __init__(self) -> None:

class PSOGambler2_2_2(Gambler):
"""
A 2x2x2 PSOGambler trained with pyswarm. Original version by @GDKO.
A 2x2x2 PSOGambler trained with a particle swarm algorithm (implemented in
pyswarm). Original version by Georgios Koutsovoulos.
Names:
- PSO Gambler 2_2_2: Original name by Marc Harper
- PSO Gambler 2_2_2: Original name by Marc Harper
"""

name = "PSO Gambler 2_2_2"
Expand All @@ -98,8 +106,8 @@ class PSOGambler2_2_2_Noise05(Gambler):
A 2x2x2 PSOGambler trained with pyswarm with noise=0.05.
Names:
- PSO Gambler 2_2_2 Noise 05: Original name by Marc Harper
- PSO Gambler 2_2_2 Noise 05: Original name by Marc Harper
"""

name = "PSO Gambler 2_2_2 Noise 05"
Expand Down
17 changes: 15 additions & 2 deletions axelrod/strategies/geller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Geller(Player):
If unable to do this: will play randomly.
Geller - by Martin Chorley (@martinjc), heavily inspired by Matthew Williams (@voxmjw)
This code is inspired by Matthew Williams' talk
"Cheating at rock-paper-scissors — meta-programming in Python"
Expand All @@ -33,6 +32,10 @@ class Geller(Player):
This is almost certainly cheating, and more than likely against the
spirit of the 'competition' :-)
Names:
- Geller: Original name by Martin Chorley (@martinjc)
"""

name = 'Geller'
Expand Down Expand Up @@ -64,6 +67,10 @@ def strategy(self, opponent: Player) -> Action:
class GellerCooperator(Geller):
"""Observes what the payer will do (like :code:`Geller`) but if unable to
will cooperate.
Names:
- Geller Cooperator: Original name by Karol Langner
"""
name = 'Geller Cooperator'
classifier = {
Expand All @@ -78,13 +85,19 @@ class GellerCooperator(Geller):

@staticmethod
def foil_strategy_inspection() -> Action:
"""Foils _strategy_utils.inspect_strategy and _strategy_utils.look_ahead"""
"""
Foils _strategy_utils.inspect_strategy and _strategy_utils.look_ahead
"""
return C


class GellerDefector(Geller):
"""Observes what the payer will do (like :code:`Geller`) but if unable to
will defect.
Names:
- Geller Defector: Original name by Karol Langner
"""
name = 'Geller Defector'
classifier = {
Expand Down
41 changes: 41 additions & 0 deletions axelrod/strategies/gobymajority.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class GoByMajority(Player):
An optional memory attribute will limit the number of turns remembered (by
default this is 0)
Names:
- Go By Majority: [Axelrod1984]_
- Soft Majority: [Mittal2009]_
"""

name = 'Go By Majority'
Expand Down Expand Up @@ -86,6 +91,10 @@ def strategy(self, opponent: Player) -> Action:
class GoByMajority40(GoByMajority):
"""
GoByMajority player with a memory of 40.
Names:
- Go By Majority 40: Original name by Karol Langner
"""
name = 'Go By Majority 40'
classifier = copy.copy(GoByMajority.classifier)
Expand All @@ -98,6 +107,10 @@ def __init__(self) -> None:
class GoByMajority20(GoByMajority):
"""
GoByMajority player with a memory of 20.
Names:
- Go By Majority 20: Original name by Karol Langner
"""
name = 'Go By Majority 20'
classifier = copy.copy(GoByMajority.classifier)
Expand All @@ -110,6 +123,10 @@ def __init__(self) -> None:
class GoByMajority10(GoByMajority):
"""
GoByMajority player with a memory of 10.
Names:
- Go By Majority 10: Original name by Karol Langner
"""
name = 'Go By Majority 10'
classifier = copy.copy(GoByMajority.classifier)
Expand All @@ -122,6 +139,10 @@ def __init__(self) -> None:
class GoByMajority5(GoByMajority):
"""
GoByMajority player with a memory of 5.
Names:
- Go By Majority 5: Original name by Karol Langner
"""
name = 'Go By Majority 5'
classifier = copy.copy(GoByMajority.classifier)
Expand All @@ -138,6 +159,10 @@ class HardGoByMajority(GoByMajority):
An optional memory attribute will limit the number of turns remembered (by
default this is 0)
Names:
- Hard Majority: [Mittal2009]_
"""
name = 'Hard Go By Majority'

Expand All @@ -148,6 +173,10 @@ def __init__(self, memory_depth: Union[int, float] = float('inf')) -> None:
class HardGoByMajority40(HardGoByMajority):
"""
HardGoByMajority player with a memory of 40.
Names:
- Hard Go By Majority 40: Original name by Karol Langner
"""
name = 'Hard Go By Majority 40'
classifier = copy.copy(GoByMajority.classifier)
Expand All @@ -160,6 +189,10 @@ def __init__(self) -> None:
class HardGoByMajority20(HardGoByMajority):
"""
HardGoByMajority player with a memory of 20.
Names:
- Hard Go By Majority 20: Original name by Karol Langner
"""
name = 'Hard Go By Majority 20'
classifier = copy.copy(GoByMajority.classifier)
Expand All @@ -172,6 +205,10 @@ def __init__(self) -> None:
class HardGoByMajority10(HardGoByMajority):
"""
HardGoByMajority player with a memory of 10.
Names:
- Hard Go By Majority 10: Original name by Karol Langner
"""
name = 'Hard Go By Majority 10'
classifier = copy.copy(GoByMajority.classifier)
Expand All @@ -184,6 +221,10 @@ def __init__(self) -> None:
class HardGoByMajority5(HardGoByMajority):
"""
HardGoByMajority player with a memory of 5.
Names:
- Hard Go By Majority 5: Original name by Karol Langner
"""
name = 'Hard Go By Majority 5'
classifier = copy.copy(GoByMajority.classifier)
Expand Down
36 changes: 26 additions & 10 deletions axelrod/strategies/grudger.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ def strategy(opponent: Player) -> Action:


class ForgetfulGrudger(Player):
"""A player starts by cooperating however will defect if at any point the
opponent has defected, but forgets after mem_length matches."""
"""
A player starts by cooperating however will defect if at any point the
opponent has defected, but forgets after mem_length matches.
Names:
- Forgetful Grudger: Original name by Geraint Palmer
"""

name = 'Forgetful Grudger'
classifier = {
Expand Down Expand Up @@ -83,8 +89,14 @@ def reset(self):


class OppositeGrudger(Player):
"""A player starts by defecting however will cooperate if at any point the
opponent has cooperated."""
"""
A player starts by defecting however will cooperate if at any point the
opponent has cooperated.
Names:
- Opposite Grudger: Original name by Geraint Palmer
"""

name = 'Opposite Grudger'
classifier = {
Expand All @@ -107,7 +119,13 @@ def strategy(opponent: Player) -> Action:


class Aggravater(Player):
"""Grudger, except that it defects on the first 3 turns"""
"""
Grudger, except that it defects on the first 3 turns
Names
Aggravater: Original name by Thomas Campbell
"""

name = 'Aggravater'
classifier = {
Expand Down Expand Up @@ -135,10 +153,7 @@ class SoftGrudger(Player):
defecting: punishes by playing: D, D, D, D, C, C. (Will continue to
cooperate afterwards).
For reference see: "Engineering Design of Strategies for Winning
Iterated Prisoner's Dilemma Competitions" by Jiawei Li, Philip Hingston,
and Graham Kendall. IEEE TRANSACTIONS ON COMPUTATIONAL INTELLIGENCE AND AI
IN GAMES, VOL. 3, NO. 4, DECEMBER 2011
- Soft Grudger (SGRIM): [Li2011]_
"""

name = 'Soft Grudger'
Expand Down Expand Up @@ -218,7 +233,8 @@ class EasyGo(Player):
Names:
- Easy Go [Prison1998]_
- Easy Go: [Prison1998]_
- Reverse Grudger (RGRIM): [Li2011]_
"""

name = 'EasyGo'
Expand Down
10 changes: 8 additions & 2 deletions axelrod/strategies/grumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@


class Grumpy(Player):
"""A player that defects after a certain level of grumpiness.
"""
A player that defects after a certain level of grumpiness.
Grumpiness increases when the opponent defects and decreases
when the opponent co-operates."""
when the opponent co-operates.
Names:
- Grumpy: Original name by Jason Young
"""

name = 'Grumpy'
classifier = {
Expand Down
Loading

0 comments on commit 124359a

Please sign in to comment.