-
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 12 commits
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from axelrod import Actions, Player, random_choice | ||
|
||
C, D = Actions.C, Actions.D | ||
|
||
class WorseAndWorse (Player): | ||
""" | ||
Defects with probability of 'current turn / 1000'. Therefore | ||
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. |
||
|
||
Source code available at the download tab of [PRISON1998]_ | ||
|
||
|
||
Names: | ||
- Worse and Worse: [PRISON1998]_ | ||
|
||
""" | ||
|
||
name = 'Worse and Worse' | ||
classifier = { | ||
'memory_depth': float('inf'), | ||
'stochastic': True, | ||
'makes_use_of': set(), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def strategy(self, opponent): | ||
current_round = len(self.history) + 1 | ||
probability = 1 - float(current_round) / 1000 | ||
return random_choice(probability) | ||
|
||
|
||
class KnowledgeableWorseAndWorse (Player): | ||
""" | ||
This strategy is based on 'Worse And Worse' but will defect with probability | ||
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 = 'Knowledgeable Worse and Worse' | ||
classifier = { | ||
'memory_depth': float('inf'), | ||
'stochastic': True, | ||
'makes_use_of': set(['length']), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def strategy(self, opponent): | ||
current_round = len(self.history) + 1 | ||
expected_length = self.match_attributes['length'] | ||
probability = 1 - float(current_round) / expected_length | ||
return random_choice(probability) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
"""Test for the Worse and Worse strategies.""" | ||
|
||
import axelrod | ||
|
||
from .test_player import TestPlayer | ||
|
||
C, D = axelrod.Actions.C, axelrod.Actions.D | ||
|
||
class TestWorseAndWorse(TestPlayer): | ||
|
||
name = "Worse and Worse" | ||
player = axelrod.WorseAndWorse | ||
expected_classifier = { | ||
'memory_depth': float('inf'), | ||
'stochastic': True, | ||
'makes_use_of': set(), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def test_strategy(self): | ||
""" | ||
Test that the strategy gives expected behaviour | ||
""" | ||
|
||
axelrod.seed(8) | ||
opponent = axelrod.Cooperator() | ||
player = axelrod.WorseAndWorse() | ||
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(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 = "Knowledgeable Worse and Worse" | ||
player = axelrod.KnowledgeableWorseAndWorse | ||
expected_classifier = { | ||
'memory_depth': float('inf'), | ||
'stochastic': True, | ||
'makes_use_of': set(['length']), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def test_strategy(self): | ||
""" | ||
Test that the strategy gives expected behaviour | ||
""" | ||
axelrod.seed(1) | ||
opponent = axelrod.Cooperator() | ||
player = axelrod.KnowledgeableWorseAndWorse() | ||
match = axelrod.Match((opponent, player), turns=5) | ||
self.assertEqual(match.play(), [('C', 'C'), | ||
('C', 'D'), | ||
('C', 'D'), | ||
('C', 'D'), | ||
('C', 'D')]) | ||
|
||
# Test that behaviour does not depend on opponent | ||
opponent = axelrod.Defector() | ||
player = axelrod.KnowledgeableWorseAndWorse() | ||
axelrod.seed(1) | ||
match = axelrod.Match((opponent, player), turns=5) | ||
self.assertEqual(match.play(), [('D', 'C'), | ||
('D', 'D'), | ||
('D', 'D'), | ||
('D', 'D'), | ||
('D', 'D')]) | ||
|
||
# Test that behaviour changes when does not know length. | ||
axelrod.seed(1) | ||
match = axelrod.Match((opponent, player), turns=5, | ||
match_attributes={'length': float('inf')}) | ||
self.assertEqual(match.play(), [('D', 'C'), | ||
('D', 'C'), | ||
('D', 'C'), | ||
('D', 'C'), | ||
('D', 'C')]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,9 @@ Here are the docstrings of all the strategies in the library. | |
.. automodule:: axelrod.strategies.gobymajority | ||
:members: | ||
:undoc-members: | ||
.. automodule:: axelrod.strategies.gradualkiller | ||
:members: | ||
:undoc-members: | ||
.. automodule:: axelrod.strategies.grudger | ||
:members: | ||
:undoc-members: | ||
|
@@ -120,6 +123,6 @@ Here are the docstrings of all the strategies in the library. | |
.. automodule:: axelrod.strategies.titfortat | ||
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. Do not delete 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. I didn't, if you look further up you will see that I moved it so that the list was in alphabetical order again. 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. Ah great: my mistake :) 👍 |
||
:members: | ||
:undoc-members: | ||
.. automodule:: axelrod.strategies.gradualkiller | ||
.. automodule:: axelrod.strategies.worse_and_worse | ||
:members: | ||
:undoc-members: | ||
:undoc-members: |
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