ss14_chemistry_site/reworked/calc.py

40 lines
960 B
Python
Raw Normal View History

def expand_recipe(recipe, recipes):
2024-05-01 12:07:43 +00:00
global expanded
ok = False
part = 1 # Одна часть
2024-05-01 12:07:43 +00:00
while not ok:
ok = True
# Перебираем элементы
2024-05-01 12:07:43 +00:00
for el in recipe:
# Если составное
2024-05-01 12:07:43 +00:00
if el in recipes:
# Одна часть должна делиться без остатка!
2024-05-01 12:07:43 +00:00
if part % recipes[el].out != 0:
ok = False
part += 1
expanded = {}
break
else:
expand_recipe(recipes[el].comps, recipes)
else:
if el in expanded:
expanded[el] += recipe[el]*part
else:
expanded[el] = recipe[el]*part
def calc(element, amount, recipes):
# TODO: Пока только выводит расширенную версию рецепта
recipe, out = recipes[element].comps, recipes[element].out
global expanded
expanded = {}
expand_recipe(recipe, recipes)
2024-05-01 12:07:43 +00:00
return expanded
from parse import *
#print( load_recipes() )
print( calc('Dylovene', 100, load_recipes()) )