Skip to content

Commit

Permalink
(Aegis) partial refactor to wrap paramter stuff with classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyangyi committed Oct 26, 2023
1 parent f6f2ef1 commit aac5af5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
10 changes: 5 additions & 5 deletions industry/lib/industry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def __init__(self, *, name, id=None, callbacks={}, **props):

@property
def dynamic_prop_variables(self):
ret = {}
ret = set()
for p in self._props.values():
if isinstance(p, SplitDefinition):
for v in p.variables:
ret[v] = VARLEN[v]
return list(ret.items())
ret.add(v)
return list(sorted(ret))

def resolve_props(self, parameters):
new_props = {}
Expand Down Expand Up @@ -75,8 +75,8 @@ def dynamic_definitions(self, all_choices, parameters, i=0):
else:
return []
ret = []
var_id, choices = all_choices[i]
for choice in range(choices):
var_id = all_choices[i]
for choice in range(VARLEN[var_id]):
parameters[var_id] = choice
actions = self.dynamic_definitions(all_choices, parameters, i + 1)
if len(actions) == 0:
Expand Down
74 changes: 44 additions & 30 deletions industry/lib/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,42 +176,56 @@ def index(self, name):
]
)

parameter_choices = [
("POLICY", ["AUTARKY", "SELF_SUFFICIENT", "FREE_TRADE", "EXPORT"]),
("BOOSTER", ["NONE", "UNIVERSAL", "GENERIC", "GENERIC_PASSENGERS"]),
(
"WORKFORCE",
[
"ABSTRACT",
"PROFESSIONAL",
"PROFESSIONAL_PASSENGERS",
"PROFESSIONAL_MAIL",
"PROFESSIONAL_TIRED",
"YETI",
"YETI_PASSENGERS",
"YETI_MAIL",
"YETI_TIRED",
],
),
("LAND_PORTS", ["ORGANIC", "LAND_ONLY", "BOTH", "SEA_ONLY"]),
("TOWN_GOODS", ["ORGANIC", "NONE", "SUBARCTIC", "SUBTROPICAL"]),
]

class SearchSpace:
def __init__(self, choices, parameter_list):
self.choices = choices
self.parameter_list = parameter_list

docs_parameter_choices = copy.deepcopy(parameter_choices)
def copy(self):
return SearchSpace(copy.deepcopy(self.choices), parameter_list)

def fix_docs_params(self, cat, options):
[(idx, all_options)] = [
(i, the_options) for i, (the_cat, the_options) in enumerate(self.choices) if the_cat == cat
]
assert all(o in all_options for o in options)
self.choices[idx] = (cat, options)

def fix_docs_params(cat, options):
[(idx, all_options)] = [
(i, the_options) for i, (the_cat, the_options) in enumerate(docs_parameter_choices) if the_cat == cat
]
assert all(o in all_options for o in options)
docs_parameter_choices[idx] = (cat, options)

parameter_choices = SearchSpace(
[
("POLICY", ["AUTARKY", "SELF_SUFFICIENT", "FREE_TRADE", "EXPORT"]),
("BOOSTER", ["NONE", "UNIVERSAL", "GENERIC", "GENERIC_PASSENGERS"]),
(
"WORKFORCE",
[
"ABSTRACT",
"PROFESSIONAL",
"PROFESSIONAL_PASSENGERS",
"PROFESSIONAL_MAIL",
"PROFESSIONAL_TIRED",
"YETI",
"YETI_PASSENGERS",
"YETI_MAIL",
"YETI_TIRED",
],
),
("LAND_PORTS", ["ORGANIC", "LAND_ONLY", "BOTH", "SEA_ONLY"]),
("TOWN_GOODS", ["ORGANIC", "NONE", "SUBARCTIC", "SUBTROPICAL"]),
],
parameter_list,
)


docs_parameter_choices = parameter_choices.copy()
docs_parameter_choices.fix_docs_params("WORKFORCE", ["ABSTRACT", "PROFESSIONAL", "YETI"])
docs_parameter_choices.fix_docs_params("LAND_PORTS", ["ORGANIC"])
docs_parameter_choices.fix_docs_params("TOWN_GOODS", ["ORGANIC"])


fix_docs_params("WORKFORCE", ["ABSTRACT", "PROFESSIONAL", "YETI"])
fix_docs_params("LAND_PORTS", ["ORGANIC"])
fix_docs_params("TOWN_GOODS", ["ORGANIC"])
parameter_choices = parameter_choices.choices
docs_parameter_choices = docs_parameter_choices.choices

PRESETS = {
"VANILLA": {
Expand Down

0 comments on commit aac5af5

Please sign in to comment.