-
Notifications
You must be signed in to change notification settings - Fork 269
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
Michaelos strategy #1091
Michaelos strategy #1091
Changes from 22 commits
20d4be9
dbfb9f2
2e246da
2631c02
dc58ba8
6ade0fd
c16de25
1aef132
2cab969
b1d5f8b
862b10c
a9cbf02
52827c7
8783b18
371a2b2
5e1272d
c22d58a
29545ec
ae41d6c
7a10e4b
8ac65c6
07e4396
13c5635
e02e232
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -649,6 +649,7 @@ def strategy(self, opponent: Player) -> Action: | |
# Otherwise play previous move | ||
return self.history[-1] | ||
|
||
|
||
@FinalTransformer((D,), name_prefix=None) | ||
class Alexei(Player): | ||
""" | ||
|
@@ -677,6 +678,7 @@ def strategy(self, opponent: Player) -> Action: | |
return D | ||
return C | ||
|
||
|
||
@FinalTransformer((D,), name_prefix=None) | ||
class EugineNier(Player): | ||
""" | ||
|
@@ -761,7 +763,7 @@ def __init__(self, N: int=3, M: int=2) -> None: | |
super().__init__() | ||
self.N = N | ||
self.M = M | ||
self.classifier['memory_depth'] = max([M,N]) | ||
self.classifier['memory_depth'] = max([M, N]) | ||
self.retaliate_count = 0 | ||
|
||
def strategy(self, opponent: Player) -> Action: | ||
|
@@ -772,3 +774,52 @@ def strategy(self, opponent: Player) -> Action: | |
self.retaliate_count -= 1 | ||
return D | ||
return C | ||
|
||
|
||
@FinalTransformer((D,), name_prefix=None) | ||
class Michaelos(Player): | ||
""" | ||
Plays similar to Tit-for-Tat with two exceptions: | ||
1) Defect on last turn. | ||
2) After own defection and opponent's cooperation, 50 percent of the time, | ||
cooperate. The other 50 percent of the time, always defect for the rest of | ||
the game. | ||
|
||
Names: | ||
|
||
- Michaelos: [LessWrong2011]_ | ||
""" | ||
|
||
name = 'Michaelos' | ||
classifier = { | ||
'memory_depth': 1, | ||
'stochastic': True, | ||
'makes_use_of': {'length'}, | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.is_defector = False | ||
|
||
def strategy(self, opponent: Player) -> Action: | ||
if not self.history: | ||
return C | ||
if self.is_defector: | ||
return D | ||
if self.history[-1] == D and opponent.history[-1] == C: | ||
decision = random_choice() | ||
if(decision == C): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8:
|
||
return C | ||
else: | ||
self.is_defector = True | ||
return D | ||
|
||
return opponent.history[-1] | ||
|
||
def reset(self): | ||
super().reset() | ||
self.is_defector = False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -717,3 +717,50 @@ def test_varying_memory_depth(self): | |
self.assertEqual(self.player(1, 1).classifier['memory_depth'], 1) | ||
self.assertEqual(self.player(0, 3).classifier['memory_depth'], 3) | ||
self.assertEqual(self.player(5, 3).classifier['memory_depth'], 5) | ||
|
||
|
||
class TestMichaelos(TestPlayer): | ||
""" | ||
Tests for the Michaelos strategy | ||
""" | ||
|
||
name = "Michaelos: (D,)" | ||
player = axelrod.Michaelos | ||
expected_classifier = { | ||
'memory_depth': 1, | ||
'stochastic': True, | ||
'makes_use_of': {'length'}, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def test_strategy(self): | ||
|
||
actions = [(C, C), (C, C), (C, C), (D, C)] | ||
self.versus_test(axelrod.Cooperator(), expected_actions=actions, | ||
attrs={"is_defector": False}, seed=2) | ||
|
||
actions = [(C, C), (C, C), (C, C), (C, C)] | ||
self.versus_test(axelrod.Cooperator(), expected_actions=actions, | ||
attrs={"is_defector": False}, | ||
match_attributes={"length": -1}, seed=2) | ||
|
||
actions = [(C, D), (D, D), (D, D), (D, D)] | ||
self.versus_test(axelrod.Defector(), expected_actions=actions, | ||
attrs={"is_defector": False}, seed=2) | ||
|
||
actions = [(C, D), (D, D), (D, D), (D, D)] | ||
self.versus_test(axelrod.Defector(), expected_actions=actions, | ||
attrs={"is_defector": False}, | ||
match_attributes={"length": -1}, seed=2) | ||
|
||
# Chance of becoming a defector is 50% after (D, C) occurs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you repeat this test with a different seed to show differing behaviour after
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, I don't think this scenario is possible for the strategy unless I am misinterpreting something. After (C, D) Michaelos will play D since it is still playing like Tit-for-Tat. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the second test, does tweaking the test mean changing the expected actions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry you're correct, that was a typo from me, I simply mean to include a random seed version to illustrate that 50% of the time after
Yes. |
||
actions = [(C, C), (C, D), (D, C), (D, D), (D, C), (D, D), (D, C)] | ||
self.versus_test(axelrod.Alternator(), expected_actions=actions, | ||
attrs={"is_defector": True}, seed=2) | ||
|
||
actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (D, D), (D, C)] | ||
self.versus_test(axelrod.Alternator(), expected_actions=actions, | ||
attrs={"is_defector": True}, | ||
match_attributes={"length": -1}, seed=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the memory depth is not 1.
If on turn
n
Michaelos defects and the opponent cooperates then 50% of the time I defect and defect throughout, However if I have already become a defector than I will defect 100% of the time so I not only need to know the previous turns (that I D and you C but I also need to know if I D'd because I have already "transformed" in to a defector).I believe the memory depth is in fact
float('inf')
:If our actions are
...(D, D), (D, C)
then I do not know if my previous plays ofD
are TfT retaliations or because I have previously been turned in to a defector so I do not know if I need to randomly sample as a result of the last round being(D, C)
.