Skip to content

Commit 8793e58

Browse files
Merge pull request #1355 from gaffney2010/kill_makes_use_of
Implements a make_use_of function that automatically
2 parents 0739d39 + 012af14 commit 8793e58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+287
-311
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ docker-compose.yml
119119
# Mypy files
120120
.mypy_cache/
121121

122+
test_outputs/classifier_test.yaml
122123
test_outputs/stochastic_tournament_0.csv
123124
test_outputs/stochastic_tournament_1.csv
124125
test_outputs/test_fingerprint.csv

axelrod/classifier.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
Union,
1414
)
1515

16-
import yaml
16+
from axelrod.makes_use_of import makes_use_of
1717
from axelrod.player import Player
18+
import yaml
1819

1920
ALL_CLASSIFIERS_PATH = "data/all_classifiers.yml"
2021

@@ -59,12 +60,18 @@ def classify_player(self, player: Type[Player]) -> T:
5960

6061

6162
stochastic = Classifier[bool]("stochastic", lambda _: False)
62-
memory_depth = Classifier[Union[float, int]]("memory_depth", lambda _: float("inf"))
63-
makes_use_of = Classifier[Optional[Set[Text]]]("makes_use_of", lambda _: None)
63+
memory_depth = Classifier[Union[float, int]](
64+
"memory_depth", lambda _: float("inf")
65+
)
66+
makes_use_of = Classifier[Optional[Set[Text]]]("makes_use_of", makes_use_of)
6467
long_run_time = Classifier[bool]("long_run_time", lambda _: False)
6568
inspects_source = Classifier[Optional[bool]]("inspects_source", lambda _: None)
66-
manipulates_source = Classifier[Optional[bool]]("manipulates_source", lambda _: None)
67-
manipulates_state = Classifier[Optional[bool]]("manipulates_state", lambda _: None)
69+
manipulates_source = Classifier[Optional[bool]](
70+
"manipulates_source", lambda _: None
71+
)
72+
manipulates_state = Classifier[Optional[bool]](
73+
"manipulates_state", lambda _: None
74+
)
6875

6976
# Should list all known classifiers.
7077
all_classifiers = [
@@ -77,6 +84,8 @@ def classify_player(self, player: Type[Player]) -> T:
7784
manipulates_state,
7885
]
7986

87+
all_classifiers_map = {c.name: c.classify_player for c in all_classifiers}
88+
8089

8190
def rebuild_classifier_table(
8291
classifiers: List[Classifier],
@@ -209,7 +218,13 @@ def try_lookup() -> Any:
209218
return player.classifier[key]
210219

211220
# Try to find the name in the all_player_dicts, read from disk.
212-
return try_lookup()
221+
lookup = try_lookup()
222+
if lookup is not None:
223+
return lookup
224+
225+
# If we can't find it, then return a function that calculates fresh.
226+
global all_classifiers_map
227+
return all_classifiers_map[key](player)
213228

214229
return classify_player_for_this_classifier
215230

0 commit comments

Comments
 (0)