1- from ctypes import c_int , c_float , POINTER , CDLL
1+ from ctypes import c_int , c_float , POINTER
22import itertools
33
44import pytest
55
66from axelrod_fortran import Player , characteristics , all_strategies
77from axelrod import (Alternator , Cooperator , Defector , Match , MoranProcess ,
8- Game , basic_strategies , seed )
8+ Game , RandomGenerator , Tournament , basic_strategies )
99from axelrod .action import Action
1010
1111
@@ -122,32 +122,33 @@ def test_implemented_strategies():
122122 """
123123 for strategy , dictionary in characteristics .items ():
124124 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 :
129127 for opponent_strategy in basic_strategies :
128+ player = Player (strategy )
130129 opponent = opponent_strategy ()
131130 match = Match ((player , opponent ))
132131 interactions = match .play ()
132+
133+ axl_player = axelrod_class ()
134+ opponent = opponent_strategy ()
133135 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
135138
136139
137140def test_champion_v_alternator ():
138141 """
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
140144 """
141145 player = Player ("k61r" )
142146 opponent = Alternator ()
143-
144- match = Match ((player , opponent ))
145-
146- seed (0 )
147+ seed = 3
148+ match = Match ((player , opponent ), seed = seed )
147149 interactions = match .play ()
148150 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 )
151152 assert interactions == match .play ()
152153
153154
@@ -157,9 +158,7 @@ def test_warning_for_self_interaction(recwarn):
157158 """
158159 player = Player ("k42r" )
159160 opponent = player
160-
161161 match = Match ((player , opponent ))
162-
163162 interactions = match .play ()
164163 assert len (recwarn ) == 1
165164
@@ -168,13 +167,10 @@ def test_no_warning_for_normal_interaction(recwarn):
168167 """
169168 Test that a warning is not given for a normal interaction
170169 """
171- player = Player ("k42r" )
172- opponent = Alternator ()
173170 for players in [(Player ("k42r" ), Alternator ()),
174171 (Player ("k42r" ), Player ("k41r" ))]:
175172
176173 match = Match (players )
177-
178174 interactions = match .play ()
179175 assert len (recwarn ) == 0
180176
@@ -185,3 +181,35 @@ def test_multiple_copies(recwarn):
185181 mp = MoranProcess (players )
186182 mp .play ()
187183 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