From ed4004344810b5b1c44f3fcbc78a9e01d6cbae9c Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Sat, 6 Nov 2021 11:49:03 -0700 Subject: [PATCH] Pick recipe with lowest energy cost for ingredient. --- worlds/factorio/Technologies.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/worlds/factorio/Technologies.py b/worlds/factorio/Technologies.py index 74f5bbbd..04736a2e 100644 --- a/worlds/factorio/Technologies.py +++ b/worlds/factorio/Technologies.py @@ -156,10 +156,13 @@ class Recipe(FactorioElement): total_energy = self.energy for ingredient, cost in self.ingredients.items(): if ingredient in all_product_sources: - for ingredient_recipe in all_product_sources[ingredient]: # FIXME: this may select the wrong recipe + selected_recipe_energy = float('inf') + for ingredient_recipe in all_product_sources[ingredient]: craft_count = max((n for name, n in ingredient_recipe.products.items() if name == ingredient)) - total_energy += ingredient_recipe.total_energy / craft_count * cost - break + recipe_energy = ingredient_recipe.total_energy / craft_count * cost + if recipe_energy < selected_recipe_energy: + selected_recipe_energy = recipe_energy + total_energy += selected_recipe_energy return total_energy