Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Created August 26, 2013 21:17
Show Gist options
  • Save yanmhlv/6346764 to your computer and use it in GitHub Desktop.
Save yanmhlv/6346764 to your computer and use it in GitHub Desktop.
# coding: utf-8
field = [
{'cost': 10, 'prod': 2, 'time': 3},
{'cost': 20, 'prod': 3, 'time': 4}
]
total_resource, base_production, total_time = 0, 1, 0
lvl = 0
required_lvl = len(field)
while True:
if total_resource - field[lvl]['cost'] < 0:
total_time, total_resource = total_time + 1, total_resource + base_production
print 'continue tic', total_resource, total_time, base_production
continue
total_resource -= field[lvl]['cost'] # вычитаем стоймость постройки
total_time += field[lvl]['time'] # время строительства
total_resource += field[lvl]['prod'] * field[lvl]['time'] # ресурсы, которые набегут за время строительства
base_production += field[lvl]['prod']
lvl += 1
print 'build tic', total_resource, total_time, base_production
if lvl == required_lvl:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment