Skip to content

Commit 5b6ebfb

Browse files
committed
Adding WorseAndWorse stratergy attempt 2
1 parent 45368a7 commit 5b6ebfb

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

axelrod/strategies/worse_and_worse.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from axelrod import Actions, Player
2+
from random import randint
3+
4+
class WorseAndWorse (Player):
5+
"""
6+
Defects with probability of 'current turn / total no. of turns'. Therefore
7+
it is more and more likely to defect as the round goes on.
8+
9+
Names:
10+
- worse_and_worse: [PRISON1998]
11+
12+
"""
13+
14+
name = 'Worse and worse'
15+
classifier = {
16+
'memory_depth': float('inf'),
17+
'stochastic': True,
18+
'makes_use_of': set(['length']),
19+
'long_run_time': False,
20+
'inspects_source': False,
21+
'manipulates_source': False,
22+
'manipulates_state': False
23+
}
24+
25+
def strategy(self, opponent):
26+
current_round = len(self.history) + 1
27+
expected_length = self.match_attributes['length']
28+
try:
29+
if randint(0, expected_length) < (current_round):
30+
return Actions.D
31+
return Actions.C
32+
except:
33+
if randint(0, 200) < (current_round):
34+
return Actions.D
35+
return Actions.C
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Test for the Worse and Worse strategy."""
2+
3+
import axelrod
4+
5+
from .test_player import TestPlayer
6+
7+
C, D = axelrod.Actions.C, axelrod.Actions.D
8+
9+
10+
class TestWorseAndWorse(TestPlayer):
11+
12+
name = "Worse and worse"
13+
player = axelrod.WorseAndWorse
14+
expected_classifier = {
15+
'memory_depth': float('inf'),
16+
'stochastic': True,
17+
'makes_use_of': set(['length']),
18+
'long_run_time': False,
19+
'inspects_source': False,
20+
'manipulates_source': False,
21+
'manipulates_state': False
22+
}
23+
24+
def test_strategy(self):
25+
"""
26+
Test that the stratergy chooses to defect according to the correct
27+
probability.
28+
"""
29+
self.responses_test([], [], [C, C, D, D, D], random_seed=1,
30+
tournament_length=5)
31+
32+
self.responses_test([], [], [D, D, D, D, D], random_seed=2,
33+
tournament_length=5)

0 commit comments

Comments
 (0)