Исправил баг, немного модифицировал.

main
justuser31 6 months ago
parent 5deaa5823e
commit 45ec9a1157

@ -1,6 +1,8 @@
global expanded ; expanded = {} global expanded
def expand_recipe(recipe, recipes, main = False): def expand_recipe(recipe, recipes, main = False):
global expanded global expanded
if main:
expanded = {}
ok = False ok = False
part = 1 # Одна часть part = 1 # Одна часть
@ -34,19 +36,15 @@ def expand_recipe(recipe, recipes, main = False):
def calc(element, amount, recipes): def calc(element, amount, recipes):
# Получаем характеристику элемента # Получаем характеристику элемента
recipe, out = recipes[element].comps, recipes[element].out recipe, vol_out = recipes[element].comps, recipes[element].out
# Расчитываем минимальный рецепт # Расчитываем минимальный рецепт
expanded, vol, part = expand_recipe(recipe, recipes, True) expanded, vol_in, part = expand_recipe(recipe, recipes, True)
# Домнажаем на сколько нужно need = amount//vol_in
need = amount//vol
for i in expanded: for i in expanded:
expanded[i] = expanded[i]*need expanded[i] = expanded[i]*need
out = part*out*need vol_in *= need
vol_out *= part*need
return expanded, out
return expanded, vol_in, vol_out
from parse import *
#print( load_recipes() )
print( calc('Leporazine', 100, load_recipes()) )

Loading…
Cancel
Save