Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0b71b6e
Update _strategies.py
souravsingh Apr 30, 2017
fa70b52
Update titfortat.py
souravsingh Apr 30, 2017
0be3624
Update test_titfortat.py
souravsingh Apr 30, 2017
4c471b9
Fix error
souravsingh Apr 30, 2017
640712e
Update classification_of_strategies.rst
souravsingh Apr 30, 2017
de8f570
Add Finaltransformer in Alexei strategy
souravsingh May 2, 2017
c977452
Update titfortat.py
souravsingh May 3, 2017
a0b9f63
Make changes to strategy
souravsingh May 4, 2017
b70c5c2
Update test_titfortat.py
souravsingh May 4, 2017
693ea45
Update test_titfortat.py
souravsingh May 4, 2017
e83de3a
Fix name of strategy
souravsingh May 6, 2017
1aa8b4f
Fix classifier parameter
souravsingh May 6, 2017
fd1fa66
Update titfortat.py
souravsingh May 6, 2017
fd55bf6
Update test_titfortat.py
souravsingh May 6, 2017
ea8bb11
Update classification_of_strategies.rst
souravsingh May 6, 2017
d3207d6
Fix test
souravsingh May 8, 2017
5c1d688
Update test_titfortat.py
souravsingh May 8, 2017
62bb722
Fix issue with FinalTransformer
souravsingh May 8, 2017
7d1a8cf
Update titfortat.py
souravsingh May 8, 2017
f8db68d
Update the memory_depth parameter
souravsingh May 8, 2017
d789c38
Fix missing comma between parameters
souravsingh May 8, 2017
b10c09d
Change name of strategy
souravsingh May 8, 2017
bb55e6c
Fix doctest
souravsingh May 8, 2017
e3fe33b
Add reference to LessWrong for Alexei
souravsingh May 8, 2017
f0f863a
Update titfortat.py
souravsingh May 8, 2017
02a5801
Add test cases
souravsingh May 10, 2017
54c54fc
Remove a few tests
souravsingh May 10, 2017
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 @@ -75,7 +75,7 @@
TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat,
SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats,
OmegaTFT, Gradual, ContriteTitForTat, SlowTitForTwoTats, AdaptiveTitForTat,
SpitefulTitForTat, SlowTitForTwoTats2)
SpitefulTitForTat, SlowTitForTwoTats2, Alexei)
from .verybad import VeryBad
from .worse_and_worse import (WorseAndWorse, KnowledgeableWorseAndWorse,
WorseAndWorse2, WorseAndWorse3)
Expand All @@ -86,6 +86,7 @@
Adaptive,
AdaptiveTitForTat,
Aggravater,
Alexei,
ALLCorALLD,
Alternator,
AlternatorHunter,
Expand Down
30 changes: 29 additions & 1 deletion axelrod/strategies/titfortat.py
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

Expand Down Expand Up @@ -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:

- Alexei's Strategy: [LessWrong2011]_
"""

name = 'Alexei'
classifier = {
'memory_depth': float('inf'),
'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
53 changes: 53 additions & 0 deletions axelrod/tests/strategies/test_titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,56 @@ 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):
"""
Tests for the Alexei strategy
"""

name = "Alexei: ('D',)"
player = axelrod.Alexei
expected_classifier = {
'memory_depth': float('inf'),
'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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this test because you moved it.

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)
Copy link
Member

Choose a reason for hiding this comment

The 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), (C, D)]
self.versus_test(axelrod.Alternator(), expected_actions=actions,
match_attributes={"length": -1})

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


actions = [(C, D), (D, D), (D, C), (C, C), (D, D)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the test case will be covered by the cases above, we can simplify this and remove everything below.

Copy link
Member

Choose a reason for hiding this comment

The 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.

self.versus_test(axelrod.Random(), expected_actions=actions,
seed=0)

actions = [(C, C), (C, D), (D, D), (D, C)]
Copy link
Member

Choose a reason for hiding this comment

The 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.

self.versus_test(axelrod.Random(), expected_actions=actions,
seed=1)

opponent = axelrod.MockPlayer(actions=[C, D])
Copy link
Member

Choose a reason for hiding this comment

The 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, D), (D, C), (D, D)]
self.versus_test(opponent, expected_actions=actions)

opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, D])
Copy link
Member

Choose a reason for hiding this comment

The 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)
1 change: 1 addition & 0 deletions docs/reference/bibliography.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ documentation.
.. [Frean1994] Frean, Marcus R. “The Prisoner's Dilemma without Synchrony.” Proceedings: Biological Sciences, vol. 257, no. 1348, 1994, pp. 75–79. www.jstor.org/stable/50253.
.. [Hilde2013] Hilbe, C., Nowak, M.A. and Traulsen, A. (2013). Adaptive dynamics of extortion and compliance, PLoS ONE, 8(11), p. e77886. doi: 10.1371/journal.pone.0077886.
.. [Kraines1989] Kraines, D. & Kraines, V. Theor Decis (1989) 26: 47. doi:10.1007/BF00134056
.. [LessWrong2011] Zoo of Strategies (2011) LessWrong. Available at: http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All on one line please. I think this doesn't play properly with sphinx otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have written in one line. Unless I am misunderstanding something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have indeed. I'll review properly when I get a moment.

.. [Li2009] Li, J. & Kendall, G. (2009). A Strategy with Novel Evolutionary Features for the Iterated Prisoner’s Dilemma. Evolutionary Computation 17(2): 257–274.
.. [Li2011] Li, J., Hingston, P., Member, S., & Kendall, G. (2011). Engineering Design of Strategies for Winning Iterated Prisoner ’ s Dilemma Competitions, 3(4), 348–360.
.. [Li2014] Li, J. and Kendall, G. (2016). The Effect of Memory Size on the Evolutionary Stability of Strategies in Iterated Prisoner's Dilemma. IEEE Transactions on Evolutionary Computation, 18(6) 819-826
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/advanced/classification_of_strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ length of each match of the tournament::
... }
>>> strategies = axl.filtered_strategies(filterset)
>>> len(strategies)
25
26

Note that in the filterset dictionary, the value for the 'makes_use_of' key
must be a list. Here is how we might identify the number of strategies that use
Expand Down