Skip to content

New Strategies: Mem2, Pun1, Collective Strategy #795

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

Merged
merged 5 commits into from
Jan 1, 2017
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
36 changes: 22 additions & 14 deletions axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from .apavlov import APavlov2006, APavlov2011
from .appeaser import Appeaser
from .averagecopier import AverageCopier, NiceAverageCopier
from .axelrod_first import (Davis, RevisedDowning, Feld, Grofman, Nydegger,
Joss, Shubik, Tullock, UnnamedStrategy)
from .axelrod_first import (
Davis, RevisedDowning, Feld, Grofman, Nydegger, Joss, Shubik, Tullock,
UnnamedStrategy)
from .axelrod_second import Champion, Eatherley, Tester
from .backstabber import BackStabber, DoubleCrosser
from .better_and_better import BetterAndBetter
Expand All @@ -20,16 +21,15 @@
from .defector import Defector, TrickyDefector
from .doubler import Doubler
from .finite_state_machines import (
Fortress3, Fortress4, Predator, Raider, Ripoff, SolutionB1, SolutionB5,
Thumper, FSMPlayer)
Fortress3, Fortress4, Predator, Pun1, Raider, Ripoff, SolutionB1,
SolutionB5, Thumper, FSMPlayer)
from .forgiver import Forgiver, ForgivingTitForTat
from .geller import Geller, GellerCooperator, GellerDefector
from .gambler import Gambler, PSOGambler
from .gobymajority import (GoByMajority,
GoByMajority10, GoByMajority20, GoByMajority40,
GoByMajority5,
HardGoByMajority, HardGoByMajority10, HardGoByMajority20, HardGoByMajority40,
HardGoByMajority5)
from .gobymajority import (
GoByMajority, GoByMajority10, GoByMajority20, GoByMajority40,
GoByMajority5, HardGoByMajority, HardGoByMajority10, HardGoByMajority20,
HardGoByMajority40, HardGoByMajority5)
from .gradualkiller import GradualKiller
from .grudger import (Grudger, ForgetfulGrudger, OppositeGrudger, Aggravater,
SoftGrudger, GrudgerAlternator, EasyGo)
Expand All @@ -46,15 +46,17 @@
MemoryOnePlayer, ALLCorALLD, FirmButFair, GTFT, SoftJoss,
StochasticCooperator, StochasticWSLS, ZDExtort2, ZDExtort2v2, ZDExtort4,
ZDGen2, ZDGTFT2, ZDSet2, WinStayLoseShift, WinShiftLoseStay)
from .memorytwo import MEM2
from .mindcontrol import MindController, MindWarper, MindBender
from .mindreader import MindReader, ProtectedMindReader, MirrorMindReader
from .mutual import Desperate, Hopeless, Willing
from .negation import Negation
from .oncebitten import OnceBitten, FoolMeOnce, ForgetfulFoolMeOnce, FoolMeForever
from .prober import (Prober, Prober2, Prober3, Prober4, HardProber,
NaiveProber, RemorsefulProber)
from .prober import (CollectiveStrategy, Prober, Prober2, Prober3, Prober4,
HardProber, NaiveProber, RemorsefulProber)
from .punisher import Punisher, InversePunisher
from .qlearner import RiskyQLearner, ArrogantQLearner, HesitantQLearner, CautiousQLearner
from .qlearner import (
RiskyQLearner, ArrogantQLearner, HesitantQLearner, CautiousQLearner)
from .rand import Random
from .retaliate import (
Retaliate, Retaliate2, Retaliate3, LimitedRetaliate, LimitedRetaliate2,
Expand All @@ -63,8 +65,10 @@
from .titfortat import (
TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat,
SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats,
OmegaTFT, Gradual, ContriteTitForTat, SlowTitForTwoTats, AdaptiveTitForTat,SpitefulTitForTat)
from .worse_and_worse import (WorseAndWorse, KnowledgeableWorseAndWorse, WorseAndWorse2, WorseAndWorse3)
OmegaTFT, Gradual, ContriteTitForTat, SlowTitForTwoTats, AdaptiveTitForTat,
SpitefulTitForTat)
from .worse_and_worse import (WorseAndWorse, KnowledgeableWorseAndWorse,
WorseAndWorse2, WorseAndWorse3)

# Note: Meta* strategies are handled in .__init__.py

Expand All @@ -88,6 +92,7 @@
Calculator,
CautiousQLearner,
Champion,
CollectiveStrategy,
ContriteTitForTat,
Cooperator,
CooperatorHunter,
Expand Down Expand Up @@ -157,6 +162,7 @@
LimitedRetaliate3,
MathConstantHunter,
NaiveProber,
MEM2,
MindBender,
MindController,
MindReader,
Expand All @@ -175,6 +181,7 @@
Prober3,
Prober4,
ProtectedMindReader,
Pun1,
Punisher,
Raider,
Random,
Expand All @@ -183,6 +190,7 @@
Retaliate,
Retaliate2,
Retaliate3,
RevisedDowning,
Ripoff,
RiskyQLearner,
Shubik,
Expand Down
187 changes: 117 additions & 70 deletions axelrod/strategies/finite_state_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class FSMPlayer(Player):
}

@init_args
def __init__(self, transitions=None, initial_state=None, initial_action=None):
def __init__(self, transitions=None, initial_state=None,
initial_action=None):
if not transitions:
# Tit For Tat
transitions = [(1, C, 1, C), (1, D, 1, D)]
Expand Down Expand Up @@ -92,14 +93,16 @@ class Fortress3(FSMPlayer):

@init_args
def __init__(self):
transitions = ((1, D, 2, D),
(1, C, 1, D),
(2, C, 1, D),
(2, D, 3, C),
(3, C, 3, C),
(3, D, 1, D))
transitions = (
(1, D, 2, D),
(1, C, 1, D),
(2, C, 1, D),
(2, D, 3, C),
(3, C, 3, C),
(3, D, 1, D)
)

FSMPlayer.__init__(self, transitions=transitions, initial_state=1, initial_action=D)
FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=D)


class Fortress4(FSMPlayer):
Expand All @@ -120,14 +123,16 @@ class Fortress4(FSMPlayer):

@init_args
def __init__(self):
transitions = ((1, C, 1, D),
(1, D, 2, D),
(2, C, 1, D),
(2, D, 3, D),
(3, C, 1, D),
(3, D, 4, C),
(4, C, 4, C),
(4, D, 1, D))
transitions = (
(1, C, 1, D),
(1, D, 2, D),
(2, C, 1, D),
(2, D, 3, D),
(3, C, 1, D),
(3, D, 4, C),
(4, C, 4, C),
(4, D, 1, D)
)

FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=D)

Expand All @@ -148,28 +153,60 @@ class Predator(FSMPlayer):

@init_args
def __init__(self):
transitions = ((0, C, 0, D),
(0, D, 1, D),
(1, C, 2, D),
(1, D, 3, D),
(2, C, 4, C),
(2, D, 3, D),
(3, C, 5, D),
(3, D, 4, C),
(4, C, 2, C),
(4, D, 6, D),
(5, C, 7, D),
(5, D, 3, D),
(6, C, 7, C),
(6, D, 7, D),
(7, C, 8, D),
(7, D, 7, D),
(8, C, 8, D),
(8, D, 6, D))
transitions = (
(0, C, 0, D),
(0, D, 1, D),
(1, C, 2, D),
(1, D, 3, D),
(2, C, 4, C),
(2, D, 3, D),
(3, C, 5, D),
(3, D, 4, C),
(4, C, 2, C),
(4, D, 6, D),
(5, C, 7, D),
(5, D, 3, D),
(6, C, 7, C),
(6, D, 7, D),
(7, C, 8, D),
(7, D, 7, D),
(8, C, 8, D),
(8, D, 6, D)
)

FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=C)


class Pun1(FSMPlayer):
"""FSM player described in [Ashlock2006].

Names:
- Pun1 [Ashlock2006]_
"""

name = 'Pun1'
classifier = {
'memory_depth': 2,
'stochastic': False,
'makes_use_of': set(),
'long_run_time': False,
'inspects_source': False,
'manipulates_source': False,
'manipulates_state': False
}

@init_args
def __init__(self):
transitions = (
(1, C, 2, C),
(1, D, 2, C),
(2, C, 1, C),
(2, D, 1, D)
)

FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=D)


class Raider(FSMPlayer):
"""FSM player described in DOI:10.1109/FOCI.2014.7007818"""

Expand All @@ -186,14 +223,16 @@ class Raider(FSMPlayer):

@init_args
def __init__(self):
transitions = ((0, C, 2, D),
(0, D, 2, D),
(1, C, 1, C),
(1, D, 1, D),
(2, C, 0, D),
(2, D, 3, C),
(3, C, 0, D),
(3, D, 1, C))
transitions = (
(0, C, 2, D),
(0, D, 2, D),
(1, C, 1, C),
(1, D, 1, D),
(2, C, 0, D),
(2, D, 3, C),
(3, C, 0, D),
(3, D, 1, C)
)

FSMPlayer.__init__(self, transitions, initial_state=0, initial_action=D)

Expand All @@ -214,12 +253,14 @@ class Ripoff(FSMPlayer):

@init_args
def __init__(self):
transitions = ((1, C, 2, C),
(1, D, 3, C),
(2, C, 1, D),
(2, D, 3, C),
(3, C, 3, C), # Note that it's TFT in state 3
(3, D, 3, D))
transitions = (
(1, C, 2, C),
(1, D, 3, C),
(2, C, 1, D),
(2, D, 3, C),
(3, C, 3, C), # Note that it's TFT in state 3
(3, D, 3, D)
)

FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=D)

Expand All @@ -240,12 +281,14 @@ class SolutionB1(FSMPlayer):

@init_args
def __init__(self):
transitions = ((1, C, 2, D),
(1, D, 1, D),
(2, C, 2, C),
(2, D, 3, C),
(3, C, 3, C),
(3, D, 3, C))
transitions = (
(1, C, 2, D),
(1, D, 1, D),
(2, C, 2, C),
(2, D, 3, C),
(3, C, 3, C),
(3, D, 3, C)
)

FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=D)

Expand All @@ -266,18 +309,20 @@ class SolutionB5(FSMPlayer):

@init_args
def __init__(self):
transitions = ((1, C, 2, C),
(1, D, 6, D),
(2, C, 2, C),
(2, D, 3, D),
(3, C, 6, C),
(3, D, 1, D),
(4, C, 3, C),
(4, D, 6, D),
(5, C, 5, D),
(5, D, 4, D),
(6, C, 3, C),
(6, D, 5, D))
transitions = (
(1, C, 2, C),
(1, D, 6, D),
(2, C, 2, C),
(2, D, 3, D),
(3, C, 6, C),
(3, D, 1, D),
(4, C, 3, C),
(4, D, 6, D),
(5, C, 5, D),
(5, D, 4, D),
(6, C, 3, C),
(6, D, 5, D)
)

FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=D)

Expand All @@ -298,9 +343,11 @@ class Thumper(FSMPlayer):

@init_args
def __init__(self):
transitions = ((1, C, 1, C),
(1, D, 2, D),
(2, C, 1, D),
(2, D, 1, D))
transitions = (
(1, C, 1, C),
(1, D, 2, D),
(2, C, 1, D),
(2, D, 1, D)
)

FSMPlayer.__init__(self, transitions, initial_state=1, initial_action=C)
1 change: 0 additions & 1 deletion axelrod/strategies/memoryone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from axelrod import Actions, Player, init_args, random_choice

"""IPD Strategies: http://www.prisoners-dilemma.com/strategies.html"""

C, D = Actions.C, Actions.D

Expand Down
Loading