Skip to content

Implements a make_use_of function that automatically #1355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ docker-compose.yml
# Mypy files
.mypy_cache/

test_outputs/classifier_test.yaml
test_outputs/stochastic_tournament_0.csv
test_outputs/stochastic_tournament_1.csv
test_outputs/test_fingerprint.csv
Expand Down
27 changes: 21 additions & 6 deletions axelrod/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
Union,
)

import yaml
from axelrod.makes_use_of import makes_use_of
from axelrod.player import Player
import yaml

ALL_CLASSIFIERS_PATH = "data/all_classifiers.yml"

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


stochastic = Classifier[bool]("stochastic", lambda _: False)
memory_depth = Classifier[Union[float, int]]("memory_depth", lambda _: float("inf"))
makes_use_of = Classifier[Optional[Set[Text]]]("makes_use_of", lambda _: None)
memory_depth = Classifier[Union[float, int]](
"memory_depth", lambda _: float("inf")
)
makes_use_of = Classifier[Optional[Set[Text]]]("makes_use_of", makes_use_of)
long_run_time = Classifier[bool]("long_run_time", lambda _: False)
inspects_source = Classifier[Optional[bool]]("inspects_source", lambda _: None)
manipulates_source = Classifier[Optional[bool]]("manipulates_source", lambda _: None)
manipulates_state = Classifier[Optional[bool]]("manipulates_state", lambda _: None)
manipulates_source = Classifier[Optional[bool]](
"manipulates_source", lambda _: None
)
manipulates_state = Classifier[Optional[bool]](
"manipulates_state", lambda _: None
)

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

all_classifiers_map = {c.name: c.classify_player for c in all_classifiers}


def rebuild_classifier_table(
classifiers: List[Classifier],
Expand Down Expand Up @@ -209,7 +218,13 @@ def try_lookup() -> Any:
return player.classifier[key]

# Try to find the name in the all_player_dicts, read from disk.
return try_lookup()
lookup = try_lookup()
if lookup is not None:
return lookup

# If we can't find it, then return a function that calculates fresh.
global all_classifiers_map
return all_classifiers_map[key](player)

return classify_player_for_this_classifier

Expand Down
Loading