Skip to content

Commit 92b5125

Browse files
committed
Revert basic_strategies to a basic list
1 parent 4cb4182 commit 92b5125

File tree

5 files changed

+14
-41
lines changed

5 files changed

+14
-41
lines changed

axelrod/player.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@
88

99
# Strategy classifiers
1010

11-
def is_basic(s):
12-
"""
13-
Defines criteria for a strategy to be considered 'basic'
14-
"""
15-
stochastic = s.classifier['stochastic']
16-
depth = s.classifier['memory_depth']
17-
inspects_source = s.classifier['inspects_source']
18-
manipulates_source = s.classifier['manipulates_source']
19-
manipulates_state = s.classifier['manipulates_state']
20-
return (not stochastic) and (not inspects_source) and (not manipulates_source) and (not manipulates_state) and (depth in (0, 1))
21-
2211
def is_cheater(s):
2312
"""
2413
A function to check if a strategy cheats.

axelrod/strategies/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..player import is_basic, is_cheater
1+
from ..player import is_cheater
22
from ._strategies import *
33

44
# `from ._strategies import *` import the collection `strategies`
@@ -11,6 +11,8 @@
1111
# Distinguished strategy collections in addition to
1212
# `strategies` from _strategies.py
1313

14-
basic_strategies = [s for s in strategies if is_basic(s())]
1514
ordinary_strategies = [s for s in strategies if not is_cheater(s())]
1615
cheating_strategies = [s for s in strategies if is_cheater(s())]
16+
17+
# Defined by fiat for demo purposes
18+
basic_strategies = [Alternator, Cooperator, Defector, Random, TitForTat]

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats)
4242

4343

44-
# Note: Meta* strategies are handled in .__init__.py
44+
# Note: Meta* strategies are handled in .__init__.py, so this is not the
45+
# final form of the list
4546

4647
strategies = [
4748
Aggravater,

axelrod/tests/unit/test_classification.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ def test_is_cheater(self):
6262
axelrod.MindWarper,
6363
axelrod.MindReader]
6464

65-
known_basic = [axelrod.Alternator,
66-
axelrod.AntiTitForTat,
67-
axelrod.Bully,
68-
axelrod.Cooperator,
69-
axelrod.Defector,
70-
axelrod.GoByMajority,
71-
axelrod.SuspiciousTitForTat,
72-
axelrod.TitForTat,
73-
axelrod.WinStayLoseShift]
74-
7565
known_ordinary = [axelrod.AverageCopier,
7666
axelrod.ForgivingTitForTat,
7767
axelrod.GoByMajority20,
@@ -82,14 +72,8 @@ def test_is_cheater(self):
8272

8373
for strategy in known_cheaters:
8474
self.assertTrue(axelrod.is_cheater(strategy()), msg=strategy)
85-
self.assertFalse(axelrod.is_basic(strategy()), msg=strategy)
86-
87-
for strategy in known_basic:
88-
self.assertTrue(axelrod.is_basic(strategy()), msg=strategy)
89-
self.assertFalse(axelrod.is_cheater(strategy()), msg=strategy)
9075

9176
for strategy in known_ordinary:
92-
self.assertFalse(axelrod.is_basic(strategy()), msg=strategy)
9377
self.assertFalse(axelrod.is_cheater(strategy()), msg=strategy)
9478

9579

docs/usage.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ We can list the so called 'basic strategies' by doing the following::
5252
which gives::
5353

5454
Alternator
55-
Anti Tit For Tat
56-
Bully
5755
Cooperator
5856
Defector
59-
Soft Go By Majority
60-
Suspicious Tit For Tat
57+
Random: 0.5
6158
Tit For Tat
62-
Win-Stay Lose-Shift
6359

6460
Before creating a tournament let us add another :code:`Defector` to our strategies::
6561

@@ -75,7 +71,7 @@ To view the player types in our tournament::
7571

7672
which gives::
7773

78-
[Alternator, Anti Tit For Tat, Bully, Cooperator, Defector, Soft Go By Majority, Suspicious Tit For Tat, Tit For Tat, Win-Stay Lose-Shift, Defector]
74+
[Alternator, Cooperator, Defector, Random: 0.5, Tit For Tat, Defector]
7975

8076
Now to run the tournament and save the results::
8177

@@ -88,7 +84,7 @@ First, let us view the scores::
8884

8985
which gives::
9086

91-
[[2.25, 2.25, 2.25, 2.25, 2.25, 2.25, 2.25, 2.25, 2.25, 2.25], [1.8722222222222222, 1.8722222222222222, 1.8722222222222222, 1.8722222222222222, 1.8722222222222222, 1.8722222222222222, 1.8722222222222222, 1.8722222222222222, 1.8722222222222222, 1.8722222222222222], [2.428888888888889, 2.428888888888889, 2.428888888888889, 2.428888888888889, 2.428888888888889, 2.428888888888889, 2.428888888888889, 2.428888888888889, 2.428888888888889, 2.428888888888889], [1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5], [2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78], [2.181111111111111, 2.181111111111111, 2.181111111111111, 2.181111111111111, 2.181111111111111, 2.181111111111111, 2.181111111111111, 2.181111111111111, 2.181111111111111, 2.181111111111111], [2.1127777777777776, 2.1127777777777776, 2.1127777777777776, 2.1127777777777776, 2.1127777777777776, 2.1127777777777776, 2.1127777777777776, 2.1127777777777776, 2.1127777777777776, 2.1127777777777776], [2.2755555555555556, 2.2755555555555556, 2.2755555555555556, 2.2755555555555556, 2.2755555555555556, 2.2755555555555556, 2.2755555555555556, 2.2755555555555556, 2.2755555555555556, 2.2755555555555556], [1.8794444444444445, 1.8794444444444445, 1.8794444444444445, 1.8794444444444445, 1.8794444444444445, 1.8794444444444445, 1.8794444444444445, 1.8794444444444445, 1.8794444444444445, 1.8794444444444445], [2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78, 2.78]]
87+
[[1.94, 1.927, 1.929, 1.962, 1.961, 1.977, 1.907, 1.948, 1.954, 1.967], [1.2, 1.146, 1.194, 1.215, 1.188, 1.191, 1.203, 1.2, 1.191, 1.179], [2.588, 2.588, 2.608, 2.624, 2.632, 2.596, 2.62, 2.592, 2.612, 2.572], [1.889, 1.976, 1.91, 1.888, 1.899, 1.893, 1.919, 1.926, 1.921, 1.912], [1.927, 1.95, 1.943, 1.944, 1.941, 1.943, 1.942, 1.942, 1.957, 1.951], [2.636, 2.532, 2.628, 2.58, 2.604, 2.648, 2.584, 2.556, 2.584, 2.62]]
9288

9389

9490
We see here that when we ran :code:`tournament.play()` it automatically repeated the round robin tournament 10 times (this is to deal with the stochasticity of the random players).
@@ -100,15 +96,16 @@ To view a ranking based on median score::
10096

10197
which gives::
10298

103-
[4, 9, 2, 7, 0, 5, 6, 8, 1, 3]
99+
[2, 5, 0, 4, 3, 1]
104100

105101
Finally, to obtain the ranking in a helpful format with all the names::
106102

107103
results.ranked_names
108104

109105
which gives::
110106

111-
['Defector', 'Defector', 'Bully', 'Tit For Tat', 'Alternator', 'Soft Go By Majority', 'Suspicious Tit For Tat', 'Win-Stay Lose-Shift', 'Anti Tit For Tat', 'Cooperator']
107+
['Defector', 'Defector', 'Alternator', 'Tit For Tat', 'Random: 0.5', 'Cooperator']
108+
112109

113110
So in this particular instance our two defectors have won.
114111
Let us write a little script that will throw in a new :code:`TitForTat` player until the Tit-For-Tat player wins::
@@ -124,7 +121,7 @@ Once that has run let us see how many :code:`TitForTat` players were required::
124121

125122
which gives::
126123

127-
4
124+
3
128125

129126
We can wrap all this in a function and use it to see how many :code:`TitForTat` are needed to overcome a varying number :code:`Defector`::
130127

@@ -153,7 +150,7 @@ By viewing :code:`t` we actually see that even with 50 :code:`Defector` 3 :code:
153150

154151
gives::
155152

156-
4
153+
3
157154

158155
So even with a large quantity of :code:`Defector` only a small number of
159156
:code:`TitForTat` strategies is required.

0 commit comments

Comments
 (0)