From 83e4ffbdf1b4aa58af505a17929ac166d495c8c2 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Wed, 14 Feb 2024 23:33:18 -0800 Subject: [PATCH] start testing out target groups --- calc2.py | 81 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/calc2.py b/calc2.py index bff286c..c6bf5b2 100644 --- a/calc2.py +++ b/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}')