Skip to content

Commit

Permalink
Change sub function for filterset to take player.
Browse files Browse the repository at this point in the history
They used to take a strategy class but this ended up initialising
players multiples times.
  • Loading branch information
drvinceknight authored and marcharper committed Dec 4, 2016
1 parent f764fc5 commit e9273ef
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions axelrod/strategies/_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import operator


def passes_operator_filter(strategy, classifier_key, value, operator):
def passes_operator_filter(player, classifier_key, value, operator):
"""
Tests whether a given strategy passes a filter for a
Tests whether a given player passes a filter for a
given key in its classifier dict using a given (in)equality operator.
e.g.
Expand All @@ -19,13 +19,13 @@ class ExampleStrategy(Player):
'makes_use_of': ['game', 'length']
}
passes_operator_filter(ExampleStrategy, 'memory_depth', 10, operator.eq)
passes_operator_filter(ExampleStrategy(), 'memory_depth', 10, operator.eq)
would test whether the 'memory_depth' entry equals 10 and return True
Parameters
----------
strategy : a descendant class of axelrod.Player
player : an instance of axelrod.Player
classifier_key: string
Defining which entry from the strategy's classifier dict is to be
tested (e.g. 'memory_depth').
Expand All @@ -43,18 +43,18 @@ class ExampleStrategy(Player):
True if the value from the strategy's classifier dictionary matches
the value and operator passed to the function.
"""
classifier_value = strategy().classifier[classifier_key]
classifier_value = player.classifier[classifier_key]
if (isinstance(classifier_value, str) and
classifier_value.lower() == 'infinity'):
classifier_value = float('inf')

return operator(classifier_value, value)


def passes_in_list_filter(strategy, classifier_key, value):
def passes_in_list_filter(player, classifier_key, value):
"""
Tests whether a given list of values exist in the list returned from the
given strategy's classifier dict for the given classifier_key.
given players's classifier dict for the given classifier_key.
e.g.
Expand All @@ -68,7 +68,7 @@ class ExampleStrategy(Player):
'makes_use_of': ['game', 'length']
}
passes_in_list_filter(ExampleStrategy, 'makes_use_of', 'game', operator.eq)
passes_in_list_filter(ExampleStrategy(), 'makes_use_of', 'game', operator.eq)
would test whether 'game' exists in the strategy's' 'makes_use_of' entry
and return True.
Expand All @@ -89,7 +89,7 @@ class ExampleStrategy(Player):
"""
result = True
for entry in value:
if entry not in strategy().classifier[classifier_key]:
if entry not in player.classifier[classifier_key]:
result = False
return result

Expand Down Expand Up @@ -211,7 +211,7 @@ class ExampleStrategy(Player):

if filterset.get(_filter, None) is not None:
kwargs = filter_function.kwargs
kwargs['strategy'] = strategy
kwargs['player'] = strategy()
kwargs['value'] = filterset[_filter]
passes_filters.append(filter_function.function(**kwargs))

Expand Down

0 comments on commit e9273ef

Please sign in to comment.