13
13
Union ,
14
14
)
15
15
16
- import yaml
16
+ from axelrod . makes_use_of import makes_use_of
17
17
from axelrod .player import Player
18
+ import yaml
18
19
19
20
ALL_CLASSIFIERS_PATH = "data/all_classifiers.yml"
20
21
@@ -59,12 +60,18 @@ def classify_player(self, player: Type[Player]) -> T:
59
60
60
61
61
62
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 )
64
67
long_run_time = Classifier [bool ]("long_run_time" , lambda _ : False )
65
68
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
+ )
68
75
69
76
# Should list all known classifiers.
70
77
all_classifiers = [
@@ -77,6 +84,8 @@ def classify_player(self, player: Type[Player]) -> T:
77
84
manipulates_state ,
78
85
]
79
86
87
+ all_classifiers_map = {c .name : c .classify_player for c in all_classifiers }
88
+
80
89
81
90
def rebuild_classifier_table (
82
91
classifiers : List [Classifier ],
@@ -209,7 +218,13 @@ def try_lookup() -> Any:
209
218
return player .classifier [key ]
210
219
211
220
# 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 )
213
228
214
229
return classify_player_for_this_classifier
215
230
0 commit comments