Skip to content

Commit a204a2a

Browse files
committed
Merge pull request #458 from marcharper/new_strategies
New Strategy: FirmButFair
2 parents fcf3293 + 2a882fd commit a204a2a

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

axelrod/strategies/_strategies.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
from .inverse import Inverse
2929
from .lookerup import LookerUp, EvolvedLookerUp
3030
from .mathematicalconstants import Golden, Pi, e
31-
from .memoryone import (ALLCorALLD,
32-
MemoryOnePlayer, GTFT, SoftJoss, StochasticCooperator, StochasticWSLS,
33-
ZDExtort2, ZDExtort2v2, ZDExtort4, ZDGen2, ZDGTFT2, ZDSet2, WinStayLoseShift)
31+
from .memoryone import (
32+
MemoryOnePlayer, ALLCorALLD, FirmButFair, GTFT, SoftJoss,
33+
StochasticCooperator, StochasticWSLS, ZDExtort2, ZDExtort2v2, ZDExtort4,
34+
ZDGen2, ZDGTFT2, ZDSet2, WinStayLoseShift)
3435
from .mindcontrol import MindController, MindWarper, MindBender
3536
from .mindreader import MindReader, ProtectedMindReader, MirrorMindReader
3637
from .oncebitten import OnceBitten, FoolMeOnce, ForgetfulFoolMeOnce, FoolMeForever
@@ -80,6 +81,7 @@
8081
Eatherley,
8182
EventualCycleHunter,
8283
Feld,
84+
FirmButFair,
8385
FoolMeForever,
8486
FoolMeOnce,
8587
ForgetfulFoolMeOnce,

axelrod/strategies/memoryone.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ def __repr__(self):
119119
return "%s: %s" % (self.name, round(self.p, 2))
120120

121121

122+
class FirmButFair(MemoryOnePlayer):
123+
"""A Classical Strategy described in this paper (and earlier):
124+
http://www.math.ubc.ca/~hauert/publications/reprints/hauert_jtb02b.pdf"""
125+
126+
name = 'Firm But Fair'
127+
128+
@init_args
129+
def __init__(self):
130+
four_vector = (1, 0, 1, 2./3)
131+
super(FirmButFair, self).__init__(four_vector)
132+
self.set_four_vector(four_vector)
133+
134+
122135
class StochasticCooperator(MemoryOnePlayer):
123136
"""Stochastic Cooperator, http://www.nature.com/ncomms/2013/130801/ncomms3193/full/ncomms3193.html."""
124137

axelrod/tests/unit/test_memoryone.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ def test_allow_for_zero_probability(self):
6161
self.assertAlmostEqual(player._four_vector, expected)
6262

6363

64+
class TestFirmButFair(TestPlayer):
65+
66+
name = "Firm But Fair"
67+
player = axelrod.FirmButFair
68+
expected_classifier = {
69+
'memory_depth': 1,
70+
'stochastic': True,
71+
'makes_use_of': set(),
72+
'inspects_source': False,
73+
'manipulates_source': False,
74+
'manipulates_state': False
75+
}
76+
77+
def test_four_vector(self):
78+
expected_dictionary = {(C, C): 1, (C, D): 0, (D, C): 1, (D, D): 2./3}
79+
test_four_vector(self, expected_dictionary)
80+
81+
def test_strategy(self):
82+
self.first_play_test(C)
83+
self.responses_test([C], [C], [C])
84+
self.responses_test([C], [D], [D])
85+
self.responses_test([D], [C], [C])
86+
self.responses_test([D], [D], [C], random_seed=1)
87+
self.responses_test([D], [D], [D], random_seed=2)
88+
6489
class TestStochasticCooperator(TestPlayer):
6590

6691
name = "Stochastic Cooperator"

docs/tutorials/further_topics/classification_of_strategies.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ This allows us to, for example, quickly identify all the stochastic
2424
strategies::
2525

2626
>>> len([s for s in axl.strategies if s().classifier['stochastic']])
27-
37
27+
38
2828

2929
Or indeed find out how many strategy only use 1 turn worth of memory to
3030
make a decision::
3131

3232
>>> len([s for s in axl.strategies if s().classifier['memory_depth']==1])
33-
17
33+
18
3434

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

test

100644100755
File mode changed.

0 commit comments

Comments
 (0)