From e50db6103078f247493eb8f5ab70b375b07bdf54 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 10 May 2021 02:33:54 +0200 Subject: [PATCH] constrict Factorio logic to require all paths to a product, not any. Should narrow this down in a careful manner later. --- worlds/factorio/Technologies.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/worlds/factorio/Technologies.py b/worlds/factorio/Technologies.py index d6302c7f..188c240b 100644 --- a/worlds/factorio/Technologies.py +++ b/worlds/factorio/Technologies.py @@ -108,15 +108,16 @@ for technology, data in raw.items(): del (raw) lookup_id_to_name: Dict[int, str] = {item_id: item_name for item_name, item_id in tech_table.items()} -all_product_sources: Dict[str, Recipe] = {} +all_product_sources: Dict[str, Set[Recipe]] = {} for recipe_name, recipe_data in raw_recipes.items(): # example: # "accumulator":{"ingredients":["iron-plate","battery"],"products":["accumulator"],"category":"crafting"} recipe = Recipe(recipe_name, recipe_data["category"], set(recipe_data["ingredients"]), set(recipe_data["products"])) - if recipe.products != recipe.ingredients: # prevents loop recipes like uranium centrifuging + if recipe.products != recipe.ingredients and "empty-barrel" not in recipe.products: # prevents loop recipes like uranium centrifuging for product_name in recipe.products: - all_product_sources[product_name] = recipe + all_product_sources.setdefault(product_name, set()).add(recipe) + # build requirements graph for all technology ingredients @@ -133,12 +134,14 @@ def recursively_get_unlocking_technologies(ingredient_name, _done=None) -> Set[T _done.add(ingredient_name) else: _done = {ingredient_name} - recipe = all_product_sources.get(ingredient_name) - if not recipe: + recipes = all_product_sources.get(ingredient_name) + if not recipes: return set() - current_technologies = recipe.unlocking_technologies.copy() - for ingredient_name in recipe.ingredients: - current_technologies |= recursively_get_unlocking_technologies(ingredient_name, _done) + current_technologies = set() + for recipe in recipes: + current_technologies |= recipe.unlocking_technologies + for ingredient_name in recipe.ingredients: + current_technologies |= recursively_get_unlocking_technologies(ingredient_name, _done) return current_technologies