Skip to content

Commit c6923d1

Browse files
Merge pull request #1151 from gaffney2010/master
Implement Getzler, K35R from Axelrod's second.
2 parents aafb4be + 3df78f6 commit c6923d1

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .axelrod_second import (
1111
Champion, Eatherley, Tester, Gladstein, Tranquilizer, MoreGrofman,
1212
Kluepfel, Borufsen, Cave, WmAdams, GraaskampKatzen, Weiner, Harrington,
13-
MoreTidemanAndChieruzzi)
13+
MoreTidemanAndChieruzzi, Getzler)
1414
from .backstabber import BackStabber, DoubleCrosser
1515
from .better_and_better import BetterAndBetter
1616
from .bush_mosteller import BushMosteller
@@ -164,6 +164,7 @@
164164
GellerCooperator,
165165
GellerDefector,
166166
GeneralSoftGrudger,
167+
Getzler,
167168
Gladstein,
168169
GoByMajority,
169170
GoByMajority10,

axelrod/strategies/axelrod_second.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,3 +1416,41 @@ def strategy(self, opponent: Player) -> Action:
14161416
return C # First cooperation
14171417

14181418
return D
1419+
1420+
1421+
class Getzler(Player):
1422+
"""
1423+
Strategy submitted to Axelrod's second tournament by Abraham Getzler (K35R)
1424+
and came in tenth in that tournament.
1425+
1426+
Strategy Defects with probability `flack`, where `flack` is calculated as
1427+
the sum over opponent Defections of 0.5 ^ (turns ago Defection happened).
1428+
1429+
Names:
1430+
1431+
- Getzler: [Axelrod1980b]_
1432+
"""
1433+
1434+
name = 'Getzler'
1435+
classifier = {
1436+
'memory_depth': float('inf'),
1437+
'stochastic': True,
1438+
'makes_use_of': set(),
1439+
'long_run_time': False,
1440+
'inspects_source': False,
1441+
'manipulates_source': False,
1442+
'manipulates_state': False
1443+
}
1444+
1445+
def __init__(self) -> None:
1446+
super().__init__()
1447+
self.flack = 0.0 # The relative untrustworthiness of opponent
1448+
1449+
def strategy(self, opponent: Player) -> Action:
1450+
if not opponent.history:
1451+
return C
1452+
1453+
self.flack += 1 if opponent.history[-1] == D else 0
1454+
self.flack *= 0.5 # Defections have half-life of one round
1455+
1456+
return random_choice(1.0 - self.flack)

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,3 +906,27 @@ def test_strategy(self):
906906
actions += [(D, D)] # No Defection here means no Fresh Start.
907907
self.versus_test(C5D5_Player, expected_actions=actions)
908908

909+
910+
class TestGetzler(TestPlayer):
911+
name = 'Getzler'
912+
player = axelrod.Getzler
913+
expected_classifier = {
914+
'memory_depth': float('inf'),
915+
'stochastic': True,
916+
'makes_use_of': set(),
917+
'long_run_time': False,
918+
'inspects_source': False,
919+
'manipulates_source': False,
920+
'manipulates_state': False
921+
}
922+
923+
def test_strategy(self):
924+
actions = [(C, C)] * 100
925+
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
926+
927+
actions = [(C, D), (C, D), (D, D), (D, D), (D, D)]
928+
self.versus_test(axelrod.Defector(), expected_actions=actions, seed=1, attrs={"flack": 15./16.})
929+
930+
actions = [(C, C), (C, D), (C, C), (C, D), (D, C), (C, D)]
931+
self.versus_test(axelrod.Alternator(), expected_actions=actions, seed=4, attrs={"flack": 5./16.})
932+

docs/tutorials/advanced/classification_of_strategies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ strategies::
4747
... }
4848
>>> strategies = axl.filtered_strategies(filterset)
4949
>>> len(strategies)
50-
79
50+
80
5151

5252
Or, to find out how many strategies only use 1 turn worth of memory to
5353
make a decision::

0 commit comments

Comments
 (0)