start testing out target groups
This commit is contained in:
parent
abb16eae6d
commit
83e4ffbdf1
67
calc2.py
67
calc2.py
@ -1,4 +1,4 @@
|
|||||||
from pprint import pprint
|
from pprint import pformat, pprint
|
||||||
|
|
||||||
recipies: dict[str, dict[str, float]] = {
|
recipies: dict[str, dict[str, float]] = {
|
||||||
# mining
|
# 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]:
|
def add_assembler_name(recipe_name: str, resources: dict[str, float]) -> dict[str, float]:
|
||||||
return {
|
return {get_resource_name(resource, recipe_name): count for resource, count in resources.items()}
|
||||||
resource if resource != 'assembler' else f'assembler[{recipe_name}]': count
|
|
||||||
for resource, count in resources.items()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
recipies = {name: add_assembler_name(name, resources) for name, resources in recipies.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]:
|
def add_recipe(targets: dict[str, float], recipe: dict[str, float], multiplier: float) -> dict[str, float]:
|
||||||
return {
|
return {
|
||||||
@ -166,13 +159,14 @@ 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:
|
while len(targets) > 0:
|
||||||
print(targets)
|
|
||||||
resource, count = next(iter(targets.items()))
|
resource, count = next(iter(targets.items()))
|
||||||
|
# print(f'{resource}: {count}')
|
||||||
|
|
||||||
if resource in base_resources or resource.startswith('assembler'):
|
if resource in base_resources or '[' in resource:
|
||||||
results = add_recipe(results, {resource: count}, -1)
|
results = add_recipe(results, {resource: count}, -1)
|
||||||
del targets[resource]
|
del targets[resource]
|
||||||
continue
|
continue
|
||||||
@ -181,5 +175,34 @@ while len(targets) > 0:
|
|||||||
multiplier = count / recipe[resource]
|
multiplier = count / recipe[resource]
|
||||||
targets = add_recipe(targets, recipe, multiplier)
|
targets = add_recipe(targets, recipe, multiplier)
|
||||||
|
|
||||||
print()
|
return results
|
||||||
print(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