|  | @@ -0,0 +1,213 @@
 | 
	
		
			
				|  |  | +"""Calculate cost to reach total buidings level"""
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +from rival_regions_calc import ConstructionCosts, Building
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +PRICES = {
 | 
	
		
			
				|  |  | +    'cash': 0.7,
 | 
	
		
			
				|  |  | +    'gold': 0.45,
 | 
	
		
			
				|  |  | +    'oil': 250,
 | 
	
		
			
				|  |  | +    'ore': 230,
 | 
	
		
			
				|  |  | +    'diamond': 1700000,
 | 
	
		
			
				|  |  | +    'uranium': 2100
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +BUILDING_TYPES = {
 | 
	
		
			
				|  |  | +    'hospital': Building('hospital'),
 | 
	
		
			
				|  |  | +    'military base': Building('military base'),
 | 
	
		
			
				|  |  | +    'school': Building('school'),
 | 
	
		
			
				|  |  | +    'missile system': Building('missile system'),
 | 
	
		
			
				|  |  | +    'power plant': Building('power plant'),
 | 
	
		
			
				|  |  | +    'spaceport': Building('spaceport'),
 | 
	
		
			
				|  |  | +    'airport': Building('airport')
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def main():
 | 
	
		
			
				|  |  | +    """Main method"""
 | 
	
		
			
				|  |  | +    buildings = {
 | 
	
		
			
				|  |  | +# palmer
 | 
	
		
			
				|  |  | +#        'hospital': 2516,
 | 
	
		
			
				|  |  | +#        'military base': 1800,
 | 
	
		
			
				|  |  | +#        'school': 2000,
 | 
	
		
			
				|  |  | +#        'missile system': 7745,
 | 
	
		
			
				|  |  | +#        'power plant': 2275,
 | 
	
		
			
				|  |  | +#        'spaceport': 1800,
 | 
	
		
			
				|  |  | +#        'airport': 7961
 | 
	
		
			
				|  |  | +# oost-nl
 | 
	
		
			
				|  |  | +#        'hospital': 2475,
 | 
	
		
			
				|  |  | +#        'military base': 1646,
 | 
	
		
			
				|  |  | +#        'school': 1565,
 | 
	
		
			
				|  |  | +#        'missile system': 4550,
 | 
	
		
			
				|  |  | +#        'power plant': 1461,
 | 
	
		
			
				|  |  | +#        'spaceport': 201,
 | 
	
		
			
				|  |  | +#        'airport': 3750,
 | 
	
		
			
				|  |  | +# noord-nl
 | 
	
		
			
				|  |  | +        'hospital': 2474,
 | 
	
		
			
				|  |  | +        'military base': 1645,
 | 
	
		
			
				|  |  | +        'school': 1564,
 | 
	
		
			
				|  |  | +        'missile system': 1200,
 | 
	
		
			
				|  |  | +        'power plant': 2570,
 | 
	
		
			
				|  |  | +        'spaceport': 4,
 | 
	
		
			
				|  |  | +        'airport': 2305
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    build_buildings = {
 | 
	
		
			
				|  |  | +        'hospital': 0,
 | 
	
		
			
				|  |  | +        'military base': 0,
 | 
	
		
			
				|  |  | +        'school': 0,
 | 
	
		
			
				|  |  | +        'missile system': 0,
 | 
	
		
			
				|  |  | +        'power plant': 0,
 | 
	
		
			
				|  |  | +        'spaceport': 0,
 | 
	
		
			
				|  |  | +        'airport': 0
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    total_buildings = sum(item for item in buildings.values())
 | 
	
		
			
				|  |  | +    # building_goal = 36581 #5
 | 
	
		
			
				|  |  | +    building_goal = 61300 #1
 | 
	
		
			
				|  |  | +    total_price = 0
 | 
	
		
			
				|  |  | +    required_buildings = building_goal - total_buildings
 | 
	
		
			
				|  |  | +    power_surplus = 6198
 | 
	
		
			
				|  |  | +    power_consumption = (total_buildings - buildings['power plant']) * 2
 | 
	
		
			
				|  |  | +    power_production = buildings['power plant'] * 10
 | 
	
		
			
				|  |  | +    for i in range(1, required_buildings + 1):
 | 
	
		
			
				|  |  | +        lowest_building_name = None
 | 
	
		
			
				|  |  | +        lowest_building_price = 1000000000000000
 | 
	
		
			
				|  |  | +        if power_consumption > power_production + power_surplus - 2:
 | 
	
		
			
				|  |  | +            lowest_building_name = 'power plant'
 | 
	
		
			
				|  |  | +            cc = ConstructionCosts(
 | 
	
		
			
				|  |  | +                BUILDING_TYPES['power plant'],
 | 
	
		
			
				|  |  | +                buildings['power plant'] + build_buildings['power plant']
 | 
	
		
			
				|  |  | +            )
 | 
	
		
			
				|  |  | +            cc.calculate(1)
 | 
	
		
			
				|  |  | +            lowest_building_price = sum_building_cost(cc)         
 | 
	
		
			
				|  |  | +        else:
 | 
	
		
			
				|  |  | +            for building_name in BUILDING_TYPES:
 | 
	
		
			
				|  |  | +                cc = ConstructionCosts(
 | 
	
		
			
				|  |  | +                    BUILDING_TYPES[building_name],
 | 
	
		
			
				|  |  | +                    buildings[building_name] + build_buildings[building_name]
 | 
	
		
			
				|  |  | +                )
 | 
	
		
			
				|  |  | +                cc.calculate(1)
 | 
	
		
			
				|  |  | +                price = sum_building_cost(cc)         
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if price <= lowest_building_price:
 | 
	
		
			
				|  |  | +                    lowest_building_price = price
 | 
	
		
			
				|  |  | +                    lowest_building_name = building_name
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if lowest_building_name == 'power plant':
 | 
	
		
			
				|  |  | +            power_production += 10
 | 
	
		
			
				|  |  | +        else:
 | 
	
		
			
				|  |  | +            power_consumption += 2
 | 
	
		
			
				|  |  | +        build_buildings[lowest_building_name] += 1
 | 
	
		
			
				|  |  | +        total_price += lowest_building_price
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    total_build = sum(item for item in build_buildings.values())
 | 
	
		
			
				|  |  | +    total_resources = {
 | 
	
		
			
				|  |  | +        'cash': 0,
 | 
	
		
			
				|  |  | +        'gold': 0,
 | 
	
		
			
				|  |  | +        'oil': 0,
 | 
	
		
			
				|  |  | +        'ore': 0,
 | 
	
		
			
				|  |  | +        'diamond': 0,
 | 
	
		
			
				|  |  | +        'uranium': 0
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    print('—'*53)
 | 
	
		
			
				|  |  | +    for resource_name, price in PRICES.items():
 | 
	
		
			
				|  |  | +        print('{:8}: {:12,.2f}'.format(resource_name, price))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    for building_name, build in build_buildings.items():
 | 
	
		
			
				|  |  | +        if build == 0:
 | 
	
		
			
				|  |  | +            continue
 | 
	
		
			
				|  |  | +        print('—'*53)
 | 
	
		
			
				|  |  | +        print('{}: +{}'.format(building_name, build))
 | 
	
		
			
				|  |  | +        cc = ConstructionCosts(
 | 
	
		
			
				|  |  | +            BUILDING_TYPES[building_name],
 | 
	
		
			
				|  |  | +            buildings[building_name]
 | 
	
		
			
				|  |  | +        )
 | 
	
		
			
				|  |  | +        cc.calculate(build)
 | 
	
		
			
				|  |  | +        total_resources['cash'] += cc.cash
 | 
	
		
			
				|  |  | +        total_resources['gold'] += cc.gold
 | 
	
		
			
				|  |  | +        total_resources['oil'] += cc.oil
 | 
	
		
			
				|  |  | +        total_resources['ore'] += cc.ore
 | 
	
		
			
				|  |  | +        total_resources['uranium'] += cc.uranium
 | 
	
		
			
				|  |  | +        total_resources['diamond'] += cc.diamond
 | 
	
		
			
				|  |  | +        print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +            'cash', cc.cash,
 | 
	
		
			
				|  |  | +            round(cc.cash * PRICES['cash'])
 | 
	
		
			
				|  |  | +        ))
 | 
	
		
			
				|  |  | +        print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +            'gold', cc.gold,
 | 
	
		
			
				|  |  | +            round(cc.gold * PRICES['gold'])
 | 
	
		
			
				|  |  | +        ))
 | 
	
		
			
				|  |  | +        print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +            'oil', cc.oil,
 | 
	
		
			
				|  |  | +            round(cc.oil * PRICES['oil'])
 | 
	
		
			
				|  |  | +        ))
 | 
	
		
			
				|  |  | +        print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +            'ore', cc.ore,
 | 
	
		
			
				|  |  | +            round(cc.ore * PRICES['ore'])
 | 
	
		
			
				|  |  | +        ))
 | 
	
		
			
				|  |  | +        print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +            'uranium', cc.uranium,
 | 
	
		
			
				|  |  | +            round(cc.uranium * PRICES['uranium'])
 | 
	
		
			
				|  |  | +        ))
 | 
	
		
			
				|  |  | +        print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +            'diamond', cc.diamond,
 | 
	
		
			
				|  |  | +            round(cc.diamond * PRICES['diamond'])
 | 
	
		
			
				|  |  | +        ))
 | 
	
		
			
				|  |  | +        print('total {:23} {:20,} $'.format(
 | 
	
		
			
				|  |  | +            building_name,
 | 
	
		
			
				|  |  | +            round(sum_building_cost(cc))))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    print('—'*53)
 | 
	
		
			
				|  |  | +    print('total')
 | 
	
		
			
				|  |  | +    print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +        'cash', total_resources['cash'],
 | 
	
		
			
				|  |  | +        round(total_resources['cash'] * PRICES['cash'])
 | 
	
		
			
				|  |  | +    ))
 | 
	
		
			
				|  |  | +    print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +        'gold', total_resources['gold'],
 | 
	
		
			
				|  |  | +        round(total_resources['gold'] * PRICES['gold'])
 | 
	
		
			
				|  |  | +    ))
 | 
	
		
			
				|  |  | +    print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +        'oil', total_resources['oil'],
 | 
	
		
			
				|  |  | +        round(total_resources['oil'] * PRICES['oil'])
 | 
	
		
			
				|  |  | +    ))
 | 
	
		
			
				|  |  | +    print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +        'ore', total_resources['ore'],
 | 
	
		
			
				|  |  | +        round(total_resources['ore'] * PRICES['ore'])
 | 
	
		
			
				|  |  | +    ))
 | 
	
		
			
				|  |  | +    print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +        'uranium', total_resources['uranium'],
 | 
	
		
			
				|  |  | +        round(total_resources['uranium'] * PRICES['uranium'])
 | 
	
		
			
				|  |  | +    ))
 | 
	
		
			
				|  |  | +    print('{:8} {:20,} {:20,} $'.format(
 | 
	
		
			
				|  |  | +        'diamond', total_resources['diamond'],
 | 
	
		
			
				|  |  | +        round(total_resources['diamond'] * PRICES['diamond'])
 | 
	
		
			
				|  |  | +    ))
 | 
	
		
			
				|  |  | +    print('total {:44,} $'.format(round(total_price)))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    print('—'*53)
 | 
	
		
			
				|  |  | +    print('buildings')
 | 
	
		
			
				|  |  | +    print('orginal            : {:,}'.format(total_buildings))
 | 
	
		
			
				|  |  | +    print('build              : {:,}'.format(total_build))
 | 
	
		
			
				|  |  | +    print('total              : {:,}'.format(building_goal))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    print('—'*53)
 | 
	
		
			
				|  |  | +    power_difference = power_production - power_consumption + power_surplus
 | 
	
		
			
				|  |  | +    print('power')
 | 
	
		
			
				|  |  | +    print('orignal production : {:6}'.format(buildings['power plant'] * 10))
 | 
	
		
			
				|  |  | +    print('extra production   : {:6}'.format(build_buildings['power plant'] * 10))
 | 
	
		
			
				|  |  | +    print('total production   : {:6}'.format(power_production))
 | 
	
		
			
				|  |  | +    print('consumption        : {:6}'.format(power_consumption))
 | 
	
		
			
				|  |  | +    print('surplus            : {:6}'.format(power_surplus))
 | 
	
		
			
				|  |  | +    print('difference         : {:6}'.format(power_difference))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def sum_building_cost(cc):
 | 
	
		
			
				|  |  | +    """Sum building costs"""
 | 
	
		
			
				|  |  | +    return cc.cash * PRICES['cash'] + \
 | 
	
		
			
				|  |  | +        cc.gold * PRICES['gold'] + \
 | 
	
		
			
				|  |  | +        cc.oil * PRICES['oil'] + \
 | 
	
		
			
				|  |  | +        cc.ore * PRICES['ore'] + \
 | 
	
		
			
				|  |  | +        cc.diamond * PRICES['diamond'] + \
 | 
	
		
			
				|  |  | +        cc.uranium * PRICES['uranium']
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +if __name__ == "__main__":
 | 
	
		
			
				|  |  | +    main()
 |