Skip to content
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

New Strategy From the PRISON (http://www.lifl.fr/IPD/ipd.frame.html) #724

Merged
merged 13 commits into from
Sep 28, 2016
4 changes: 2 additions & 2 deletions axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat,
SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats,
OmegaTFT, Gradual, ContriteTitForTat, SlowTitForTwoTats, AdaptiveTitForTat)
from .worse_and_worse import (WorseAndWorse, WorseAndWorseRandom)
from .worse_and_worse import (WorseAndWorse, KnowledgeableWorseAndWorse)

# Note: Meta* strategies are handled in .__init__.py

Expand Down Expand Up @@ -196,7 +196,7 @@
WinShiftLoseStay,
WinStayLoseShift,
WorseAndWorse,
WorseAndWorseRandom,
KnowledgeableWorseAndWorse,
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 put this in alphabetical order please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

ZDExtort2,
ZDExtort2v2,
ZDExtort4,
Expand Down
18 changes: 9 additions & 9 deletions axelrod/strategies/worse_and_worse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import random

from axelrod import Actions, Player, random_choice

C, D = Actions.C, Actions.D
Expand All @@ -10,11 +8,12 @@ class WorseAndWorse (Player):
it is more and more likely to defect as the round goes on.
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:

Source code available at the download tab of [PRISON1998].

Copy link
Member Author

Choose a reason for hiding this comment

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

Would this line go at the end of line 10 or do you want it as part of the names section?

Copy link
Member

Choose a reason for hiding this comment

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

In between line 10 and the names section. So:

Defects with probability ...
is more likely ...

Source code available ...

Names...

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the clarification, I have now made this change.


Names:
- worse_and_worse: [PRISON1998]
- worse_and_worse: Source code available at the download tab of
[PRISON1998].
Copy link
Member

@drvinceknight drvinceknight Sep 27, 2016

Choose a reason for hiding this comment

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

Does this indent render ok? (you can run make html to check from the docs directory, you might have to pip install a sphinx theme...)

I think the rst syntax should be:

        - worse_and_worse: Source code available at the download tab of
          [PRISON1998].


"""

name = 'Worse and worse'
name = 'Worse and Worse'
classifier = {
'memory_depth': float('inf'),
'stochastic': True,
Expand All @@ -27,19 +26,20 @@ class WorseAndWorse (Player):

def strategy(self, opponent):
current_round = len(self.history) + 1
if random.randint(0, 1000) < current_round:
return D
return C
probability = 1 - float(current_round) / 1000
return random_choice(probability)


class WorseAndWorseRandom (Player):
class KnowledgeableWorseAndWorse (Player):
"""
This strategy is based of 'Worse And Worse' but will defect with probability
Copy link
Member

Choose a reason for hiding this comment

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

Typo: should be 'is based on'

Copy link
Member Author

@AdamPohl AdamPohl Sep 28, 2016

Choose a reason for hiding this comment

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

Thanks, I have now made these changes

of 'current turn / total no. of turns'.

Copy link
Member

@drvinceknight drvinceknight Sep 27, 2016

Choose a reason for hiding this comment

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

This still needs a names section:

    Names:
        - Knowledgeable Worse and Worse: Original name by Adam Phol

Names:
- Knowledgeable Worse and Worse: Original name by Adam Pohl
"""

name = 'Worse and worse random'
name = 'Knowledgeable Worse and Worse'
classifier = {
'memory_depth': float('inf'),
'stochastic': True,
Expand Down
28 changes: 19 additions & 9 deletions axelrod/tests/unit/test_worse_and_worse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TestWorseAndWorse(TestPlayer):

name = "Worse and worse"
name = "Worse and Worse"
player = axelrod.WorseAndWorse
expected_classifier = {
'memory_depth': float('inf'),
Expand All @@ -25,32 +25,42 @@ def test_strategy(self):
Test that the strategy gives expected behaviour
"""

axelrod.seed(1)
axelrod.seed(8)
opponent = axelrod.Cooperator()
player = axelrod.WorseAndWorse()
match = axelrod.Match((opponent, player), turns=5)
match = axelrod.Match((opponent, player), turns=10)
self.assertEqual(match.play(), [('C', 'C'),
Copy link
Member

Choose a reason for hiding this comment

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

Once you've made the expected change, this might change but either way it would be good if you picked a seed that didn't just have WorseAndWorse cooperate (ie choose one that gives a mix of C and D). Change the strategy first though.

('C', 'C'),
('C', 'C'),
('C', 'C'),
('C', 'C'),
('C', 'C'),
('C', 'D'),
('C', 'C'),
('C', 'C'),
('C', 'C')])

# Test that behaviour does not depend on opponent
opponent = axelrod.Defector()
player = axelrod.WorseAndWorse()
axelrod.seed(1)
match = axelrod.Match((opponent, player), turns=5)
axelrod.seed(8)
match = axelrod.Match((opponent, player), turns=10)
self.assertEqual(match.play(), [('D', 'C'),
('D', 'C'),
('D', 'C'),
('D', 'C'),
('D', 'C'),
('D', 'C'),
('D', 'D'),
('D', 'C'),
('D', 'C'),
('D', 'C')])


class TestWorseAndWorseRandom(TestPlayer):

name = "Worse and worse random"
player = axelrod.WorseAndWorseRandom
name = "Knowledgeable Worse and Worse"
player = axelrod.KnowledgeableWorseAndWorse
expected_classifier = {
'memory_depth': float('inf'),
'stochastic': True,
Expand All @@ -67,7 +77,7 @@ def test_strategy(self):
"""
axelrod.seed(1)
opponent = axelrod.Cooperator()
player = axelrod.WorseAndWorseRandom()
player = axelrod.KnowledgeableWorseAndWorse()
match = axelrod.Match((opponent, player), turns=5)
self.assertEqual(match.play(), [('C', 'C'),
('C', 'D'),
Expand All @@ -77,7 +87,7 @@ def test_strategy(self):

# Test that behaviour does not depend on opponent
opponent = axelrod.Defector()
player = axelrod.WorseAndWorseRandom()
player = axelrod.KnowledgeableWorseAndWorse()
axelrod.seed(1)
match = axelrod.Match((opponent, player), turns=5)
self.assertEqual(match.play(), [('D', 'C'),
Expand Down