8
8
9
9
import inspect
10
10
import random
11
- from types import FunctionType
11
+ import collections
12
12
from numpy .random import choice
13
13
14
14
from .actions import Actions , flip_action
@@ -246,6 +246,16 @@ def mixed_wrapper(player, opponent, action, probability, m_player):
246
246
of players or a single player.
247
247
248
248
In essence creating a mixed strategy.
249
+
250
+ Parameters
251
+ ----------
252
+
253
+ probability: a float (or integer: 0 or 1) OR an iterable representing a
254
+ an incomplete probability distribution (entries to do not have to sum to
255
+ 1). Eg: 0, 1, [.5,.5], (.5,.3)
256
+ m_players: a single player class or iterable representing set of player
257
+ classes to mix from.
258
+ Eg: axelrod.TitForTat, [axelod.Cooperator, axelrod.Defector]
249
259
"""
250
260
251
261
# If a single probability, player is passed
@@ -254,14 +264,15 @@ def mixed_wrapper(player, opponent, action, probability, m_player):
254
264
probability = [probability ]
255
265
256
266
# If a probability distribution, players is passed
257
- if isinstance (probability , list ) and isinstance (m_player , list ):
267
+ if isinstance (probability , collections .Iterable ) and \
268
+ isinstance (m_player , collections .Iterable ):
258
269
mutate_prob = sum (probability ) # Prob of mutation
259
270
if mutate_prob > 0 :
260
271
# Distribution of choice of mutation:
261
272
normalised_prob = [prob / float (mutate_prob )
262
273
for prob in probability ]
263
274
if random .random () < mutate_prob :
264
- p = choice (m_player , p = normalised_prob )()
275
+ p = choice (list ( m_player ) , p = normalised_prob )()
265
276
p .history = player .history
266
277
return p .strategy (opponent )
267
278
0 commit comments