Example #1
0
    def offense(self, game_state, turn_state):
        locations = [[5, 14], [3, 17], [4, 16]]
        top_left_enemy_destructors = 0
        advanced_game_state = AdvancedGameState(self.config, turn_state)
        for location in locations:
            top_left_enemy_destructors = max(
                top_left_enemy_destructors,
                len(advanced_game_state.get_attackers(location, 1)))
        top_left_enemy_units = self.get_enemy_left_units(game_state)

        for _ in range(top_left_enemy_destructors // 3 +
                       top_left_enemy_units // 6):
            if game_state.can_spawn(EMP, [2, 11]):
                game_state.attempt_spawn(EMP, [2, 11])

        while game_state.can_spawn(PING, [16, 2], 1):
            game_state.attempt_spawn(PING, [16, 2], 1)
    def simulate(self, state: gamelib.AdvancedGameState, unit_type, spawn_loc=(13, 0), num_units=1):
        map = state.game_map

        """
        TODO: ENCRYPTORS
        """
        target_edge = map.TOP_RIGHT if spawn_loc[0] < 14 else map.TOP_LEFT

        path = state.find_path_to_edge(spawn_loc, target_edge)

        total_dmg = 0
        total_cores = 0

        frames = 2 if unit_type == PING else 4
        dmg = 0 if unit_type == SCRAMBLER else (1 if unit_type == PING else 3)

        for i in range(num_units):
            map.add_unit(unit_type, spawn_loc)
        idx = 0

        remaining = map[spawn_loc]

        map.remove_unit(spawn_loc)
        pings = 0
        while idx < len(path):

            loc = path[idx]

            for i in remaining:
                i.x = loc[0]
                i.y = loc[1]
                map[loc].append(i)

            for i in range(frames):
                defense_dmg = 4 * len(state.get_attackers(loc, 0))
                our_dmg = len(map[loc]) * dmg

                initial = len(map[loc])

                if map[loc]:
                    target = state.get_target(map[loc][0])
                else:
                    break

                if target:
                    target.stability -= our_dmg
                    total_dmg += our_dmg
                    total_cores += (our_dmg / target.max_stability) * target.cost
                    if target.stability < 0:
                        map.remove_unit([target.x, target.y])

                dead = 0
                for i in range(initial):

                    if defense_dmg <= 0 or dead == len(map[loc]):
                        break

                    # Killed one, did they kill more
                    if defense_dmg >= map[loc][dead].stability:
                        defense_dmg -= map[loc][dead].stability
                        dead += 1

                    # They didn't kill this one
                    else:
                        map[loc][dead].stability -= defense_dmg
                        break

                # kill the dead ones
                for i in range(dead):
                    map[loc].pop(0)

            remaining = map[loc]
            pings = remaining

            if len(remaining) == 0:
                break

            map.remove_unit(loc)

            idx += 1

            if loc[1] > 14:
                mod_path = state.find_path_to_edge(spawn_loc, target_edge)
                if path != mod_path and loc in mod_path:
                    idx = mod_path.index(loc) + 1
                    path = mod_path

        return 3.5 * len(pings) + total_cores