start testing out target groups
This commit is contained in:
parent
abb16eae6d
commit
83e4ffbdf1
81
calc2.py
81
calc2.py
@ -1,4 +1,4 @@
|
||||
from pprint import pprint
|
||||
from pprint import pformat, pprint
|
||||
|
||||
recipies: dict[str, dict[str, float]] = {
|
||||
# mining
|
||||
@ -137,26 +137,19 @@ recipies: dict[str, dict[str, float]] = {
|
||||
}
|
||||
|
||||
|
||||
# add [recipe-name] to "assembler" keys
|
||||
def get_resource_name(orig_name: str, recipe_name: str) -> str:
|
||||
if orig_name in {'assembler', 'chemical-plant', 'oil-refinery'}:
|
||||
return f'{orig_name}[{recipe_name}]'
|
||||
else:
|
||||
return orig_name
|
||||
|
||||
|
||||
def add_assembler_name(recipe_name: str, resources: dict[str, float]) -> dict[str, float]:
|
||||
return {
|
||||
resource if resource != 'assembler' else f'assembler[{recipe_name}]': count
|
||||
for resource, count in resources.items()
|
||||
}
|
||||
return {get_resource_name(resource, recipe_name): count for resource, count in resources.items()}
|
||||
|
||||
|
||||
recipies = {name: add_assembler_name(name, resources) for name, resources in recipies.items()}
|
||||
|
||||
SPM = 1
|
||||
targets: dict[str, float] = {
|
||||
'science-red': SPM,
|
||||
}
|
||||
|
||||
base_resources = {
|
||||
'iron-plate',
|
||||
'copper-plate',
|
||||
}
|
||||
|
||||
|
||||
def add_recipe(targets: dict[str, float], recipe: dict[str, float], multiplier: float) -> dict[str, float]:
|
||||
return {
|
||||
@ -166,20 +159,50 @@ def add_recipe(targets: dict[str, float], recipe: dict[str, float], multiplier:
|
||||
}
|
||||
|
||||
|
||||
results = {}
|
||||
def compute_base_resource_flow(targets: dict[str, float], base_resources: set[str]) -> dict[str, float]:
|
||||
results = {}
|
||||
|
||||
while len(targets) > 0:
|
||||
print(targets)
|
||||
resource, count = next(iter(targets.items()))
|
||||
while len(targets) > 0:
|
||||
resource, count = next(iter(targets.items()))
|
||||
# print(f'{resource}: {count}')
|
||||
|
||||
if resource in base_resources or resource.startswith('assembler'):
|
||||
results = add_recipe(results, {resource: count}, -1)
|
||||
del targets[resource]
|
||||
continue
|
||||
if resource in base_resources or '[' in resource:
|
||||
results = add_recipe(results, {resource: count}, -1)
|
||||
del targets[resource]
|
||||
continue
|
||||
|
||||
recipe = recipies[resource]
|
||||
multiplier = count / recipe[resource]
|
||||
targets = add_recipe(targets, recipe, multiplier)
|
||||
recipe = recipies[resource]
|
||||
multiplier = count / recipe[resource]
|
||||
targets = add_recipe(targets, recipe, multiplier)
|
||||
|
||||
print()
|
||||
print(results)
|
||||
return results
|
||||
|
||||
|
||||
SPM = 1
|
||||
targets_groups: list[dict[str, float]] = [
|
||||
{'science-red': SPM},
|
||||
{'science-green': SPM},
|
||||
{'science-gray': SPM},
|
||||
{'science-blue': SPM},
|
||||
]
|
||||
base_resources = {
|
||||
'iron-plate',
|
||||
'copper-plate',
|
||||
'stone',
|
||||
'stone-brick',
|
||||
'coal',
|
||||
'steel',
|
||||
'sulfur',
|
||||
'plastic',
|
||||
}
|
||||
|
||||
# TODO: science-blue is wrong
|
||||
|
||||
print(f'{SPM=}')
|
||||
print(f'{base_resources=}')
|
||||
for targets in targets_groups:
|
||||
print()
|
||||
print(f'{targets=}')
|
||||
results = compute_base_resource_flow(targets, base_resources)
|
||||
for resource, count in sorted(results.items()):
|
||||
print(f'{resource:30}: {count:.3g}')
|
||||
|
Loading…
Reference in New Issue
Block a user