-
Notifications
You must be signed in to change notification settings - Fork 264
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
Adding remorseful prober #633
Changes from 3 commits
287f57c
de6393e
907fd35
f5a7751
7aa6fdf
cd4bcd6
27a065e
ba1cce5
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,8 +1,7 @@ | ||
"""Tests for prober strategies.""" | ||
|
||
import random | ||
|
||
import axelrod | ||
import random | ||
|
||
from .test_player import TestPlayer, test_responses | ||
|
||
|
@@ -162,3 +161,68 @@ def test_reduction_to_TFT(self): | |
test_responses(self, player, opponent, [C], [D], [D]) | ||
test_responses(self, player, opponent, [C, D], [D, C], [C]) | ||
test_responses(self, player, opponent, [C, D], [D, D], [D]) | ||
|
||
|
||
class TestRemorsefulProber(TestPlayer): | ||
|
||
name = "Remorseful Prober: 0.1" | ||
player = axelrod.RemorsefulProber | ||
expected_classifier = { | ||
'memory_depth': 2, | ||
'stochastic': True, | ||
'makes_use_of': set(), | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def test_strategy(self): | ||
"Randomly defects (probes) and always retaliates like tit for tat." | ||
self.first_play_test(C) | ||
|
||
player = self.player(0.4) | ||
opponent = axelrod.Random() | ||
player.history = [C, C] | ||
opponent.history = [C, D] | ||
self.assertEqual(player.strategy(opponent), D) | ||
|
||
def test_random_defection(self): | ||
# Random defection | ||
player = self.player(0.4) | ||
opponent = axelrod.Random() | ||
test_responses(self, player, opponent, [C], [C], [D], random_seed=1) | ||
|
||
def test_remorse(self): | ||
"""After probing, if opponent retaliates, will offer a C""" | ||
player = self.player(0.4) | ||
opponent = axelrod.Random() | ||
|
||
random.seed(0) | ||
player.history = [C] | ||
opponent.history = [C] | ||
self.assertEqual(player.strategy(opponent), D) # Random defection | ||
self.assertEqual(player.probing, True) | ||
|
||
player.history = [C, D] | ||
opponent.history = [C, D] | ||
self.assertEqual(player.strategy(opponent), C) # Remorse | ||
self.assertEqual(player.probing, False) | ||
|
||
player.history = [C, D, C] | ||
opponent.history = [C, D, D] | ||
self.assertEqual(player.strategy(opponent), D) | ||
self.assertEqual(player.probing, False) | ||
|
||
def test_reduction_to_TFT(self): | ||
player = self.player(0) | ||
opponent = axelrod.Random() | ||
test_responses(self, player, opponent, [C], [C], [C], random_seed=1) | ||
test_responses(self, player, opponent, [C], [D], [D]) | ||
test_responses(self, player, opponent, [C, D], [D, 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. You can use e.g. 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. Yeah I tried the various helper functions but with no success and was getting frustrated as to whether I was making mistakes with the strategy or misusing the helper functions so it just felt easier to use the verbose calls... I'll have another go. It might have just been me getting myself confused. |
||
test_responses(self, player, opponent, [C, D], [D, D], [D]) | ||
|
||
def test_reset_probing(self): | ||
player = self.player(0.4) | ||
player.probing = True | ||
player.reset() | ||
self.assertFalse(player.probing) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ This allows us to, for example, quickly identify all the stochastic | |
strategies:: | ||
|
||
>>> len([s for s in axl.strategies if s().classifier['stochastic']]) | ||
40 | ||
41 | ||
|
||
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. Doesn't line 33 need to change too? 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. No, this strategy has memory depth 2 as it needs to remember if a 'probe' was punished (so that it can be remorseful). 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 yes - I was looking at the memory depth for Naive Prober by mistake 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. 👍 On Thu, Jun 16, 2016 at 1:29 PM Owen Campbell [email protected]
|
||
Or indeed find out how many strategy only use 1 turn worth of memory to | ||
make a decision:: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,13 +104,13 @@ The library includes the following transformers: | |
>>> ApologizingDefector = ApologyTransformer([D], [C])(axelrod.Defector) | ||
>>> player = ApologizingDefector() | ||
|
||
You can pass any two sequences in. In this example the player would apologize | ||
after two consequtive rounds of `(D, C)`:: | ||
You can pass any two sequences in. In this example the player would apologize | ||
after two consequtive rounds of `(D, C)`:: | ||
|
||
>>> import axelrod | ||
>>> from axelrod.strategy_transformers import ApologyTransformer | ||
>>> ApologizingDefector = ApologyTransformer([D, D], [C, C])(axelrod.Defector) | ||
>>> player = ApologizingDefector() | ||
>>> import axelrod | ||
>>> from axelrod.strategy_transformers import ApologyTransformer | ||
>>> ApologizingDefector = ApologyTransformer([D, D], [C, C])(axelrod.Defector) | ||
>>> player = ApologizingDefector() | ||
|
||
* :code:`DeadlockBreakingTransformer`: Attempts to break :code:`(D, C) -> (C, D)` deadlocks by cooperating:: | ||
|
||
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. Is this supposed to be here? It doesn't appear to be related to the new strategy. 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 added this to this PR just to fix the indentation for the docs. It's unrelated. |
||
|
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.
That url can be shortened to just https://books.google.co.uk/books?id=ekonDAAAQBAJ
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.
Good shout, I'll give this a general clean up now :)