Skip to content

Commit 8c10690

Browse files
committed
More tests for mutual, mark as stochastic
1 parent 951da6e commit 8c10690

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

axelrod/strategies/mutual.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
C, D = Actions.C, Actions.D
55

6+
67
class Desperate(Player):
78
"""A player that only cooperates after mutual defection"""
89
name = "Desperate"
910
classifier = {
1011
'memory_depth': 1,
11-
'stochastic': False,
12+
'stochastic': True,
1213
'makes_use_of': set(),
1314
'inspects_source': False,
1415
'manipulates_source': False,
@@ -22,12 +23,13 @@ def strategy(self, opponent):
2223
return C
2324
return D
2425

26+
2527
class Hopeless(Player):
2628
"""A player that only defects after mutual cooperation"""
2729
name = "Hopeless"
2830
classifier = {
2931
'memory_depth': 1,
30-
'stochastic': False,
32+
'stochastic': True,
3133
'makes_use_of': set(),
3234
'inspects_source': False,
3335
'manipulates_source': False,
@@ -41,12 +43,13 @@ def strategy(self, opponent):
4143
return D
4244
return C
4345

46+
4447
class Willing(Player):
4548
"""A player that only defects after mutual defection"""
4649
name = "Willing"
4750
classifier = {
4851
'memory_depth': 1,
49-
'stochastic': False,
52+
'stochastic': True,
5053
'makes_use_of': set(),
5154
'inspects_source': False,
5255
'manipulates_source': False,

axelrod/tests/unit/test_mutual.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Tests for strategies Desperate, Hopeless, Willing, and Grim"""
22
import axelrod
33

4+
from axelrod.random_ import seed
5+
46
from .test_player import TestPlayer
57

68
C, D = axelrod.Actions.C, axelrod.Actions.D
@@ -11,17 +13,19 @@ class TestDesperate(TestPlayer):
1113
player = axelrod.Desperate
1214
expected_classifier = {
1315
'memory_depth': 1,
14-
'stochastic': False,
16+
'stochastic': True,
1517
'makes_use_of': set(),
1618
'inspects_source': False,
1719
'manipulates_source': False,
1820
'manipulates_state': False
1921
}
2022

23+
def test_strategy(self):
24+
seed(1)
25+
self.first_play_test(C)
2126

2227
def test_responses(self):
23-
24-
self.responses_test([C]* 4, [D] * 4, [D])
28+
self.responses_test([C] * 4, [D] * 4, [D])
2529
self.responses_test([D, D, C], [C, C, D], [D])
2630
self.responses_test([D, D, D], [C, C, D], [C])
2731

@@ -32,16 +36,18 @@ class TestHopeless(TestPlayer):
3236
player = axelrod.Hopeless
3337
expected_classifier = {
3438
'memory_depth': 1,
35-
'stochastic': False,
39+
'stochastic': True,
3640
'makes_use_of': set(),
3741
'inspects_source': False,
3842
'manipulates_source': False,
3943
'manipulates_state': False
4044
}
4145

46+
def test_strategy(self):
47+
seed(1)
48+
self.first_play_test(C)
4249

4350
def test_responses(self):
44-
4551
self.responses_test([C] * 4, [D] * 4, [C])
4652
self.responses_test([D] * 5, [C] * 5, [C])
4753
self.responses_test([C, D, C], [C, C, C], [D])
@@ -52,16 +58,18 @@ class TestWilling(TestPlayer):
5258
player = axelrod.Willing
5359
expected_classifier = {
5460
'memory_depth': 1,
55-
'stochastic': False,
61+
'stochastic': True,
5662
'makes_use_of': set(),
5763
'inspects_source': False,
5864
'manipulates_source': False,
5965
'manipulates_state': False
6066
}
6167

68+
def test_strategy(self):
69+
seed(1)
70+
self.first_play_test(C)
6271

6372
def test_responses(self):
64-
6573
self.responses_test([C] * 4, [D] * 4, [C])
6674
self.responses_test([D] * 5, [C] * 5, [C])
6775
self.responses_test([C, C, D], [C, C, D], [D])

docs/tutorials/advanced/classification_of_strategies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This allows us to, for example, quickly identify all the stochastic
2424
strategies::
2525

2626
>>> len([s for s in axl.strategies if s().classifier['stochastic']])
27-
40
27+
43
2828

2929
Or indeed find out how many strategy only use 1 turn worth of memory to
3030
make a decision::

0 commit comments

Comments
 (0)