88
99import inspect
1010import random
11- from types import FunctionType
11+ import collections
1212from numpy .random import choice
1313
1414from .actions import Actions , flip_action
@@ -246,6 +246,16 @@ def mixed_wrapper(player, opponent, action, probability, m_player):
246246 of players or a single player.
247247
248248 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]
249259 """
250260
251261 # If a single probability, player is passed
@@ -254,14 +264,15 @@ def mixed_wrapper(player, opponent, action, probability, m_player):
254264 probability = [probability ]
255265
256266 # 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 ):
258269 mutate_prob = sum (probability ) # Prob of mutation
259270 if mutate_prob > 0 :
260271 # Distribution of choice of mutation:
261272 normalised_prob = [prob / float (mutate_prob )
262273 for prob in probability ]
263274 if random .random () < mutate_prob :
264- p = choice (m_player , p = normalised_prob )()
275+ p = choice (list ( m_player ) , p = normalised_prob )()
265276 p .history = player .history
266277 return p .strategy (opponent )
267278
0 commit comments