-
Notifications
You must be signed in to change notification settings - Fork 282
Add Alexei strategy #997
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
Add Alexei strategy #997
Changes from 18 commits
0b71b6e
fa70b52
0be3624
4c471b9
640712e
de8f570
c977452
a0b9f63
b70c5c2
693ea45
e83de3a
1aa8b4f
fd1fa66
fd55bf6
ea8bb11
d3207d6
5c1d688
62bb722
7d1a8cf
f8db68d
d789c38
b10c09d
bb55e6c
e3fe33b
f0f863a
02a5801
54c54fc
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from axelrod.actions import Actions, Action | ||
| from axelrod.player import Player | ||
| from axelrod.strategy_transformers import TrackHistoryTransformer | ||
| from axelrod.strategy_transformers import TrackHistoryTransformer, FinalTransformer | ||
|
|
||
| C, D = Actions.C, Actions.D | ||
|
|
||
|
|
@@ -636,3 +636,31 @@ def strategy(self, opponent: Player) -> Action: | |
|
|
||
| # Otherwise play previous move | ||
| return self.history[-1] | ||
|
|
||
| @FinalTransformer((D, ) name_prefix=None) | ||
| class Alexei(Player): | ||
| """ | ||
| Plays similar to Tit-for-Tat, but always defect on last turn. | ||
|
|
||
| Names: | ||
|
|
||
| - From http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/ | ||
|
||
| """ | ||
|
|
||
| name = 'Alexei' | ||
| classifier = { | ||
| 'memory_depth': 1, | ||
|
||
| 'stochastic': False, | ||
| 'makes_use_of': {'length'}, | ||
| 'long_run_time': False, | ||
| 'inspects_source': False, | ||
| 'manipulates_source': False, | ||
| 'manipulates_state': False | ||
| } | ||
|
|
||
| def strategy(self, opponent: Player) -> Action: | ||
| if not self.history: | ||
| return C | ||
| if opponent.history[-1] == D: | ||
| return D | ||
| return C | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -563,3 +563,54 @@ def test_strategy(self): | |
| actions = [(C, C), (C, C), (C, D), (C, D), (D, C), (D, D), (D, D), | ||
| (D, C), (D, C), (C, D), (C, D)] | ||
| self.versus_test(opponent, expected_actions=actions) | ||
|
|
||
| class TestAlexei(TestPlayer): | ||
| """ | ||
| Note that this test is referred to in the documentation as an example on | ||
| writing tests. If you modify the tests here please also modify the | ||
| documentation. | ||
| """ | ||
|
|
||
| name = "Alexei: D" | ||
| player = axelrod.Alexei | ||
| expected_classifier = { | ||
| 'memory_depth': 1, | ||
| 'stochastic': False, | ||
| 'makes_use_of': {'length'}, | ||
| 'inspects_source': False, | ||
| 'manipulates_source': False, | ||
| 'manipulates_state': False | ||
| } | ||
|
|
||
| def test_strategy(self): | ||
| self.first_play_test(C) | ||
| self.second_play_test(rCC=C, rCD=D, rDC=C, rDD=D) | ||
|
|
||
| actions = [(C, C), (C, D), (D, C), (C, D), (D, C)] | ||
|
||
| self.versus_test(axelrod.Alternator(), expected_actions=actions) | ||
|
|
||
| actions = [(C, C), (C, C), (C, C), (C, C), (D, C)] | ||
| self.versus_test(axelrod.Cooperator(), expected_actions=actions) | ||
|
Member
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. You are getting a failure against Cooperator. |
||
|
|
||
| actions = [(C, D), (D, D), (D, D), (D, D), (D, D)] | ||
| self.versus_test(axelrod.Defector(), expected_actions=actions) | ||
|
|
||
| actions = [(C, C), (C, D), (D, C), (C, D), (D, C)] | ||
|
||
| self.versus_test(axelrod.Alternator(), expected_actions=actions, | ||
| match_attributes={"length": -1}) | ||
|
|
||
| actions = [(C, D), (D, D), (D, C), (C, C), (D, D)] | ||
|
||
| self.versus_test(axelrod.Random(), expected_actions=actions, | ||
| seed=0) | ||
|
|
||
| actions = [(C, C), (C, D), (D, D), (D, C)] | ||
|
||
| self.versus_test(axelrod.Random(), expected_actions=actions, | ||
| seed=1) | ||
|
|
||
| opponent = axelrod.MockPlayer(actions=[C, D]) | ||
|
||
| actions = [(C, C), (C, D), (D, C), (D, D)] | ||
| self.versus_test(opponent, expected_actions=actions) | ||
|
|
||
| opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, D]) | ||
|
Member
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. As long as coverage remains the same, I think we can remove this test. |
||
| actions = [(C, C), (C, C), (C, D), (D, D), (D, C), (D, D)] | ||
| self.versus_test(opponent, expected_actions=actions) | ||
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.
(D,)(no space)