Skip to content

Commit 53f68e8

Browse files
committed
Have made the changes that @drvinceknight suggested.
1 parent 0209f71 commit 53f68e8

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat,
6060
SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats,
6161
OmegaTFT, Gradual, ContriteTitForTat, SlowTitForTwoTats, AdaptiveTitForTat)
62-
from .worse_and_worse import (WorseAndWorse, WorseAndWorseRandom)
62+
from .worse_and_worse import (WorseAndWorse, KnowledgeableWorseAndWorse)
6363

6464
# Note: Meta* strategies are handled in .__init__.py
6565

@@ -196,7 +196,7 @@
196196
WinShiftLoseStay,
197197
WinStayLoseShift,
198198
WorseAndWorse,
199-
WorseAndWorseRandom,
199+
KnowledgeableWorseAndWorse,
200200
ZDExtort2,
201201
ZDExtort2v2,
202202
ZDExtort4,

axelrod/strategies/worse_and_worse.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import random
2-
31
from axelrod import Actions, Player, random_choice
42

53
C, D = Actions.C, Actions.D
@@ -10,11 +8,12 @@ class WorseAndWorse (Player):
108
it is more and more likely to defect as the round goes on.
119
1210
Names:
13-
- worse_and_worse: [PRISON1998]
11+
- worse_and_worse: Source code available at the download tab of
12+
[PRISON1998].
1413
1514
"""
1615

17-
name = 'Worse and worse'
16+
name = 'Worse and Worse'
1817
classifier = {
1918
'memory_depth': float('inf'),
2019
'stochastic': True,
@@ -27,19 +26,20 @@ class WorseAndWorse (Player):
2726

2827
def strategy(self, opponent):
2928
current_round = len(self.history) + 1
30-
if random.randint(0, 1000) < current_round:
31-
return D
32-
return C
29+
probability = 1 - float(current_round) / 1000
30+
return random_choice(probability)
3331

3432

35-
class WorseAndWorseRandom (Player):
33+
class KnowledgeableWorseAndWorse (Player):
3634
"""
3735
This strategy is based of 'Worse And Worse' but will defect with probability
3836
of 'current turn / total no. of turns'.
3937
38+
Names:
39+
- Knowledgeable Worse and Worse: Original name by Adam Pohl
4040
"""
4141

42-
name = 'Worse and worse random'
42+
name = 'Knowledgeable Worse and Worse'
4343
classifier = {
4444
'memory_depth': float('inf'),
4545
'stochastic': True,

axelrod/tests/unit/test_worse_and_worse.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class TestWorseAndWorse(TestPlayer):
1010

11-
name = "Worse and worse"
11+
name = "Worse and Worse"
1212
player = axelrod.WorseAndWorse
1313
expected_classifier = {
1414
'memory_depth': float('inf'),
@@ -25,32 +25,42 @@ def test_strategy(self):
2525
Test that the strategy gives expected behaviour
2626
"""
2727

28-
axelrod.seed(1)
28+
axelrod.seed(8)
2929
opponent = axelrod.Cooperator()
3030
player = axelrod.WorseAndWorse()
31-
match = axelrod.Match((opponent, player), turns=5)
31+
match = axelrod.Match((opponent, player), turns=10)
3232
self.assertEqual(match.play(), [('C', 'C'),
3333
('C', 'C'),
3434
('C', 'C'),
3535
('C', 'C'),
36+
('C', 'C'),
37+
('C', 'C'),
38+
('C', 'D'),
39+
('C', 'C'),
40+
('C', 'C'),
3641
('C', 'C')])
3742

3843
# Test that behaviour does not depend on opponent
3944
opponent = axelrod.Defector()
4045
player = axelrod.WorseAndWorse()
41-
axelrod.seed(1)
42-
match = axelrod.Match((opponent, player), turns=5)
46+
axelrod.seed(8)
47+
match = axelrod.Match((opponent, player), turns=10)
4348
self.assertEqual(match.play(), [('D', 'C'),
4449
('D', 'C'),
4550
('D', 'C'),
4651
('D', 'C'),
52+
('D', 'C'),
53+
('D', 'C'),
54+
('D', 'D'),
55+
('D', 'C'),
56+
('D', 'C'),
4757
('D', 'C')])
4858

4959

5060
class TestWorseAndWorseRandom(TestPlayer):
5161

52-
name = "Worse and worse random"
53-
player = axelrod.WorseAndWorseRandom
62+
name = "Knowledgeable Worse and Worse"
63+
player = axelrod.KnowledgeableWorseAndWorse
5464
expected_classifier = {
5565
'memory_depth': float('inf'),
5666
'stochastic': True,
@@ -67,7 +77,7 @@ def test_strategy(self):
6777
"""
6878
axelrod.seed(1)
6979
opponent = axelrod.Cooperator()
70-
player = axelrod.WorseAndWorseRandom()
80+
player = axelrod.KnowledgeableWorseAndWorse()
7181
match = axelrod.Match((opponent, player), turns=5)
7282
self.assertEqual(match.play(), [('C', 'C'),
7383
('C', 'D'),
@@ -77,7 +87,7 @@ def test_strategy(self):
7787

7888
# Test that behaviour does not depend on opponent
7989
opponent = axelrod.Defector()
80-
player = axelrod.WorseAndWorseRandom()
90+
player = axelrod.KnowledgeableWorseAndWorse()
8191
axelrod.seed(1)
8292
match = axelrod.Match((opponent, player), turns=5)
8393
self.assertEqual(match.play(), [('D', 'C'),

0 commit comments

Comments
 (0)