1
- from ctypes import c_int , c_float , POINTER , CDLL
1
+ from ctypes import c_int , c_float , POINTER
2
2
import itertools
3
3
4
4
import pytest
5
5
6
6
from axelrod_fortran import Player , characteristics , all_strategies
7
7
from axelrod import (Alternator , Cooperator , Defector , Match , MoranProcess ,
8
- Game , basic_strategies , seed )
8
+ Game , RandomGenerator , Tournament , basic_strategies )
9
9
from axelrod .action import Action
10
10
11
11
@@ -122,32 +122,33 @@ def test_implemented_strategies():
122
122
"""
123
123
for strategy , dictionary in characteristics .items ():
124
124
axelrod_class = dictionary ["axelrod-python_class" ]
125
- player = Player (strategy )
126
- if (axelrod_class is not None and
127
- player .classifier ["stochastic" ] is False ):
128
- axl_player = axelrod_class ()
125
+ stochastic = Player (strategy ).classifier ["stochastic" ]
126
+ if axelrod_class is not None and not stochastic :
129
127
for opponent_strategy in basic_strategies :
128
+ player = Player (strategy )
130
129
opponent = opponent_strategy ()
131
130
match = Match ((player , opponent ))
132
131
interactions = match .play ()
132
+
133
+ axl_player = axelrod_class ()
134
+ opponent = opponent_strategy ()
133
135
axl_match = Match ((axl_player , opponent ))
134
- assert interactions == axl_match .play (), (player , opponent )
136
+ axl_interactions = axl_match .play ()
137
+ assert interactions == axl_interactions
135
138
136
139
137
140
def test_champion_v_alternator ():
138
141
"""
139
- Specific regression test for a bug.
142
+ Specific regression test for a bug. See:
143
+ https://github.com/Axelrod-Python/axelrod-fortran/issues/62
140
144
"""
141
145
player = Player ("k61r" )
142
146
opponent = Alternator ()
143
-
144
- match = Match ((player , opponent ))
145
-
146
- seed (0 )
147
+ seed = 3
148
+ match = Match ((player , opponent ), seed = seed )
147
149
interactions = match .play ()
148
150
assert interactions [25 :30 ] == [(C , D ), (C , C ), (C , D ), (D , C ), (C , D )]
149
-
150
- seed (0 )
151
+ match = Match ((player , opponent ), seed = seed )
151
152
assert interactions == match .play ()
152
153
153
154
@@ -157,9 +158,7 @@ def test_warning_for_self_interaction(recwarn):
157
158
"""
158
159
player = Player ("k42r" )
159
160
opponent = player
160
-
161
161
match = Match ((player , opponent ))
162
-
163
162
interactions = match .play ()
164
163
assert len (recwarn ) == 1
165
164
@@ -168,13 +167,10 @@ def test_no_warning_for_normal_interaction(recwarn):
168
167
"""
169
168
Test that a warning is not given for a normal interaction
170
169
"""
171
- player = Player ("k42r" )
172
- opponent = Alternator ()
173
170
for players in [(Player ("k42r" ), Alternator ()),
174
171
(Player ("k42r" ), Player ("k41r" ))]:
175
172
176
173
match = Match (players )
177
-
178
174
interactions = match .play ()
179
175
assert len (recwarn ) == 0
180
176
@@ -185,3 +181,35 @@ def test_multiple_copies(recwarn):
185
181
mp = MoranProcess (players )
186
182
mp .play ()
187
183
mp .populations_plot ()
184
+
185
+
186
+ def test_match_reproducibility ():
187
+ for _ in range (100 ):
188
+ rng = RandomGenerator ()
189
+ seed = rng .random_seed_int ()
190
+ strategies = rng .choice (all_strategies , size = 2 )
191
+ players1 = [Player (strategy ) for strategy in strategies ]
192
+ match1 = Match (players1 , turns = 200 , noise = 0.1 , seed = seed )
193
+ results1 = match1 .play ()
194
+
195
+ players2 = [Player (strategy ) for strategy in strategies ]
196
+ match2 = Match (players2 , turns = 200 , noise = 0.1 , seed = seed )
197
+ results2 = match2 .play ()
198
+
199
+ assert (results1 == results2 )
200
+
201
+
202
+ def test_tournament_reproducibility ():
203
+ rng = RandomGenerator ()
204
+ seed = rng .random_seed_int ()
205
+ strategies = rng .choice (all_strategies , size = 10 )
206
+ players1 = [Player (strategy ) for strategy in strategies ]
207
+ tournament1 = Tournament (players1 , seed = seed , repetitions = 2 )
208
+ results1 = tournament1 .play (processes = 2 )
209
+
210
+ players2 = [Player (strategy ) for strategy in strategies ]
211
+ tournament2 = Tournament (players2 , seed = seed , repetitions = 2 )
212
+ results2 = tournament2 .play (processes = 2 )
213
+
214
+ assert (results1 .ranked_names == results2 .ranked_names )
215
+
0 commit comments