Skip to content

Commit 292a70e

Browse files
drvinceknightmarcharper
authored andcommitted
Add sufficient rounds to test strategies.
1 parent a58604c commit 292a70e

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

axelrod/strategies/resurrection.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66

77
class Resurrection(Player):
88
"""
9-
A player starts by cooperating and defects if the number of rounds
10-
played by the player is greater than five and the last five rounds are defections.
9+
A player starts by cooperating and defects if the number of rounds
10+
played by the player is greater than five and the last five rounds
11+
are defections.
12+
1113
Otherwise, the strategy plays like Tit-for-tat.
12-
14+
1315
Names:
14-
- Resurrection: Name from CoopSim https://github.com/jecki/CoopSim
16+
- Resurrection: Name from CoopSim https://github.com/jecki/CoopSim
1517
"""
1618

1719
# These are various properties for the strategy
1820
name = 'Resurrection'
1921
classifier = {
20-
'memory_depth': 1,
22+
'memory_depth': 5,
2123
'stochastic': False,
2224
'makes_use_of': set(),
2325
'long_run_time': False,
@@ -33,20 +35,22 @@ def strategy(self, opponent: Player) -> Action:
3335
return D
3436
else:
3537
return opponent.history[-1]
36-
38+
3739
class DoubleResurrection(Player):
3840
"""
39-
A player starts by cooperating and defects if the number of rounds
40-
played by the player is greater than five and the last five rounds are cooperations.
41+
A player starts by cooperating and defects if the number of rounds
42+
played by the player is greater than five and the last five rounds
43+
are cooperations.
44+
4145
If the last five rounds were defections, the player cooperates.
42-
46+
4347
Names:
44-
- DoubleResurrection: Name from CoopSim https://github.com/jecki/CoopSim
48+
- DoubleResurrection: Name from CoopSim https://github.com/jecki/CoopSim
4549
"""
4650

4751
name = 'DoubleResurrection'
4852
classifier = {
49-
'memory_depth': 1,
53+
'memory_depth': 5,
5054
'stochastic': False,
5155
'makes_use_of': set(),
5256
'long_run_time': False,

axelrod/tests/strategies/test_resurrection.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Resurrection(TestPlayer):
99
name = "Resurrection"
1010
player = axelrod.Resurrection
1111
expected_classifier = {
12-
'memory_depth': 1,
12+
'memory_depth': 5,
1313
'stochastic': False,
1414
'makes_use_of': set(),
1515
'long_run_time': False,
@@ -21,25 +21,24 @@ class Resurrection(TestPlayer):
2121
def test_strategy(self):
2222
# Starts by Cooperating
2323
self.first_play_test(C)
24-
25-
# Check if the turns played are greater than 5
26-
self.responses_test([D], [D, C, C, D, D, D, D, D] , [C] * 8)
27-
28-
#Check if turns played are less than 5.
29-
self.responses_test([C], [D, C, D, C], [C] * 4)
30-
24+
25+
# Check if the turns played are greater than 5
26+
actions = [(C, C), (C, C), (C, C), (C, C), (C, C), (C, C), (C, C)]
27+
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
28+
29+
actions = [(C, D), (D, D), (D, D), (D, D), (D, D), (D, D), (D, D)]
30+
self.versus_test(axelrod.Defector(), expected_actions=actions)
31+
3132
# Check for TFT behavior after 5 rounds
32-
self.responses_test([C], [C] * 5, [C, C, C, C, C, D])
33-
34-
# Check for four defections and a cooperation by opponent
35-
self.responses_test([D], [C] * 5, [D, D, D, D, D, C])
36-
33+
actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (C, D), (D, C)]
34+
self.versus_test(axelrod.Alternator(), expected_actions=actions)
35+
3736
class TestDoubleResurrection(TestPlayer):
3837

3938
name = "DoubleResurrection"
4039
player = axelrod.DoubleResurrection
4140
expected_classifier = {
42-
'memory_depth': 1,
41+
'memory_depth': 5,
4342
'stochastic': False,
4443
'makes_use_of': set(),
4544
'long_run_time': False,
@@ -51,12 +50,12 @@ class TestDoubleResurrection(TestPlayer):
5150
def test_strategy(self):
5251
# Starts by Cooperating
5352
self.first_play_test(C)
54-
55-
actions = [(C, C), (C, D), (D, C), (C, D), (D, C)]
53+
54+
actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (C, D)]
5655
self.versus_test(axelrod.Alternator(), expected_actions=actions)
5756

58-
actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
57+
actions = [(C, C), (C, C), (C, C), (C, C), (C, C), (D, C)]
5958
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
6059

61-
actions = [(C, D), (D, D), (D, D), (D, D), (D, D)]
60+
actions = [(C, D), (D, D), (D, D), (D, D), (D, D), (D, D), (C, D)]
6261
self.versus_test(axelrod.Defector(), expected_actions=actions)

docs/tutorials/advanced/classification_of_strategies.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ make a decision::
5757
... }
5858
>>> strategies = axl.filtered_strategies(filterset)
5959
>>> len(strategies)
60-
28
60+
27
6161

6262
Multiple filters can be specified within the filterset dictionary. To specify a
6363
range of memory_depth values, we can use the 'min_memory_depth' and
@@ -69,7 +69,7 @@ range of memory_depth values, we can use the 'min_memory_depth' and
6969
... }
7070
>>> strategies = axl.filtered_strategies(filterset)
7171
>>> len(strategies)
72-
50
72+
49
7373

7474
We can also identify strategies that make use of particular properties of the
7575
tournament. For example, here is the number of strategies that make use of the

0 commit comments

Comments
 (0)