Skip to content

Commit 49b5f1a

Browse files
Merge pull request #952 from Axelrod-Python/issue-945
Use kwargs for Player initialisation throughout library
2 parents 86c21c2 + 1bc9dac commit 49b5f1a

39 files changed

+267
-177
lines changed

axelrod/fingerprint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ def create_jossann(point, probe):
9191
x, y = point
9292

9393
if isinstance(probe, axl.Player):
94-
init_args = probe.init_args
94+
init_kwargs = probe.init_kwargs
9595
probe = probe.__class__
9696
else:
97-
init_args = ()
97+
init_kwargs = {}
9898

9999
if x + y >= 1:
100100
joss_ann = DualTransformer()(
101-
JossAnnTransformer((1 - x, 1 - y))(probe))(*init_args)
101+
JossAnnTransformer((1 - x, 1 - y))(probe))(**init_kwargs)
102102
else:
103-
joss_ann = JossAnnTransformer((x, y))(probe)(*init_args)
103+
joss_ann = JossAnnTransformer((x, y))(probe)(**init_kwargs)
104104
return joss_ann
105105

106106
@staticmethod

axelrod/tests/integration/test_matches.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def test_matches_with_det_player_for_stochastic_classes(self):
4747
"""A test based on a bug found in the cache.
4848
4949
See: https://github.com/Axelrod-Python/Axelrod/issues/779"""
50-
p1 = axelrod.MemoryOnePlayer((0, 0, 0, 0))
51-
p2 = axelrod.MemoryOnePlayer((1, 0, 1, 0))
52-
p3 = axelrod.MemoryOnePlayer((1, 1, 1, 0))
50+
p1 = axelrod.MemoryOnePlayer(four_vector=(0, 0, 0, 0))
51+
p2 = axelrod.MemoryOnePlayer(four_vector=(1, 0, 1, 0))
52+
p3 = axelrod.MemoryOnePlayer(four_vector=(1, 1, 1, 0))
5353

5454
m = axelrod.Match((p1, p2), turns=3)
5555
self.assertEqual(m.play(), [('C', 'C'), ('D', 'C'), ('D', 'D')])

axelrod/tests/strategies/test_alternator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ def test_strategy(self):
3030
actions = [(C, D), (D, D)] * 5
3131
self.versus_test(axelrod.Defector(), expected_actions=actions)
3232

33-
opponent = axelrod.MockPlayer([D, C])
33+
opponent = axelrod.MockPlayer(actions=[D, C])
3434
actions = [(C, D), (D, C)] * 5
3535
self.versus_test(opponent, expected_actions=actions)

axelrod/tests/strategies/test_apavlov.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_strategy(self):
2727
self.versus_test(axelrod.Cooperator(), expected_actions=actions,
2828
attrs={"opponent_class": "Cooperative"})
2929

30-
opponent = axelrod.MockPlayer([C] * 6 + [D])
30+
opponent = axelrod.MockPlayer(actions=[C] * 6 + [D])
3131
actions = [(C, C)] * 6 + [(C, D), (D, C)]
3232
self.versus_test(opponent, expected_actions=actions,
3333
attrs={"opponent_class": "Cooperative"})
@@ -36,30 +36,30 @@ def test_strategy(self):
3636
self.versus_test(axelrod.Defector(), expected_actions=actions,
3737
attrs={"opponent_class": "ALLD"})
3838

39-
opponent = axelrod.MockPlayer([D, C, D, C, D, C])
39+
opponent = axelrod.MockPlayer(actions=[D, C, D, C, D, C])
4040
actions = [(C, D), (D, C), (C, D), (D, C),
4141
(C, D), (D, C), (C, D), (C, C),
4242
(C, D), (D, C)]
4343
self.versus_test(opponent, expected_actions=actions,
4444
attrs={"opponent_class": "STFT"})
4545

46-
opponent = axelrod.MockPlayer([D, D, C, D, D, C])
46+
opponent = axelrod.MockPlayer(actions=[D, D, C, D, D, C])
4747
actions = [(C, D), (D, D), (D, C), (C, D), (D, D), (D, C), (D, D)]
4848
self.versus_test(opponent, expected_actions=actions,
4949
attrs={"opponent_class": "PavlovD"})
5050

51-
opponent = axelrod.MockPlayer([D, D, C, D, D, C, D])
51+
opponent = axelrod.MockPlayer(actions=[D, D, C, D, D, C, D])
5252
actions = [(C, D), (D, D), (D, C), (C, D),
5353
(D, D), (D, C), (D, D), (C, D)]
5454
self.versus_test(opponent, expected_actions=actions,
5555
attrs={"opponent_class": "PavlovD"})
5656

57-
opponent = axelrod.MockPlayer([C, C, C, D, D, D])
57+
opponent = axelrod.MockPlayer(actions=[C, C, C, D, D, D])
5858
actions = [(C, C), (C, C), (C, C), (C, D), (D, D), (D, D), (D, C)]
5959
self.versus_test(opponent, expected_actions=actions,
6060
attrs={"opponent_class": "Random"})
6161

62-
opponent = axelrod.MockPlayer([D, D, D, C, C, C])
62+
opponent = axelrod.MockPlayer(actions=[D, D, D, C, C, C])
6363
actions = [(C, D), (D, D), (D, D), (D, C), (C, C), (C, C), (D, D)]
6464
self.versus_test(opponent, expected_actions=actions,
6565
attrs={"opponent_class": "Random"})
@@ -90,47 +90,47 @@ def test_strategy(self):
9090
self.versus_test(axelrod.Defector(), expected_actions=actions,
9191
attrs={"opponent_class": "ALLD"})
9292

93-
opponent = axelrod.MockPlayer([C, D, D, D, D, D, D])
93+
opponent = axelrod.MockPlayer(actions=[C, D, D, D, D, D, D])
9494
actions = [(C, C), (C, D)] + [(D, D)] * 5 + [(D, C)]
9595
self.versus_test(opponent, expected_actions=actions,
9696
attrs={"opponent_class": "ALLD"})
9797

98-
opponent = axelrod.MockPlayer([C, C, D, D, D, D, D])
98+
opponent = axelrod.MockPlayer(actions=[C, C, D, D, D, D, D])
9999
actions = [(C, C), (C, C), (C, D)] + [(D, D)] * 4 + [(D, C)]
100100
self.versus_test(opponent, expected_actions=actions,
101101
attrs={"opponent_class": "ALLD"})
102102

103-
opponent = axelrod.MockPlayer([C, D, D, C, D, D, D])
103+
opponent = axelrod.MockPlayer(actions=[C, D, D, C, D, D, D])
104104
actions = [(C, C), (C, D), (D, D), (D, C),
105105
(C, D), (D, D), (D, D), (D, C)]
106106
self.versus_test(opponent, expected_actions=actions,
107107
attrs={"opponent_class": "ALLD"})
108108

109-
opponent = axelrod.MockPlayer([C, D, D, C, C, D, D])
109+
opponent = axelrod.MockPlayer(actions=[C, D, D, C, C, D, D])
110110
actions = [(C, C), (C, D), (D, D), (D, C),
111111
(C, C), (C, D), (C, D), (D, C)]
112112
self.versus_test(opponent, expected_actions=actions,
113113
attrs={"opponent_class": "STFT"})
114114

115-
opponent = axelrod.MockPlayer([C, D, C, D, C, D, D])
115+
opponent = axelrod.MockPlayer(actions=[C, D, C, D, C, D, D])
116116
actions = [(C, C), (C, D), (D, C), (C, D),
117117
(D, C), (C, D), (C, D), (D, C)]
118118
self.versus_test(opponent, expected_actions=actions,
119119
attrs={"opponent_class": "STFT"})
120120

121-
opponent = axelrod.MockPlayer([D, D, D, C, C, C, C])
121+
opponent = axelrod.MockPlayer(actions=[D, D, D, C, C, C, C])
122122
actions = [(C, D), (D, D), (D, D), (D, C),
123123
(C, C), (C, C), (C, C), (C, D)]
124124
self.versus_test(opponent, expected_actions=actions,
125125
attrs={"opponent_class": "STFT"})
126126

127-
opponent = axelrod.MockPlayer([C, C, C, C, D, D])
127+
opponent = axelrod.MockPlayer(actions=[C, C, C, C, D, D])
128128
actions = [(C, C), (C, C), (C, C), (C, C),
129129
(C, D), (D, D), (D, C), (D, C)]
130130
self.versus_test(opponent, expected_actions=actions,
131131
attrs={"opponent_class": "Random"})
132132

133-
opponent = axelrod.MockPlayer([D, D, C, C, C, C])
133+
opponent = axelrod.MockPlayer(actions=[D, D, C, C, C, C])
134134
actions = [(C, D), (D, D), (D, C), (C, C),
135135
(C, C), (C, C), (D, D), (D, D)]
136136
self.versus_test(opponent, expected_actions=actions,

axelrod/tests/strategies/test_appeaser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def test_strategy(self):
3030
actions = [(C, D), (D, D), (C, D), (D, D), (C, D)]
3131
self.versus_test(axelrod.Defector(), expected_actions=actions)
3232

33-
opponent = axelrod.MockPlayer([C, C, D, D])
33+
opponent = axelrod.MockPlayer(actions=[C, C, D, D])
3434
actions = [(C, C), (C, C), (C, D), (D, D), (C, C), (C, C)]
3535
self.versus_test(opponent, expected_actions=actions)
3636

37-
opponent = axelrod.MockPlayer([C, C, D, D, D])
37+
opponent = axelrod.MockPlayer(actions=[C, C, D, D, D])
3838
actions = [(C, C), (C, C), (C, D), (D, D), (C, D), (D, C), (D, C)]
3939
self.versus_test(opponent, expected_actions=actions)

axelrod/tests/strategies/test_averagecopier.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def test_strategy(self):
5353
self.versus_test(axelrod.Alternator(), expected_actions=actions,
5454
seed=2)
5555

56-
opponent = axelrod.MockPlayer([C, C, D, D, D, D])
56+
opponent = axelrod.MockPlayer(actions=[C, C, D, D, D, D])
5757
actions = [(C, C), (C, C), (C, D), (D, D), (D, D),
5858
(C, D), (D, C), (D, C), (D, D), (D, D)]
5959
self.versus_test(opponent, expected_actions=actions,
6060
seed=1)
6161

62-
opponent = axelrod.MockPlayer([C, C, C, D, D, D])
62+
opponent = axelrod.MockPlayer(actions=[C, C, C, D, D, D])
6363
actions = [(D, C), (C, C), (C, C), (C, D), (D, D),
6464
(C, D), (C, C), (D, C), (D, C), (D, D)]
6565
self.versus_test(opponent, expected_actions=actions,
@@ -106,13 +106,13 @@ def test_strategy(self):
106106
self.versus_test(axelrod.Alternator(), expected_actions=actions,
107107
seed=2)
108108

109-
opponent = axelrod.MockPlayer([C, C, D, D, D, D])
109+
opponent = axelrod.MockPlayer(actions=[C, C, D, D, D, D])
110110
actions = [(C, C), (C, C), (C, D), (C, D), (D, D),
111111
(D, D), (C, C), (D, C), (C, D), (D, D)]
112112
self.versus_test(opponent, expected_actions=actions,
113113
seed=1)
114114

115-
opponent = axelrod.MockPlayer([C, C, C, D, D, D])
115+
opponent = axelrod.MockPlayer(actions=[C, C, C, D, D, D])
116116
actions = [(C, C), (C, C), (C, C), (C, D), (D, D),
117117
(D, D), (C, C), (C, C), (D, C), (D, D)]
118118
self.versus_test(opponent, expected_actions=actions,

axelrod/tests/strategies/test_axelrod_first.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def test_strategy(self):
3636

3737
# If opponent defects at any point then the player will defect forever
3838
# (after 10 rounds)
39-
opponent = axelrod.MockPlayer([C] * 10 + [D])
39+
opponent = axelrod.MockPlayer(actions=[C] * 10 + [D])
4040
actions = [(C, C)] * 10 + [(C, D), (D, C)]
4141
self.versus_test(opponent, expected_actions=actions)
4242

43-
opponent = axelrod.MockPlayer([C] * 15 + [D])
43+
opponent = axelrod.MockPlayer(actions=[C] * 15 + [D])
4444
actions = [(C, C)] * 15 + [(C, D), (D, C)]
4545
self.versus_test(opponent, expected_actions=actions)
4646

@@ -69,19 +69,19 @@ def test_strategy(self):
6969
actions = [(C, D), (C, D), (D, D)]
7070
self.versus_test(axelrod.Defector(), expected_actions=actions)
7171

72-
opponent = axelrod.MockPlayer([D, C, C])
72+
opponent = axelrod.MockPlayer(actions=[D, C, C])
7373
actions = [(C, D), (C, C), (C, C), (C, D)]
7474
self.versus_test(opponent, expected_actions=actions)
7575

76-
opponent = axelrod.MockPlayer([D, D, C])
76+
opponent = axelrod.MockPlayer(actions=[D, D, C])
7777
actions = [(C, D), (C, D), (D, C), (D, D)]
7878
self.versus_test(opponent, expected_actions=actions)
7979

80-
opponent = axelrod.MockPlayer([C, C, D, D, C, C])
80+
opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, C])
8181
actions = [(C, C), (C, C), (C, D), (C, D), (D, C), (D, C), (D, C)]
8282
self.versus_test(opponent, expected_actions=actions)
8383

84-
opponent = axelrod.MockPlayer([C, C, C, C, D, D])
84+
opponent = axelrod.MockPlayer(actions=[C, C, C, C, D, D])
8585
actions = [(C, C), (C, C), (C, C), (C, C), (C, D), (C, D), (C, C)]
8686
self.versus_test(opponent, expected_actions=actions)
8787

@@ -174,11 +174,11 @@ def test_strategy(self):
174174
actions = [(C, C), (C, D), (D, C)]
175175
self.versus_test(axelrod.Alternator(), expected_actions=actions)
176176

177-
opponent = axelrod.MockPlayer([D] * 8)
177+
opponent = axelrod.MockPlayer(actions=[D] * 8)
178178
actions = [(C, D)] * 2 + [(D, D)] * 5 + [(C, D)] + [(C, D)]
179179
self.versus_test(opponent, expected_actions=actions, seed=1)
180180

181-
opponent = axelrod.MockPlayer([D] * 8)
181+
opponent = axelrod.MockPlayer(actions=[D] * 8)
182182
actions = [(C, D)] * 2 + [(D, D)] * 5 + [(C, D)] + [(D, D)]
183183
self.versus_test(opponent, expected_actions=actions, seed=2)
184184

@@ -269,7 +269,7 @@ def test_strategy(self):
269269
(D, C), (C, D), (D, C), (C, D)]
270270
self.versus_test(axelrod.Alternator(), expected_actions=actions)
271271

272-
opponent = axelrod.MockPlayer([D, C])
272+
opponent = axelrod.MockPlayer(actions=[D, C])
273273
actions = [(C, D), (D, C), (D, D), (D, C),
274274
(D, D), (D, C), (D, D), (D, C)]
275275
self.versus_test(opponent, expected_actions=actions)
@@ -301,19 +301,19 @@ def test_strategy(self):
301301
actions = [(C, C), (C, D), (D, C)]
302302
self.versus_test(axelrod.Alternator(), expected_actions=actions)
303303

304-
opponent = axelrod.MockPlayer([D, C, C])
304+
opponent = axelrod.MockPlayer(actions=[D, C, C])
305305
actions = [(C, D), (D, C), (C, C), (C, D)]
306306
self.versus_test(opponent, expected_actions=actions)
307307

308-
opponent = axelrod.MockPlayer([D, C, D, C, C])
308+
opponent = axelrod.MockPlayer(actions=[D, C, D, C, C])
309309
actions = [(C, D), (D, C), (C, D), (D, C), (D, C), (C, D), (D, C)]
310310
self.versus_test(opponent, expected_actions=actions)
311311

312-
opponent = axelrod.MockPlayer([D, C, D, D, C])
312+
opponent = axelrod.MockPlayer(actions=[D, C, D, D, C])
313313
actions = [(C, D), (D, C), (C, D), (D, D), (D, C), (C, D), (D, C)]
314314
self.versus_test(opponent, expected_actions=actions)
315315

316-
opponent = axelrod.MockPlayer([D, C, D, C, C, D])
316+
opponent = axelrod.MockPlayer(actions=[D, C, D, C, C, D])
317317
actions = [(C, D), (D, C), (C, D), (D, C), (D, C),
318318
(C, D), (D, D), (D, C), (D, D), (D, C)]
319319
self.versus_test(opponent, expected_actions=actions)
@@ -343,24 +343,24 @@ def test_strategy(self):
343343
actions = [(C, D)] * 11 + [(D, D)] * 2
344344
self.versus_test(axelrod.Defector(), expected_actions=actions)
345345

346-
opponent = axelrod.MockPlayer([D] * 10 + [C])
346+
opponent = axelrod.MockPlayer(actions=[D] * 10 + [C])
347347
actions = [(C, D)] * 10 + [(C, C), (D, D)]
348348
self.versus_test(opponent, expected_actions=actions)
349349

350350
# Test beyond 10 rounds
351-
opponent = axelrod.MockPlayer([D] * 5 + [C] * 6)
351+
opponent = axelrod.MockPlayer(actions=[D] * 5 + [C] * 6)
352352
actions = [(C, D)] * 5 + [(C, C)] * 6 + [(D, D)] * 4
353353
self.versus_test(opponent, expected_actions=actions, seed=20)
354354

355-
opponent = axelrod.MockPlayer([D] * 5 + [C] * 6)
355+
opponent = axelrod.MockPlayer(actions=[D] * 5 + [C] * 6)
356356
actions = [(C, D)] * 5 + [(C, C)] * 6 + [(C, D), (D, D), (D, D), (C, D)]
357357
self.versus_test(opponent, expected_actions=actions, seed=1)
358358

359-
opponent = axelrod.MockPlayer([C] * 9 + [D] * 2)
359+
opponent = axelrod.MockPlayer(actions=[C] * 9 + [D] * 2)
360360
actions = [(C, C)] * 9 + [(C, D)] * 2 + [(C, C), (D, C), (D, C), (C, C)]
361361
self.versus_test(opponent, expected_actions=actions, seed=1)
362362

363-
opponent = axelrod.MockPlayer([C] * 9 + [D] * 2)
363+
opponent = axelrod.MockPlayer(actions=[C] * 9 + [D] * 2)
364364
actions = [(C, C)] * 9 + [(C, D)] * 2 + [(D, C), (D, C), (C, C), (C, C)]
365365
self.versus_test(opponent, expected_actions=actions, seed=2)
366366

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ def test_strategy(self):
8484
self.versus_test(axelrod.Alternator(), expected_actions=actions,
8585
seed=1)
8686

87-
opponent = axelrod.MockPlayer([D, C, C, D])
87+
opponent = axelrod.MockPlayer(actions=[D, C, C, D])
8888
actions = [(C, D), (D, C), (C, C), (C, D), (C, D)]
8989
self.versus_test(opponent, expected_actions=actions, seed=8)
90-
opponent = axelrod.MockPlayer([D, C, C, D])
90+
opponent = axelrod.MockPlayer(actions=[D, C, C, D])
9191
actions = [(C, D), (D, C), (C, C), (C, D), (D, D)]
9292
self.versus_test(opponent, expected_actions=actions, seed=2)
9393

@@ -122,7 +122,7 @@ def test_strategy(self):
122122
attrs={"is_TFT": True})
123123

124124
# Now play TfT
125-
opponent = axelrod.MockPlayer([C, D, C, D, D, C])
125+
opponent = axelrod.MockPlayer(actions=[C, D, C, D, D, C])
126126
actions = [(D, C), (C, D), (C, C), (C, D), (D, D), (D, C), (C, C)]
127127
self.versus_test(opponent, expected_actions=actions,
128128
attrs={"is_TFT": True})

axelrod/tests/strategies/test_backstabber.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def test_when_alt_strategy_is_triggered(self):
7373

7474
opponent_actions = starting_cooperation + [D, D, C, D]
7575
expected_actions = starting_rounds + [(C, D), (C, D), (D, C), (C, D)]
76-
self.versus_test(axelrod.MockPlayer(opponent_actions), expected_actions=expected_actions,
76+
self.versus_test(axelrod.MockPlayer(actions=opponent_actions), expected_actions=expected_actions,
7777
match_attributes={"length": 200})
7878

7979
opponent_actions = starting_cooperation + [D, D, D, D, C, D]
8080
expected_actions = starting_rounds + [(C, D), (C, D), (D, D), (D, D), (D, C), (C, D)]
81-
self.versus_test(axelrod.MockPlayer(opponent_actions), expected_actions=expected_actions,
81+
self.versus_test(axelrod.MockPlayer(actions=opponent_actions), expected_actions=expected_actions,
8282
match_attributes={"length": 200})
8383

8484
def test_starting_defect_keeps_alt_strategy_from_triggering(self):
@@ -87,19 +87,19 @@ def test_starting_defect_keeps_alt_strategy_from_triggering(self):
8787

8888
defects_on_first = [D] + [C] * 6
8989
defects_on_first_actions = [(C, D)] + [(C, C)] * 6
90-
self.versus_test(axelrod.MockPlayer(defects_on_first + opponent_actions_suffix),
90+
self.versus_test(axelrod.MockPlayer(actions=defects_on_first + opponent_actions_suffix),
9191
expected_actions=defects_on_first_actions + expected_actions_suffix,
9292
match_attributes={"length": 200})
9393

9494
defects_in_middle = [C, C, C, D, C, C, C]
9595
defects_in_middle_actions = [(C, C), (C, C), (C, C), (C, D), (C, C), (C, C), (C, C)]
96-
self.versus_test(axelrod.MockPlayer(defects_in_middle + opponent_actions_suffix),
96+
self.versus_test(axelrod.MockPlayer(actions=defects_in_middle + opponent_actions_suffix),
9797
expected_actions=defects_in_middle_actions + expected_actions_suffix,
9898
match_attributes={"length": 200})
9999

100100
defects_on_last = [C] * 6 + [D]
101101
defects_on_last_actions = [(C, C)] * 6 + [(C, D)]
102-
self.versus_test(axelrod.MockPlayer(defects_on_last + opponent_actions_suffix),
102+
self.versus_test(axelrod.MockPlayer(actions=defects_on_last + opponent_actions_suffix),
103103
expected_actions=defects_on_last_actions + expected_actions_suffix,
104104
match_attributes={"length": 200})
105105

@@ -108,7 +108,7 @@ def test_alt_strategy_stops_after_round_180(self):
108108
one_eighty_expected_actions = [(C, C)] * 8 + [(C, C), (C, D)] * 86
109109
opponent_actions = one_eighty_opponent_actions + [C] * 6
110110
expected_actions = one_eighty_expected_actions + [(D, C)] * 6
111-
self.versus_test(axelrod.MockPlayer(opponent_actions), expected_actions=expected_actions,
111+
self.versus_test(axelrod.MockPlayer(actions=opponent_actions), expected_actions=expected_actions,
112112
match_attributes={"length": 200})
113113

114114

0 commit comments

Comments
 (0)