66
77import numpy as np
88
9+ from axelrod import _module_random
910from axelrod .action import Action
1011from axelrod .game import DefaultGame
1112from axelrod .history import History
@@ -70,14 +71,26 @@ def __new__(cls, *args, **kwargs):
7071 """Caches arguments for Player cloning."""
7172 obj = super ().__new__ (cls )
7273 obj .init_kwargs = cls .init_params (* args , ** kwargs )
74+ # # Set up random seed from the module level random seed
75+ # # in case the user doesn't specific one later.
76+ # need_seed = False
77+ # try:
78+ # seed = kwargs["seed"]
79+ # if seed is None:
80+ # need_seed = True
81+ # except KeyError:
82+ # need_seed = True
83+ # if need_seed:
84+ # seed = _module_random.randint(0, 2**32-1)
85+ # obj._seed = seed
7386 return obj
7487
7588 @classmethod
7689 def init_params (cls , * args , ** kwargs ):
7790 """
7891 Return a dictionary containing the init parameters of a strategy
7992 (without 'self').
80- Use *args and *kwargs as value if specified
93+ Use *args and ** kwargs as value if specified
8194 and complete the rest with the default values.
8295 """
8396 sig = inspect .signature (cls .__init__ )
@@ -99,7 +112,7 @@ def __init__(self):
99112 if dimension not in self .classifier :
100113 self .classifier [dimension ] = self .default_classifier [dimension ]
101114 self .set_match_attributes ()
102- self .set_seed ()
115+ # self.set_seed(seed=self._seed )
103116
104117 def __eq__ (self , other ):
105118 """
@@ -113,8 +126,8 @@ def __eq__(self, other):
113126 value = getattr (self , attribute , None )
114127 other_value = getattr (other , attribute , None )
115128
116- if attribute == "_random" :
117- # Don't compare the random seeds .
129+ if attribute in [ "_random" , "_seed" ] :
130+ # Don't compare the random generators .
118131 continue
119132
120133 if isinstance (value , np .ndarray ):
@@ -164,9 +177,13 @@ def set_match_attributes(self, length=-1, game=None, noise=0):
164177 self .receive_match_attributes ()
165178
166179 def set_seed (self , seed = None ):
167- """Set a random seed for the player's random number
168- generator."""
169- self ._random = RandomGenerator (seed = seed )
180+ """Set a random seed for the player's random number generator."""
181+ if seed is None :
182+ # Warning: using global seed
183+ self ._seed = _module_random .random_seed_int ()
184+ else :
185+ self ._seed = seed
186+ self ._random = RandomGenerator (seed = self ._seed )
170187
171188 def __repr__ (self ):
172189 """The string method for the strategy.
@@ -207,6 +224,7 @@ def clone(self):
207224 cls = self .__class__
208225 new_player = cls (** self .init_kwargs )
209226 new_player .match_attributes = copy .copy (self .match_attributes )
227+ # new_player.set_seed(self._seed)
210228 return new_player
211229
212230 def reset (self ):
@@ -218,6 +236,7 @@ def reset(self):
218236 """
219237 # This also resets the history.
220238 self .__init__ (** self .init_kwargs )
239+ # self.set_seed(self._seed)
221240
222241 def update_history (self , play , coplay ):
223242 self .history .append (play , coplay )
0 commit comments