Skip to content

Commit a6471e8

Browse files
committed
Rename SecondByDowning -> RevisedDowning.
I have moved this to it's own module/file.
1 parent e7cf5ad commit a6471e8

File tree

5 files changed

+117
-104
lines changed

5 files changed

+117
-104
lines changed

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
SecondByCave,
2727
SecondByChampion,
2828
SecondByColbert,
29-
SecondByDowning,
3029
SecondByEatherley,
3130
SecondByGetzler,
3231
SecondByGladstein,
@@ -190,6 +189,7 @@
190189
Retaliate2,
191190
Retaliate3,
192191
)
192+
from .revised_downing import RevisedDowning
193193
from .selfsteem import SelfSteem
194194
from .sequence_player import SequencePlayer, ThueMorse, ThueMorseInverse
195195
from .shortmem import ShortMem
@@ -367,7 +367,7 @@
367367
MindReader,
368368
MindWarper,
369369
MirrorMindReader,
370-
SecondByDowning,
370+
RevisedDowning,
371371
SecondByGrofman,
372372
SecondByTidemanAndChieruzzi,
373373
Negation,

axelrod/strategies/axelrod_second.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -61,72 +61,6 @@ def strategy(self, opponent: Player) -> Action:
6161
return D
6262
return C
6363

64-
class SecondByDowning(Player):
65-
"""
66-
Strategy submitted to Axelrod's second tournament by Leslie Downing.
67-
(K59R).
68-
69-
Revised Downing attempts to determine if players are cooperative or not.
70-
If so, it cooperates with them.
71-
72-
This strategy is a revision of the strategy submitted by Downing to
73-
Axelrod's first tournament.
74-
75-
76-
Names:
77-
- Revised Downing: [Axelrod1980]_
78-
"""
79-
80-
name = "Second by Downing"
81-
82-
classifier = {
83-
"memory_depth": float("inf"),
84-
"stochastic": False,
85-
"makes_use_of": set(),
86-
"long_run_time": False,
87-
"inspects_source": False,
88-
"manipulates_source": False,
89-
"manipulates_state": False,
90-
}
91-
92-
def __init__(self) -> None:
93-
super().__init__()
94-
self.good = 1.0
95-
self.bad = 0.0
96-
self.nice1 = 0
97-
self.nice2 = 0
98-
self.total_C = 0 # note the same as self.cooperations
99-
self.total_D = 0 # note the same as self.defections
100-
101-
def strategy(self, opponent: Player) -> Action:
102-
round_number = len(self.history) + 1
103-
104-
if round_number == 1:
105-
return C
106-
107-
# Update various counts
108-
if round_number > 2:
109-
if self.history[-1] == D:
110-
if opponent.history[-1] == C:
111-
self.nice2 += 1
112-
self.total_D += 1
113-
self.bad = self.nice2 / self.total_D
114-
else:
115-
if opponent.history[-1] == C:
116-
self.nice1 += 1
117-
self.total_C += 1
118-
self.good = self.nice1 / self.total_C
119-
# Make a decision based on the accrued counts
120-
c = 6.0 * self.good - 8.0 * self.bad - 2
121-
alt = 4.0 * self.good - 5.0 * self.bad - 1
122-
if c >= 0 and c >= alt:
123-
move = C
124-
elif (c >= 0 and c < alt) or (alt >= 0):
125-
move = self.history[-1].flip()
126-
else:
127-
move = D
128-
return move
129-
13064
class SecondByEatherley(Player):
13165
"""
13266
Strategy submitted to Axelrod's second tournament by Graham Eatherley.

axelrod/strategies/revised_downing.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
Revised Downing implemented from the Fortran source code for the second of
3+
Axelrod's tournaments.
4+
"""
5+
from axelrod.action import Action
6+
from axelrod.player import Player
7+
8+
C, D = Action.C, Action.D
9+
10+
class RevisedDowning(Player):
11+
"""
12+
Strategy submitted to Axelrod's second tournament by Leslie Downing.
13+
(K59R).
14+
15+
Revised Downing attempts to determine if players are cooperative or not.
16+
If so, it cooperates with them.
17+
18+
This strategy is a revision of the strategy submitted by Downing to
19+
Axelrod's first tournament.
20+
21+
22+
Names:
23+
- Revised Downing: [Axelrod1980]_
24+
"""
25+
26+
name = "Revised Downing"
27+
28+
classifier = {
29+
"memory_depth": float("inf"),
30+
"stochastic": False,
31+
"makes_use_of": set(),
32+
"long_run_time": False,
33+
"inspects_source": False,
34+
"manipulates_source": False,
35+
"manipulates_state": False,
36+
}
37+
38+
def __init__(self) -> None:
39+
super().__init__()
40+
self.good = 1.0
41+
self.bad = 0.0
42+
self.nice1 = 0
43+
self.nice2 = 0
44+
self.total_C = 0 # note the same as self.cooperations
45+
self.total_D = 0 # note the same as self.defections
46+
47+
def strategy(self, opponent: Player) -> Action:
48+
round_number = len(self.history) + 1
49+
50+
if round_number == 1:
51+
return C
52+
53+
# Update various counts
54+
if round_number > 2:
55+
if self.history[-1] == D:
56+
if opponent.history[-1] == C:
57+
self.nice2 += 1
58+
self.total_D += 1
59+
self.bad = self.nice2 / self.total_D
60+
else:
61+
if opponent.history[-1] == C:
62+
self.nice1 += 1
63+
self.total_C += 1
64+
self.good = self.nice1 / self.total_C
65+
# Make a decision based on the accrued counts
66+
c = 6.0 * self.good - 8.0 * self.bad - 2
67+
alt = 4.0 * self.good - 5.0 * self.bad - 1
68+
if c >= 0 and c >= alt:
69+
move = C
70+
elif (c >= 0 and c < alt) or (alt >= 0):
71+
move = self.history[-1].flip()
72+
else:
73+
move = D
74+
return move
75+

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,39 +2032,3 @@ def test_strategy(self):
20322032
self.versus_test(axelrod.Random(0.5), expected_actions=actions, seed=7)
20332033

20342034

2035-
class TestSeconodByDowning(TestPlayer):
2036-
2037-
name = "Second by Downing"
2038-
player = axelrod.SecondByDowning
2039-
expected_classifier = {
2040-
"memory_depth": float("inf"),
2041-
"stochastic": False,
2042-
"makes_use_of": set(),
2043-
"long_run_time": False,
2044-
"inspects_source": False,
2045-
"manipulates_source": False,
2046-
"manipulates_state": False,
2047-
}
2048-
2049-
def test_strategy(self):
2050-
actions = [(C, C), (C, C), (C, C)]
2051-
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
2052-
2053-
actions = [(C, D), (C, D), (D, D)]
2054-
self.versus_test(axelrod.Defector(), expected_actions=actions)
2055-
2056-
opponent = axelrod.MockPlayer(actions=[D, C, C])
2057-
actions = [(C, D), (C, C), (C, C), (C, D)]
2058-
self.versus_test(opponent, expected_actions=actions)
2059-
2060-
opponent = axelrod.MockPlayer(actions=[D, D, C])
2061-
actions = [(C, D), (C, D), (D, C), (D, D)]
2062-
self.versus_test(opponent, expected_actions=actions)
2063-
2064-
opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, C])
2065-
actions = [(C, C), (C, C), (C, D), (C, D), (D, C), (D, C), (D, C)]
2066-
self.versus_test(opponent, expected_actions=actions)
2067-
2068-
opponent = axelrod.MockPlayer(actions=[C, C, C, C, D, D])
2069-
actions = [(C, C), (C, C), (C, C), (C, C), (C, D), (C, D), (C, C)]
2070-
self.versus_test(opponent, expected_actions=actions)

axelrod/tests/test_revised_downing.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from .test_player import TestPlayer
2+
3+
C, D = axelrod.Action.C, axelrod.Action.D
4+
5+
class TestRevisedDowning(TestPlayer):
6+
7+
name = "Revised Downing"
8+
player = axelrod.RevisedDowning
9+
expected_classifier = {
10+
"memory_depth": float("inf"),
11+
"stochastic": False,
12+
"makes_use_of": set(),
13+
"long_run_time": False,
14+
"inspects_source": False,
15+
"manipulates_source": False,
16+
"manipulates_state": False,
17+
}
18+
19+
def test_strategy(self):
20+
actions = [(C, C), (C, C), (C, C)]
21+
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
22+
23+
actions = [(C, D), (C, D), (D, D)]
24+
self.versus_test(axelrod.Defector(), expected_actions=actions)
25+
26+
opponent = axelrod.MockPlayer(actions=[D, C, C])
27+
actions = [(C, D), (C, C), (C, C), (C, D)]
28+
self.versus_test(opponent, expected_actions=actions)
29+
30+
opponent = axelrod.MockPlayer(actions=[D, D, C])
31+
actions = [(C, D), (C, D), (D, C), (D, D)]
32+
self.versus_test(opponent, expected_actions=actions)
33+
34+
opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, C])
35+
actions = [(C, C), (C, C), (C, D), (C, D), (D, C), (D, C), (D, C)]
36+
self.versus_test(opponent, expected_actions=actions)
37+
38+
opponent = axelrod.MockPlayer(actions=[C, C, C, C, D, D])
39+
actions = [(C, C), (C, C), (C, C), (C, C), (C, D), (C, D), (C, C)]
40+
self.versus_test(opponent, expected_actions=actions)

0 commit comments

Comments
 (0)