def on_turn(self, turn_state): """ This function is called every turn with the game state wrapper as an argument. The wrapper stores the state of the arena and has methods for querying its state, allocating your current resources as planned unit deployments, and transmitting your intended deployments to the game engine. """ game_state = GameState(self.config, turn_state) self.health = game_state.my_health if game_state.turn_number == 0: self.cached_health = self.health debug_write('Performing turn {} of your custom algo strategy'.format(game_state.turn_number)) game_state.suppress_warnings(True) self.current_mp = game_state.get_resource(MP, 0) self.current_sp = game_state.get_resource(SP, 0) self.dynamic_strategy(game_state) self.cached_health = self.health game_state.submit_turn()
def dynamic_strategy(self, game_state: GameState): """ For defense we will use a spread out layout and some interceptors early on. We will place turrets near locations the opponent managed to score on. For offense we will use long range demolishers if they place stationary units near the enemy's front. If there are no stationary units to attack in the front, we will send Scouts to try and score quickly. """ # initial strategy is highly dependent on expected units. Don't want to react until after we've built a little. if len(self.recent_scored_on_locations) and game_state.turn_number > 3: self.build_reactive_defense() if game_state.turn_number - self.delay < 3: game_state.attempt_spawn(INTERCEPTOR, [3, 10], num=2) game_state.attempt_spawn(INTERCEPTOR, [24, 10], num=2) # On the initial turn, try to get them with a destructor if game_state.turn_number == 0: self.send_initial_destructor(game_state) if game_state.turn_number == 1: self.utility.append_action('initial_turret_upgrades', TURRET, [[3, 13], [24, 13]], upgrade=True) self.utility.prioritize_action('initial_turret_upgrades') if game_state.turn_number == 2: # we want to manually manage and not upgrade these specific walls self.build_left_side_wall(game_state) self.build_right_side_wall(game_state) self.utility.remove_action('initial_walls') self.utility.append_action('frontal_wall', WALL, self.get_frontal_wall()) # put upgrades before spawns to upgrade before spawning more; these cover the rest of the game self.utility.append_action("upgrade_factories", '', self.factory_locations, True, max_num=1) self.utility.append_action("extra_factories", FACTORY, self.factory_locations, max_num=1) if game_state.turn_number == 4: self.utility.remove_action('initial_turrets') self.utility.remove_action('initial_turret_upgrades') self.utility.append_action('frontal_turrets', TURRET, self.get_frontal_turrets()) self.utility.append_action('frontal_turret_upgrades', TURRET, self.get_frontal_turrets(), upgrade=True) self.utility.prioritize_action('frontal_turrets') self.utility.prioritize_action('frontal_turret_upgrades') if game_state.turn_number >= 5: game_state.attempt_spawn(TURRET, [[3, 12]]) # game_state.attempt_spawn(WALL, [[1, 12], [2, 12], [2, 11]]) if game_state.turn_number >= 7: game_state.attempt_spawn(TURRET, [[24, 12]]) # game_state.attempt_spawn(WALL, [[26, 12], [25, 12], [25, 11]]) if game_state.turn_number >= 12: # only do the following if the wall is intact; will assume we have that after turn 12 game_state.attempt_upgrade([[3, 12], [24, 12]]) # game_state.attempt_upgrade([[0, 13], [27, 13], [3, 12], [3, 11], [24, 12], [24, 11], [1, 12], [2, 12], [2, 11], [26, 12], # [25, 12], [25, 11]]) if game_state.turn_number == 15: self.utility.append_action('secondary_wall', WALL, self.get_secondary_wall()) self.utility.append_action('secondary_turrets', TURRET, self.get_secondary_turrets()) self.utility.prioritize_action('secondary_wall') self.utility.prioritize_action('secondary_turrets') self.utility.prioritize_action('frontal_wall') self.utility.prioritize_action('frontal_turrets') # attack logic; manually building to maintain walls if they are destroyed if (game_state.turn_number % 6) == 4: self.attack_strategy = self.get_attack_strategy(game_state) if game_state.turn_number >= 4: self.attack_strategy(game_state) # always try to use more resources self.utility.attempt_actions(game_state) while game_state.get_resource(SP) >= 9: current_location = random.choice(self.factory_locations) game_state.attempt_spawn(FACTORY, current_location) game_state.attempt_upgrade(current_location)