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
@@ -27,14 +28,26 @@ def __new__(cls, *args, **kwargs):
2728 """Caches arguments for Player cloning."""
2829 obj = super ().__new__ (cls )
2930 obj .init_kwargs = cls .init_params (* args , ** kwargs )
31+ # # Set up random seed from the module level random seed
32+ # # in case the user doesn't specific one later.
33+ # need_seed = False
34+ # try:
35+ # seed = kwargs["seed"]
36+ # if seed is None:
37+ # need_seed = True
38+ # except KeyError:
39+ # need_seed = True
40+ # if need_seed:
41+ # seed = _module_random.randint(0, 2**32-1)
42+ # obj._seed = seed
3043 return obj
3144
3245 @classmethod
3346 def init_params (cls , * args , ** kwargs ):
3447 """
3548 Return a dictionary containing the init parameters of a strategy
3649 (without 'self').
37- Use *args and *kwargs as value if specified
50+ Use *args and ** kwargs as value if specified
3851 and complete the rest with the default values.
3952 """
4053 sig = inspect .signature (cls .__init__ )
@@ -53,7 +66,7 @@ def __init__(self):
5366 self ._history = History ()
5467 self .classifier = copy .deepcopy (self .classifier )
5568 self .set_match_attributes ()
56- self .set_seed ()
69+ # self.set_seed(seed=self._seed )
5770
5871 def __eq__ (self , other ):
5972 """
@@ -67,8 +80,8 @@ def __eq__(self, other):
6780 value = getattr (self , attribute , None )
6881 other_value = getattr (other , attribute , None )
6982
70- if attribute == "_random" :
71- # Don't compare the random seeds .
83+ if attribute in [ "_random" , "_seed" ] :
84+ # Don't compare the random generators .
7285 continue
7386
7487 if isinstance (value , np .ndarray ):
@@ -118,9 +131,13 @@ def set_match_attributes(self, length=-1, game=None, noise=0):
118131 self .receive_match_attributes ()
119132
120133 def set_seed (self , seed = None ):
121- """Set a random seed for the player's random number
122- generator."""
123- self ._random = RandomGenerator (seed = seed )
134+ """Set a random seed for the player's random number generator."""
135+ if seed is None :
136+ # Warning: using global seed
137+ self ._seed = _module_random .random_seed_int ()
138+ else :
139+ self ._seed = seed
140+ self ._random = RandomGenerator (seed = self ._seed )
124141
125142 def __repr__ (self ):
126143 """The string method for the strategy.
@@ -161,6 +178,7 @@ def clone(self):
161178 cls = self .__class__
162179 new_player = cls (** self .init_kwargs )
163180 new_player .match_attributes = copy .copy (self .match_attributes )
181+ # new_player.set_seed(self._seed)
164182 return new_player
165183
166184 def reset (self ):
@@ -172,6 +190,7 @@ def reset(self):
172190 """
173191 # This also resets the history.
174192 self .__init__ (** self .init_kwargs )
193+ # self.set_seed(self._seed)
175194
176195 def update_history (self , play , coplay ):
177196 self .history .append (play , coplay )
0 commit comments