Skip to content

Implemented Mikkelson, k66r from Axelrod's second. #1167

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
Feb 22, 2018
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
3 changes: 2 additions & 1 deletion axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Champion, Eatherley, Tester, Gladstein, Tranquilizer, MoreGrofman,
Kluepfel, Borufsen, Cave, WmAdams, GraaskampKatzen, Weiner, Harrington,
MoreTidemanAndChieruzzi, Getzler, Leyvraz, White, Black, RichardHufford,
Yamachi, Colbert)
Yamachi, Colbert, Mikkelson)
from .backstabber import BackStabber, DoubleCrosser
from .better_and_better import BetterAndBetter
from .bush_mosteller import BushMosteller
Expand Down Expand Up @@ -208,6 +208,7 @@
NaiveProber,
MEM2,
Michaelos,
Mikkelson,
MindBender,
MindController,
MindReader,
Expand Down
64 changes: 64 additions & 0 deletions axelrod/strategies/axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -1851,3 +1851,67 @@ def __init__(self) -> None:

super().__init__(transitions=transitions, initial_state=0,
initial_action=C)


class Mikkelson(FSMPlayer):
"""
Strategy submitted to Axelrod's second tournament by Ray Mikkelson (K66R)
and came in twentieth in that tournament.

The strategy keeps track of a variable called `credit`, which determines if
the strategy will Cooperate, in the sense that if `credit` is positive,
then the strategy Cooperates. `credit` is initialized to 7. After the
first turn, `credit` increments if the opponent Cooperated last turn, and
decreases by two otherwise. `credit` is capped above by 8 and below by -7.
[`credit` is assessed as postive or negative, after increasing based on
opponent's last turn.]

If `credit` is non-positive within the first ten turns, then the strategy
Defects and `credit` is set to 4. If `credit` is non-positive later, then
the strategy Defects if and only if (total # opponent Defections) / (turn#)
is at least 15%. [Turn # starts at 1.]

Names:

- Mikkelson: [Axelrod1980b]_
"""

name = 'Mikkelson'
classifier = {
'memory_depth': float("inf"),
'stochastic': False,
'makes_use_of': set(),
'long_run_time': False,
'inspects_source': False,
'manipulates_source': False,
'manipulates_state': False
}

def __init__(self) -> None:
super().__init__()
self.credit = 7

def strategy(self, opponent: Player) -> Action:
turn = len(self.history) + 1
if turn == 1:
return C

if opponent.history[-1] == C:
self.credit += 1
if self.credit > 8:
self.credit = 8
else:
self.credit -= 2
if self.credit < -7:
self.credit = -7

if turn == 2:
return C
if self.credit > 0:
return C
if turn <= 10:
self.credit = 4
return D
if opponent.defections / turn >= 0.15:
return D
return C
54 changes: 54 additions & 0 deletions axelrod/tests/strategies/test_axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,3 +1189,57 @@ def test_strategy(self):
actions = [(C, C)] * 5 + [(D, C)] + [(C, C)] * 4
actions += [(C, D)] + [(D, C), (D, C), (C, C), (C, C)] + [(C, C)]
self.versus_test(OddBall, expected_actions=actions)


class TestMikkelson(TestPlayer):
name = 'Mikkelson'
player = axelrod.Mikkelson
expected_classifier = {
'memory_depth': float("inf"),
'stochastic': False,
'makes_use_of': set(),
'long_run_time': False,
'inspects_source': False,
'manipulates_source': False,
'manipulates_state': False
}

def test_strategy(self):
actions = [(C, C)] * 30
self.versus_test(axelrod.Cooperator(), expected_actions=actions, attrs={"credit": 8})

actions = [(C, D), (C, D), (C, D), (C, D)]
self.versus_test(axelrod.Defector(), expected_actions=actions, attrs={"credit": 1})
# Defect then reset to 4
actions += [(D, D)]
self.versus_test(axelrod.Defector(), expected_actions=actions, attrs={"credit": 4})
# Repeat
actions += [(C, D), (D, D)] * 2
self.versus_test(axelrod.Defector(), expected_actions=actions, attrs={"credit": 4})
# With ten turns passed, keep defecting now
actions += [(C, D), (D, D)]
self.versus_test(axelrod.Defector(), expected_actions=actions, attrs={"credit": 0})
# With ten turns passed, keep defecting now
actions += [(D, D)] * 30
self.versus_test(axelrod.Defector(), expected_actions=actions, attrs={"credit": -7})


actions = [(C, D), (C, D), (C, C)]
self.versus_test(axelrod.Cycler("DDC"), expected_actions=actions, attrs={"credit": 3})
actions += [(C, D), (C, D)]
self.versus_test(axelrod.Cycler("DDC"), expected_actions=actions, attrs={"credit": 2})
actions += [(D, C)]
self.versus_test(axelrod.Cycler("DDC"), expected_actions=actions, attrs={"credit": 4})
actions += [(C, D)]
self.versus_test(axelrod.Cycler("DDC"), expected_actions=actions, attrs={"credit": 5})
actions += [(C, D)]
self.versus_test(axelrod.Cycler("DDC"), expected_actions=actions, attrs={"credit": 3})

opponent_actions = [C] * 100 + [D] * 10
Change_of_Heart = axelrod.MockPlayer(actions=opponent_actions)
actions = [(C, C)] * 100 + [(C, D)] * 4
self.versus_test(Change_of_Heart, expected_actions=actions, attrs={"credit": 2})
Change_of_Heart = axelrod.MockPlayer(actions=opponent_actions)
actions += [(C, D)] * 2
self.versus_test(Change_of_Heart, expected_actions=actions, attrs={"credit": -2})
# Still Cooperate, because Defect rate is low
2 changes: 1 addition & 1 deletion axelrod/tests/strategies/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_strategy(self):
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=0)

actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
actions = [(C, C), (C, D), (C, C), (C, D), (D, C)]
self.versus_test(opponent=axelrod.Alternator(),
expected_actions=actions, seed=1)

Expand Down