-
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
New Strategy From the PRISON (http://www.lifl.fr/IPD/ipd.frame.html) #724
Changes from 1 commit
45368a7
5b6ebfb
593ae56
e0a4fda
384d49c
9c397ab
008656c
bf9e9b9
0209f71
53f68e8
4ec2ba9
4bc708d
3ddaa0e
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,5 +1,3 @@ | ||
import random | ||
|
||
from axelrod import Actions, Player, random_choice | ||
|
||
C, D = Actions.C, Actions.D | ||
|
@@ -10,11 +8,12 @@ class WorseAndWorse (Player): | |
it is more and more likely to defect as the round goes on. | ||
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 add:
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. Would this line go at the end of line 10 or do you want it as part of the names section? 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. In between line 10 and the names section. So:
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. 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]. | ||
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. Does this indent render ok? (you can run I think the rst syntax should be:
|
||
|
||
""" | ||
|
||
name = 'Worse and worse' | ||
name = 'Worse and Worse' | ||
classifier = { | ||
'memory_depth': float('inf'), | ||
'stochastic': True, | ||
|
@@ -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 | ||
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. Typo: should be 'is based on' 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. Thanks, I have now made these changes |
||
of 'current turn / total no. of turns'. | ||
|
||
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. This still needs a names section:
|
||
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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
class TestWorseAndWorse(TestPlayer): | ||
|
||
name = "Worse and worse" | ||
name = "Worse and Worse" | ||
player = axelrod.WorseAndWorse | ||
expected_classifier = { | ||
'memory_depth': float('inf'), | ||
|
@@ -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'), | ||
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. 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 |
||
('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, | ||
|
@@ -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'), | ||
|
@@ -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'), | ||
|
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.
Can you put this in alphabetical order please.
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.
Done