mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-01-18 16:58:48 +00:00
Новый алгоритм, ура.
This commit is contained in:
parent
d7296528b2
commit
0d3bd86b2c
36
reworked/calc.py
Normal file
36
reworked/calc.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
def expand_recipe(recipe, recipes, main = False):
|
||||||
|
global expanded
|
||||||
|
|
||||||
|
ok = False
|
||||||
|
part = 1
|
||||||
|
while not ok:
|
||||||
|
ok = True
|
||||||
|
for el in recipe:
|
||||||
|
if el in recipes:
|
||||||
|
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, True)
|
||||||
|
|
||||||
|
return expanded
|
||||||
|
|
||||||
|
|
||||||
|
from parse import *
|
||||||
|
#print( load_recipes() )
|
||||||
|
print( calc('Dylovene', 100, load_recipes()) )
|
Loading…
Reference in New Issue
Block a user