building_calculator.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. """Calculate cost to reach total buidings level"""
  2. from rival_regions_calc import ConstructionCosts, Building
  3. PRICES = {
  4. 'cash': 0.7,
  5. 'gold': 0.45,
  6. 'oil': 250,
  7. 'ore': 230,
  8. 'diamond': 1700000,
  9. 'uranium': 2100
  10. }
  11. BUILDING_TYPES = {
  12. 'hospital': Building('hospital'),
  13. 'military base': Building('military base'),
  14. 'school': Building('school'),
  15. 'missile system': Building('missile system'),
  16. 'power plant': Building('power plant'),
  17. 'spaceport': Building('spaceport'),
  18. 'airport': Building('airport')
  19. }
  20. def main():
  21. """Main method"""
  22. buildings = {
  23. # palmer
  24. # 'hospital': 2516,
  25. # 'military base': 1800,
  26. # 'school': 2000,
  27. # 'missile system': 7745,
  28. # 'power plant': 2275,
  29. # 'spaceport': 1800,
  30. # 'airport': 7961
  31. # oost-nl
  32. # 'hospital': 2475,
  33. # 'military base': 1646,
  34. # 'school': 1565,
  35. # 'missile system': 4550,
  36. # 'power plant': 1461,
  37. # 'spaceport': 201,
  38. # 'airport': 3750,
  39. # noord-nl
  40. 'hospital': 2474,
  41. 'military base': 1645,
  42. 'school': 1564,
  43. 'missile system': 1200,
  44. 'power plant': 2570,
  45. 'spaceport': 4,
  46. 'airport': 2305
  47. }
  48. build_buildings = {
  49. 'hospital': 0,
  50. 'military base': 0,
  51. 'school': 0,
  52. 'missile system': 0,
  53. 'power plant': 0,
  54. 'spaceport': 0,
  55. 'airport': 0
  56. }
  57. total_buildings = sum(item for item in buildings.values())
  58. # building_goal = 36581 #5
  59. building_goal = 61300 #1
  60. total_price = 0
  61. required_buildings = building_goal - total_buildings
  62. power_surplus = 6198
  63. power_consumption = (total_buildings - buildings['power plant']) * 2
  64. power_production = buildings['power plant'] * 10
  65. for i in range(1, required_buildings + 1):
  66. lowest_building_name = None
  67. lowest_building_price = 1000000000000000
  68. if power_consumption > power_production + power_surplus - 2:
  69. lowest_building_name = 'power plant'
  70. cc = ConstructionCosts(
  71. BUILDING_TYPES['power plant'],
  72. buildings['power plant'] + build_buildings['power plant']
  73. )
  74. cc.calculate(1)
  75. lowest_building_price = sum_building_cost(cc)
  76. else:
  77. for building_name in BUILDING_TYPES:
  78. cc = ConstructionCosts(
  79. BUILDING_TYPES[building_name],
  80. buildings[building_name] + build_buildings[building_name]
  81. )
  82. cc.calculate(1)
  83. price = sum_building_cost(cc)
  84. if price <= lowest_building_price:
  85. lowest_building_price = price
  86. lowest_building_name = building_name
  87. if lowest_building_name == 'power plant':
  88. power_production += 10
  89. else:
  90. power_consumption += 2
  91. build_buildings[lowest_building_name] += 1
  92. total_price += lowest_building_price
  93. total_build = sum(item for item in build_buildings.values())
  94. total_resources = {
  95. 'cash': 0,
  96. 'gold': 0,
  97. 'oil': 0,
  98. 'ore': 0,
  99. 'diamond': 0,
  100. 'uranium': 0
  101. }
  102. print('—'*53)
  103. for resource_name, price in PRICES.items():
  104. print('{:8}: {:12,.2f}'.format(resource_name, price))
  105. for building_name, build in build_buildings.items():
  106. if build == 0:
  107. continue
  108. print('—'*53)
  109. print('{}: +{}'.format(building_name, build))
  110. cc = ConstructionCosts(
  111. BUILDING_TYPES[building_name],
  112. buildings[building_name]
  113. )
  114. cc.calculate(build)
  115. total_resources['cash'] += cc.cash
  116. total_resources['gold'] += cc.gold
  117. total_resources['oil'] += cc.oil
  118. total_resources['ore'] += cc.ore
  119. total_resources['uranium'] += cc.uranium
  120. total_resources['diamond'] += cc.diamond
  121. print('{:8} {:20,} {:20,} $'.format(
  122. 'cash', cc.cash,
  123. round(cc.cash * PRICES['cash'])
  124. ))
  125. print('{:8} {:20,} {:20,} $'.format(
  126. 'gold', cc.gold,
  127. round(cc.gold * PRICES['gold'])
  128. ))
  129. print('{:8} {:20,} {:20,} $'.format(
  130. 'oil', cc.oil,
  131. round(cc.oil * PRICES['oil'])
  132. ))
  133. print('{:8} {:20,} {:20,} $'.format(
  134. 'ore', cc.ore,
  135. round(cc.ore * PRICES['ore'])
  136. ))
  137. print('{:8} {:20,} {:20,} $'.format(
  138. 'uranium', cc.uranium,
  139. round(cc.uranium * PRICES['uranium'])
  140. ))
  141. print('{:8} {:20,} {:20,} $'.format(
  142. 'diamond', cc.diamond,
  143. round(cc.diamond * PRICES['diamond'])
  144. ))
  145. print('total {:23} {:20,} $'.format(
  146. building_name,
  147. round(sum_building_cost(cc))))
  148. print('—'*53)
  149. print('total')
  150. print('{:8} {:20,} {:20,} $'.format(
  151. 'cash', total_resources['cash'],
  152. round(total_resources['cash'] * PRICES['cash'])
  153. ))
  154. print('{:8} {:20,} {:20,} $'.format(
  155. 'gold', total_resources['gold'],
  156. round(total_resources['gold'] * PRICES['gold'])
  157. ))
  158. print('{:8} {:20,} {:20,} $'.format(
  159. 'oil', total_resources['oil'],
  160. round(total_resources['oil'] * PRICES['oil'])
  161. ))
  162. print('{:8} {:20,} {:20,} $'.format(
  163. 'ore', total_resources['ore'],
  164. round(total_resources['ore'] * PRICES['ore'])
  165. ))
  166. print('{:8} {:20,} {:20,} $'.format(
  167. 'uranium', total_resources['uranium'],
  168. round(total_resources['uranium'] * PRICES['uranium'])
  169. ))
  170. print('{:8} {:20,} {:20,} $'.format(
  171. 'diamond', total_resources['diamond'],
  172. round(total_resources['diamond'] * PRICES['diamond'])
  173. ))
  174. print('total {:44,} $'.format(round(total_price)))
  175. print('—'*53)
  176. print('buildings')
  177. print('orginal : {:,}'.format(total_buildings))
  178. print('build : {:,}'.format(total_build))
  179. print('total : {:,}'.format(building_goal))
  180. print('—'*53)
  181. power_difference = power_production - power_consumption + power_surplus
  182. print('power')
  183. print('orignal production : {:6}'.format(buildings['power plant'] * 10))
  184. print('extra production : {:6}'.format(build_buildings['power plant'] * 10))
  185. print('total production : {:6}'.format(power_production))
  186. print('consumption : {:6}'.format(power_consumption))
  187. print('surplus : {:6}'.format(power_surplus))
  188. print('difference : {:6}'.format(power_difference))
  189. def sum_building_cost(cc):
  190. """Sum building costs"""
  191. return cc.cash * PRICES['cash'] + \
  192. cc.gold * PRICES['gold'] + \
  193. cc.oil * PRICES['oil'] + \
  194. cc.ore * PRICES['ore'] + \
  195. cc.diamond * PRICES['diamond'] + \
  196. cc.uranium * PRICES['uranium']
  197. if __name__ == "__main__":
  198. main()