def update_variables(): gc = variables.gc ## **************************************** GENERAL **************************************** ## ## Constants variables.curr_round = gc.round() variables.num_enemies = 0 variables.print_count = 0 variables.research = gc.research_info() ## Battle locations variables.last_turn_battle_locs = variables.next_turn_battle_locs.copy() variables.next_turn_battle_locs = {} if variables.curr_round % 3 == 0: variables.update_quadrant_healer_loc = True else: variables.update_quadrant_healer_loc = False # variables.quadrant_battle_locs = {} ## Units variables.my_units = gc.my_units() variables.my_unit_ids = set([unit.id for unit in variables.my_units]) variables.units = gc.units() num_workers= num_knights=num_rangers= num_mages= num_healers= num_factory= num_rocket = 0 if variables.ranged_enemies >= 5: variables.ranged_enemies = 5 else: variables.ranged_enemies = 0 if variables.switch_to_rangers: current = gc.research_info() if current.get_level(variables.unit_types["knight"]) < 2: gc.reset_research() if variables.curr_planet == bc.Planet.Earth and len(variables.dists) == 0: gc.queue_research(bc.UnitType.Rocket) if current.get_level(variables.unit_types["worker"]) != 1: gc.queue_research(bc.UnitType.Worker) if current.get_level(variables.unit_types["ranger"]) != 1: gc.queue_research(bc.UnitType.Ranger) # 25: 50 gc.queue_research(bc.UnitType.Healer) # 25: 75 if current.get_level(variables.unit_types["rocket"]) != 1: gc.queue_research(bc.UnitType.Rocket) # 50: 125 gc.queue_research(bc.UnitType.Healer) # 100: 225 gc.queue_research(bc.UnitType.Healer) # 100: 325 gc.queue_research(bc.UnitType.Ranger) # 100: 425 gc.queue_research(bc.UnitType.Ranger) # 200: 625 gc.queue_research(bc.UnitType.Worker) # 75: 700 variables.switch_to_rangers = False # Update which ally unit id's are still alive & deaths per quadrant # start_time = time.time() update_quadrants() # Updates enemies in quadrant & resets num dead allies # print('update quadrants time: ', time.time()-start_time) if variables.curr_planet == bc.Planet.Earth: quadrant_size = variables.earth_quadrant_size else: quadrant_size = variables.mars_quadrant_size remove = set() for unit_id in variables.unit_locations: if unit_id not in variables.my_unit_ids: remove.add(unit_id) for unit_id in remove: loc = variables.unit_locations[unit_id] del variables.unit_locations[unit_id] f_f_quad = (int(loc[0] / quadrant_size), int(loc[1] / quadrant_size)) variables.quadrant_battle_locs[f_f_quad].remove_ally(unit_id) # Update % health of fighting allies in quadrant for quadrant in variables.quadrant_battle_locs: q_info = variables.quadrant_battle_locs[quadrant] q_info.update_ally_health_coefficient(gc) # Something something enemies for poss_enemy in variables.units: if poss_enemy.team != variables.my_team and poss_enemy.unit_type in variables.attacker: variables.num_enemies += 1 # Update num of ally units of each type unit_types = variables.unit_types variables.producing = [0, 0, 0, 0, 0] variables.in_order_units = [] workers = [] rangers = [] knights = [] mages = [] healers = [] factories = [] rockets = [] for unit in variables.my_units: if unit.unit_type == unit_types["worker"]: num_workers+=1 workers.append(unit) elif unit.unit_type == unit_types["knight"]: num_knights+=1 rangers.append(unit) elif unit.unit_type == unit_types["ranger"]: num_rangers+=1 knights.append(unit) elif unit.unit_type == unit_types["mage"]: num_mages+=1 mages.append(unit) elif unit.unit_type == unit_types["healer"]: num_healers+=1 healers.append(unit) elif unit.unit_type == unit_types["factory"]: num_factory+=1 factories.append(unit) if unit.is_factory_producing(): type = unit.factory_unit_type() if type == variables.unit_types["worker"]: variables.producing[0]+=1 elif type == variables.unit_types["knight"]: variables.producing[1]+=1 elif type == variables.unit_types["ranger"]: variables.producing[2]+=1 elif type == variables.unit_types["mage"]: variables.producing[3]+=1 else: variables.producing[4]+=1 elif unit.unit_type == unit_types["rocket"]: num_rocket+=1 rockets.append(unit) variables.info = [num_workers, num_knights, num_rangers, num_mages, num_healers, num_factory, num_rocket] variables.in_order_units.extend(rangers) variables.in_order_units.extend(workers) variables.in_order_units.extend(knights) variables.in_order_units.extend(mages) variables.in_order_units.extend(healers) variables.in_order_units.extend(factories) variables.in_order_units.extend(rockets) ## **************************************** UNITS **************************************** ## ## Worker variables.my_karbonite = gc.karbonite() ## Income variables.worker_harvest_amount = 0 variables.past_karbonite_gain = variables.current_karbonite_gain + max(0,10 - int(variables.my_karbonite/40)) variables.current_karbonite_gain = 0 # reset counter if not worker.check_if_saviour_died(): variables.saviour_worker_id = None variables.saviour_worker = False variables.saviour_blueprinted = False variables.saviour_blueprinted_id = None variables.num_unsuccessful_savior = 0 variables.saviour_time_between = 0 # start_time = time.time() worker.designate_roles() # print("designating roles time: ",time.time() - start_time) ## Rangers variables.targeting_units = {} ranger.update_rangers() ## Knights knight.update_battles() ## Healers healer.update_healers() ## Rockets rocket.update_rockets() ## Factories factory.evaluate_stockpile()
def update_variables(): gc = variables.gc ## **************************************** GENERAL **************************************** ## ## Constants variables.curr_round = gc.round() variables.num_enemies = 0 variables.print_count = 0 variables.research = gc.research_info() ## Battle locations variables.last_turn_battle_locs = variables.next_turn_battle_locs.copy() variables.next_turn_battle_locs = {} # variables.quadrant_battle_locs = {} ## Units variables.my_units = gc.my_units() variables.my_unit_ids = set([unit.id for unit in variables.my_units]) variables.units = gc.units() num_workers= num_knights=num_rangers= num_mages= num_healers= num_factory= num_rocket = 0 # Update which ally unit id's are still alive & deaths per quadrant update_quadrants() # Updates enemies in quadrant & resets num dead allies if variables.curr_planet == bc.Planet.Earth: quadrant_size = variables.earth_quadrant_size else: quadrant_size = variables.mars_quadrant_size remove = set() for unit_id in variables.unit_locations: if unit_id not in variables.my_unit_ids: remove.add(unit_id) for unit_id in remove: loc = variables.unit_locations[unit_id] del variables.unit_locations[unit_id] f_f_quad = (int(loc[0] / quadrant_size), int(loc[1] / quadrant_size)) variables.quadrant_battle_locs[f_f_quad].remove_ally(unit_id) # Update % health of fighting allies in quadrant for quadrant in variables.quadrant_battle_locs: q_info = variables.quadrant_battle_locs[quadrant] q_info.update_ally_health_coefficient(gc) # Something something enemies for poss_enemy in variables.units: if poss_enemy.team != variables.my_team and poss_enemy.unit_type in variables.attacker: variables.num_enemies += 1 # Update num of ally units of each type unit_types = variables.unit_types for unit in variables.my_units: if unit.unit_type == unit_types["worker"]: num_workers+=1 elif unit.unit_type == unit_types["knight"]: num_knights+=1 elif unit.unit_type == unit_types["ranger"]: num_rangers+=1 elif unit.unit_type == unit_types["mage"]: num_mages+=1 elif unit.unit_type == unit_types["healer"]: num_healers+=1 elif unit.unit_type == unit_types["factory"]: num_factory+=1 elif unit.unit_type == unit_types["rocket"]: num_rocket+=1 variables.info = [num_workers, num_knights, num_rangers, num_mages, num_healers, num_factory, num_rocket] ## **************************************** UNITS **************************************** ## ## Worker variables.my_karbonite = gc.karbonite() variables.producing= [0, 0, 0, 0, 0] if not worker.check_if_saviour_died(): variables.saviour_worker_id = None variables.saviour_worker = False variables.saviour_blueprinted = False variables.saviour_blueprinted_id = None variables.num_unsuccessful_savior = 0 variables.saviour_time_between = 0 worker.designate_roles() ## Rangers variables.targeting_units = {} ranger.update_rangers() ## Knights knight.update_battles() ## Healers healer.update_healers() # Rockets rocket.update_rockets() ## Mages ## Factories factory.evaluate_stockpile()