building_calculator.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.35,
  6. 'oil': 250,
  7. 'ore': 220,
  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. # oost-nl
  40. 'hospital': 2546,
  41. 'military base': 1692,
  42. 'school': 1605,
  43. 'missile system': 4550,
  44. 'power plant': 1461,
  45. 'spaceport': 201,
  46. 'airport': 3750,
  47. # noord-nl
  48. # 'hospital': 2474,
  49. # 'military base': 1645,
  50. # 'school': 1564,
  51. # 'missile system': 1200,
  52. # 'power plant': 2570,
  53. # 'spaceport': 4,
  54. # 'airport': 2305
  55. }
  56. build_buildings = {
  57. 'hospital': 0,
  58. 'military base': 0,
  59. 'school': 0,
  60. 'missile system': 0,
  61. 'power plant': 0,
  62. 'spaceport': 0,
  63. 'airport': 0
  64. }
  65. total_buildings = sum(item for item in buildings.values())
  66. # building_goal = 37520 #5
  67. building_goal = 60500 #1
  68. total_price = 0
  69. required_buildings = building_goal - total_buildings
  70. power_surplus = 6198
  71. power_consumption = (total_buildings - buildings['power plant']) * 2
  72. power_production = buildings['power plant'] * 10
  73. for i in range(1, required_buildings + 1):
  74. lowest_building_name = None
  75. lowest_building_price = 1000000000000000
  76. if power_consumption > power_production + power_surplus - 2:
  77. lowest_building_name = 'power plant'
  78. cc = ConstructionCosts(
  79. BUILDING_TYPES['power plant'],
  80. buildings['power plant'] + build_buildings['power plant']
  81. )
  82. cc.calculate(1)
  83. lowest_building_price = sum_building_cost(cc)
  84. else:
  85. for building_name in BUILDING_TYPES:
  86. cc = ConstructionCosts(
  87. BUILDING_TYPES[building_name],
  88. buildings[building_name] + build_buildings[building_name]
  89. )
  90. cc.calculate(1)
  91. price = sum_building_cost(cc)
  92. if price <= lowest_building_price:
  93. lowest_building_price = price
  94. lowest_building_name = building_name
  95. if lowest_building_name == 'power plant':
  96. power_production += 10
  97. else:
  98. power_consumption += 2
  99. build_buildings[lowest_building_name] += 1
  100. total_price += lowest_building_price
  101. total_build = sum(item for item in build_buildings.values())
  102. total_resources = {
  103. 'cash': 0,
  104. 'gold': 0,
  105. 'oil': 0,
  106. 'ore': 0,
  107. 'diamond': 0,
  108. 'uranium': 0
  109. }
  110. print('—'*53)
  111. for resource_name, price in PRICES.items():
  112. print('{:8}: {:12,.2f}'.format(resource_name, price))
  113. for building_name, build in build_buildings.items():
  114. if build == 0:
  115. continue
  116. print('—'*53)
  117. print('{}: +{}'.format(building_name, build))
  118. cc = ConstructionCosts(
  119. BUILDING_TYPES[building_name],
  120. buildings[building_name]
  121. )
  122. cc.calculate(build)
  123. total_resources['cash'] += cc.cash
  124. total_resources['gold'] += cc.gold
  125. total_resources['oil'] += cc.oil
  126. total_resources['ore'] += cc.ore
  127. total_resources['uranium'] += cc.uranium
  128. total_resources['diamond'] += cc.diamond
  129. print('{:8} {:20,} {:20,} $'.format(
  130. 'cash', cc.cash,
  131. round(cc.cash * PRICES['cash'])
  132. ))
  133. print('{:8} {:20,} {:20,} $'.format(
  134. 'gold', cc.gold,
  135. round(cc.gold * PRICES['gold'])
  136. ))
  137. print('{:8} {:20,} {:20,} $'.format(
  138. 'oil', cc.oil,
  139. round(cc.oil * PRICES['oil'])
  140. ))
  141. print('{:8} {:20,} {:20,} $'.format(
  142. 'ore', cc.ore,
  143. round(cc.ore * PRICES['ore'])
  144. ))
  145. print('{:8} {:20,} {:20,} $'.format(
  146. 'uranium', cc.uranium,
  147. round(cc.uranium * PRICES['uranium'])
  148. ))
  149. print('{:8} {:20,} {:20,} $'.format(
  150. 'diamond', cc.diamond,
  151. round(cc.diamond * PRICES['diamond'])
  152. ))
  153. print('total {:23} {:20,} $'.format(
  154. building_name,
  155. round(sum_building_cost(cc))))
  156. print('—'*53)
  157. print('total')
  158. print('{:8} {:20,} {:20,} $'.format(
  159. 'cash', total_resources['cash'],
  160. round(total_resources['cash'] * PRICES['cash'])
  161. ))
  162. print('{:8} {:20,} {:20,} $'.format(
  163. 'gold', total_resources['gold'],
  164. round(total_resources['gold'] * PRICES['gold'])
  165. ))
  166. print('{:8} {:20,} {:20,} $'.format(
  167. 'oil', total_resources['oil'],
  168. round(total_resources['oil'] * PRICES['oil'])
  169. ))
  170. print('{:8} {:20,} {:20,} $'.format(
  171. 'ore', total_resources['ore'],
  172. round(total_resources['ore'] * PRICES['ore'])
  173. ))
  174. print('{:8} {:20,} {:20,} $'.format(
  175. 'uranium', total_resources['uranium'],
  176. round(total_resources['uranium'] * PRICES['uranium'])
  177. ))
  178. print('{:8} {:20,} {:20,} $'.format(
  179. 'diamond', total_resources['diamond'],
  180. round(total_resources['diamond'] * PRICES['diamond'])
  181. ))
  182. print('total {:44,} $'.format(round(total_price)))
  183. print('—'*53)
  184. print('buildings')
  185. print('orginal : {:,}'.format(total_buildings))
  186. print('build : {:,}'.format(total_build))
  187. print('total : {:,}'.format(building_goal))
  188. print('—'*53)
  189. power_difference = power_production - power_consumption + power_surplus
  190. print('power')
  191. print('orignal production : {:6}'.format(buildings['power plant'] * 10))
  192. print('extra production : {:6}'.format(build_buildings['power plant'] * 10))
  193. print('total production : {:6}'.format(power_production))
  194. print('consumption : {:6}'.format(power_consumption))
  195. print('surplus : {:6}'.format(power_surplus))
  196. print('difference : {:6}'.format(power_difference))
  197. def sum_building_cost(cc):
  198. """Sum building costs"""
  199. return cc.cash * PRICES['cash'] + \
  200. cc.gold * PRICES['gold'] + \
  201. cc.oil * PRICES['oil'] + \
  202. cc.ore * PRICES['ore'] + \
  203. cc.diamond * PRICES['diamond'] + \
  204. cc.uranium * PRICES['uranium']
  205. if __name__ == "__main__":
  206. main()