Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 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)
Copy link
Member

Choose a reason for hiding this comment

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

(D,) (no space)

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

Choose a reason for hiding this comment

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

Can you reference this as for other strategies please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only strategy implemented from the site.

Copy link
Member

Choose a reason for hiding this comment

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

Yes that's fine but can you move the site to the bibliography and make the Names section fit the guidelines: http://axelrod.readthedocs.io/en/stable/tutorials/contributing/strategy/docstrings.html

Copy link
Member

Choose a reason for hiding this comment

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

Take a look at how Prison is written in the bibliography. Let me know if you'd like a hand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I had forgotten the docstrings conventions for Axelrod.

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 you actually wrote that file I linked to :) 🤣 👍 )

"""

name = 'Alexei'
classifier = {
'memory_depth': 1,
Copy link
Member

Choose a reason for hiding this comment

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

This strategy has memory depth: float('inf') as it needs to keep count of how many turns it has played to be able to know when to defect on the last round.

Fixing this will fix the other test failure as it was being picked up as a basic strategy (which it is not).

'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
51 changes: 51 additions & 0 deletions axelrod/tests/strategies/test_titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
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)]
Copy link
Member

Choose a reason for hiding this comment

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

Could you add one more round to this actions, the point of having match_attributes={"length":-1} is to show how the strategy acts when playing without knowledge of the when the last round is so the last actions would be:

actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (C, D)]

Then can you repeat the exact same test but without match_attributes which should then have:

actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (D D)]

Which shows that the "last round" instruction is working. (So just move your other alternator test here and add the extra round).

self.versus_test(axelrod.Alternator(), expected_actions=actions,
match_attributes={"length": -1})

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)
6 changes: 3 additions & 3 deletions docs/tutorials/advanced/classification_of_strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ make a decision::
... }
>>> strategies = axl.filtered_strategies(filterset)
>>> len(strategies)
27
28

Multiple filters can be specified within the filterset dictionary. To specify a
range of memory_depth values, we can use the 'min_memory_depth' and
Expand All @@ -69,7 +69,7 @@ range of memory_depth values, we can use the 'min_memory_depth' and
... }
>>> strategies = axl.filtered_strategies(filterset)
>>> len(strategies)
49
50

We can also identify strategies that make use of particular properties of the
tournament. For example, here is the number of strategies that make use of the
Expand All @@ -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