Esempio n. 1
0
    def attempt_actions(self, game_state: GameState):
        """
        Call on each turn to act on the finished action queue
        Takes care of adding the updated upgrade_all action
        """

        if self.change_flag:
            self.refresh_upgrade_all()

        for action in self.action_queue:
            if not action['upgrade']:
                game_state.attempt_spawn(action['unit_type'], action['locations'])
            else:
                game_state.attempt_upgrade(action['locations'])
Esempio n. 2
0
    def repair(self,
               game_state: GameState,
               base=0.9,
               upgraded=0.97,
               locations=None):
        game_map = game_state.game_map

        to_build = self.memory["repair"]["to_build"]
        for unit in list(to_build):
            game_state.attempt_spawn(unit.unit_type, [unit.x, unit.y])
            if game_state.attempt_upgrade([unit.x, unit.y]):
                to_build.remove(unit)

        potentially_in_progress = set([(unit.x, unit.y) for unit in to_build])
        for x, y in locations or self._P1_POINTS:
            if game_map[x, y] and game_map[x, y][0].stationary:
                if not game_map[x, y][0].pending_removal:
                    unit = game_map[x, y][0]
                    repair = (unit.health / unit.max_health) < (
                        base if unit.upgraded else upgraded)
                    if repair and (unit.x,
                                   unit.y) not in potentially_in_progress:
                        if game_state.attempt_remove([x, y]):
                            to_build.add(unit)

        self.memory["repair"]["to_build"] = to_build
Esempio n. 3
0
    def attempt_actions(self, game_state: GameState):
        """
        Call on each turn to act on the finished action queue
        Takes care of adding the updated upgrade_all action
        """

        if self.change_flag:
            self.refresh_upgrade_all(game_state)

        for action in self.action_queue:
            max_actions = action['max_num']
            taken_actions = 0
            for location in action['locations']:

                if not action['upgrade']:
                    taken_actions += game_state.attempt_spawn(
                        action['unit_type'], location)
                else:
                    taken_actions += game_state.attempt_upgrade(location)

                if taken_actions >= max_actions:
                    break
Esempio n. 4
0
    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)