Skip to content

Commit 3ee5c1f

Browse files
Merge pull request #1154 from gaffney2010/master
Implemented White strategy, k72r from Axelrod's Second
2 parents bc9cd5a + 9124cba commit 3ee5c1f

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
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, Getzler, Leyvraz)
13+
MoreTidemanAndChieruzzi, Getzler, Leyvraz, White)
1414
from .backstabber import BackStabber, DoubleCrosser
1515
from .better_and_better import BetterAndBetter
1616
from .bush_mosteller import BushMosteller
@@ -276,6 +276,7 @@
276276
TwoTitsForTat,
277277
VeryBad,
278278
Weiner,
279+
White,
279280
Willing,
280281
Winner12,
281282
Winner21,

axelrod/strategies/axelrod_second.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ def calculate_chi_squared(self, turn):
11371137
In this function, the statistic is non-standard in that it excludes
11381138
summands where E_i <= 1.
11391139
"""
1140-
1140+
11411141
denom = turn - 2
11421142

11431143
expected_matrix = np.outer(self.move_history.sum(axis=1),
@@ -1165,7 +1165,7 @@ def detect_random(self, turn):
11651165
self.history, and returns True (is random) if and only if the statistic
11661166
is less than or equal to 3.
11671167
"""
1168-
1168+
11691169
denom = turn - 2
11701170

11711171
if self.move_history[0, 0] / denom >= 0.8:
@@ -1300,7 +1300,7 @@ def strategy(self, opponent: Player) -> Action:
13001300
if self.burned or random.random() > self.prob:
13011301
# Tit-for-Tat with probability 1-`prob`
13021302
return self.try_return(opponent.history[-1], inc_parity=True)
1303-
1303+
13041304
# Otherwise Defect, Cooperate, Cooperate, and increase `prob`
13051305
self.prob += 0.05
13061306
self.more_coop, self.last_generous_n_turns_ago = 2, 1
@@ -1421,7 +1421,7 @@ def strategy(self, opponent: Player) -> Action:
14211421
class Getzler(Player):
14221422
"""
14231423
Strategy submitted to Axelrod's second tournament by Abraham Getzler (K35R)
1424-
and came in tenth in that tournament.
1424+
and came in eleventh in that tournament.
14251425
14261426
Strategy Defects with probability `flack`, where `flack` is calculated as
14271427
the sum over opponent Defections of 0.5 ^ (turns ago Defection happened).
@@ -1459,7 +1459,7 @@ def strategy(self, opponent: Player) -> Action:
14591459
class Leyvraz(Player):
14601460
"""
14611461
Strategy submitted to Axelrod's second tournament by Fransois Leyvraz
1462-
(K68R) and came in eleventh in that tournament.
1462+
(K68R) and came in twelfth in that tournament.
14631463
14641464
The strategy uses the opponent's last three moves to decide on an action
14651465
based on the following ordered rules.
@@ -1508,3 +1508,40 @@ def strategy(self, opponent: Player) -> Action:
15081508
return random_choice(self.prob_coop[(recent_history[-3],
15091509
recent_history[-2],
15101510
recent_history[-1])])
1511+
1512+
1513+
class White(Player):
1514+
"""
1515+
Strategy submitted to Axelrod's second tournament by Edward C White (K72R)
1516+
and came in thirteenth in that tournament.
1517+
1518+
* If the opponent Cooperated last turn or in the first ten turns, then
1519+
Cooperate.
1520+
* Otherwise Defect if and only if:
1521+
floor(log(turn)) * opponent Defections >= turn
1522+
1523+
Names:
1524+
1525+
- White: [Axelrod1980b]_
1526+
"""
1527+
1528+
name = 'White'
1529+
classifier = {
1530+
'memory_depth': float("inf"),
1531+
'stochastic': False,
1532+
'makes_use_of': set(),
1533+
'long_run_time': False,
1534+
'inspects_source': False,
1535+
'manipulates_source': False,
1536+
'manipulates_state': False
1537+
}
1538+
1539+
def strategy(self, opponent: Player) -> Action:
1540+
turn = len(self.history) + 1
1541+
1542+
if turn <= 10 or opponent.history[-1] == C:
1543+
return C
1544+
1545+
if np.floor(np.log(turn)) * opponent.defections >= turn:
1546+
return D
1547+
return C

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,34 @@ def test_strategy(self):
960960
self.versus_test(axelrod.Alternator(), expected_actions=actions, seed=2)
961961
actions = [(C, C), (C, D), (C, C)] + [(D, D), (C, C)] * 3
962962
self.versus_test(axelrod.Alternator(), expected_actions=actions, seed=3)
963+
964+
965+
class TestWhite(TestPlayer):
966+
name = 'White'
967+
player = axelrod.White
968+
expected_classifier = {
969+
'memory_depth': float("inf"),
970+
'stochastic': False,
971+
'makes_use_of': set(),
972+
'long_run_time': False,
973+
'inspects_source': False,
974+
'manipulates_source': False,
975+
'manipulates_state': False
976+
}
977+
978+
def test_strategy(self):
979+
actions = [(C, C)] * 30
980+
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
981+
982+
actions = [(C, D)] * 10 + [(D, D)] * 20
983+
self.versus_test(axelrod.Defector(), expected_actions=actions)
984+
985+
actions = [(C, D), (C, D), (C, C), (C, C), (C, C), (C, D), (C, C),
986+
(C, D), (C, C), (C, D), (C, C), (C, D), (C, D), (D, C),
987+
(C, D), (D, D), (D, C), (C, D), (D, D), (D, C)]
988+
self.versus_test(axelrod.Random(0.5), expected_actions=actions, seed=6)
989+
actions = [(C, C), (C, D), (C, D), (C, C), (C, C), (C, C), (C, C),
990+
(C, D), (C, D), (C, D), (C, D), (D, D), (D, C), (C, C),
991+
(C, C), (C, D), (C, C), (C, D), (C, C), (C, D)]
992+
self.versus_test(axelrod.Random(0.5), expected_actions=actions, seed=12)
993+

docs/reference/overview_of_strategies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ repository.
140140
"K69R_", "Johann Joss", "Not Implemented"
141141
"K70R_", "Robert Pebly", "Not Implemented"
142142
"K71R_", "James E Hall", "Not Implemented"
143-
"K72R_", "Edward C White Jr", "Not Implemented"
143+
"K72R_", "Edward C White Jr", ":class:`White <axelrod.strategies.axelrod_second.White>`"
144144
"K73R_", "George Zimmerman", "Not Implemented"
145145
"K74R_", "Edward Friedland", "Not Implemented"
146146
"K74RXX_", "Edward Friedland", "Not Implemented"

0 commit comments

Comments
 (0)