Exemple #1
0
 def get_enemy_perimeter(self, enemy_units: Units, enemy_structures: Units,
                         reference_position: Point2):
     perimeter = 0
     pathing_grid: PixelMap = self.bot._game_info.pathing_grid
     for enemy_unit in enemy_units:
         enemies_excluding_self: Units = enemy_units.tags_not_in(
             {enemy_unit.tag})
         pos: Point2 = enemy_unit.position
         positions = [
             Point2((pos.x - 1, pos.y + 1)),
             Point2((pos.x, pos.y + 1)),
             Point2((pos.x + 1, pos.y + 1)),
             Point2((pos.x - 1, pos.y)),
             # [pos.x, pos.y], disregard center point
             Point2((pos.x + 1, pos.y)),
             Point2((pos.x - 1, pos.y - 1)),
             Point2((pos.x, pos.y - 1)),
             Point2((pos.x + 1, pos.y - 1)),
         ]
         if reference_position.distance_to(enemy_unit.position) > 5:
             positions = remove_n_furthest_points(positions,
                                                  reference_position, 3)
         for p in positions:
             if pathing_grid[
                     math.floor(p.x), math.floor(
                         p.y
                     )] <= 0 and not enemies_excluding_self.closer_than(
                         1, p).exists and not enemy_structures.closer_than(
                             1, p).exists:
                 perimeter += 1
     return perimeter
Exemple #2
0
 def _path_distance(self, start: Point2, end: Point2):
     path = Path(
         self.knowledge.pathing_manager.path_finder_terrain.find_path(
             start, end))
     if path.distance > 0:
         return path.distance
     return start.distance_to(end)  # Failsafe
Exemple #3
0
 def position_blocks_expansion(self, position: Point2) -> bool:
     """ Will the creep tumor block expansion """
     blocks_expansion = False
     for expansion in self.bot.expansion_locations_list:
         if position.distance_to(expansion) < 6:
             blocks_expansion = True
             break
     return blocks_expansion
    async def select_targets(self, center: Point2) -> (Point2, Point2):
        """ Returns none if no valid target was found. """
        closest_viable_zone: Zone = None
        second_viable_zone: Zone = None
        current_zone_index: Optional[int] = None
        enemy_zones: List[Zone] = self.knowledge.enemy_expansion_zones

        for i in range(0, len(enemy_zones)):
            zone = enemy_zones[i]
            distance = center.distance_to(zone.center_location)
            # TODO: missing conditions
            if distance < 12:
                current_zone_index = i
            if zone.is_enemys and closest_viable_zone is None:
                closest_viable_zone = zone
            else:
                if closest_viable_zone is None:
                    if zone.could_have_enemy_workers_in < self.ai.time:
                        closest_viable_zone = zone
                else:
                    # we have a viable zone
                    if zone.is_enemys and not closest_viable_zone.is_enemys:
                        closest_viable_zone = zone
                    elif zone.is_enemys:
                        # both are enemy zones
                        if current_zone_index == i:
                            if (
                                    zone.could_have_enemy_workers_in < self.ai.time
                                    and closest_viable_zone.could_have_enemy_workers_in < self.ai.time
                            ):
                                second_viable_zone = closest_viable_zone
                                closest_viable_zone = zone
                            elif zone.could_have_enemy_workers_in < self.ai.time:
                                closest_viable_zone = zone
                        elif zone.could_have_enemy_workers_in < self.ai.time:
                            if second_viable_zone is None:
                                second_viable_zone = zone

        if closest_viable_zone is None:
            return None

        if self.knowledge.enemy_race == Race.Terran and second_viable_zone:
            return (
                await self.get_zone_closest(second_viable_zone, center),
                await self.get_zone_closest(second_viable_zone, center),
            )

        if second_viable_zone:
            return (
                await self.get_zone_closest(closest_viable_zone, center),
                await self.get_zone_closest(second_viable_zone, center),
            )

        return (
            await self.get_zone_closest(closest_viable_zone, center),
            await self.get_zone_furthest(closest_viable_zone, center),
        )
Exemple #5
0
    def _existing_tumors_too_close(self, position: Point2) -> bool:
        """ Using the policy option, check if other tumors are too close """
        min_distance: int = self.policy.distance_between_queen_tumors
        # passing 0 or False value into the policy will turn this check off and save computation
        if not min_distance:
            return False
        tumors: Units = self.bot.structures.filter(
            lambda s: s.type_id in
            {UnitID.CREEPTUMORBURROWED, UnitID.CREEPTUMORQUEEN})
        for tumor in tumors:
            if position.distance_to(tumor) < min_distance:
                return True

        # check in the pending creep locations (queen on route to lay tumor)
        for pending_position in self.pending_positions:
            if position.distance_to(pending_position[0]) < min_distance:
                return True

        return False
Exemple #6
0
 def position_near_nydus_worm(self, position: Point2) -> bool:
     """ Will the creep tumor block expansion """
     is_too_close: bool = False
     worms: Units = self.bot.structures(UnitID.NYDUSCANAL)
     for worm in worms:
         # worms spread creep at a 10.5 radius, add a bit of leeway
         if position.distance_to(worm) < 12:
             is_too_close = True
             break
     return is_too_close
    def should_force_field(self, position: Point2) -> Optional[Action]:
        for ff in self.cache.force_fields:  # type: EffectData
            for position in ff.positions:
                if position.distance_to(position) < 1.5:
                    return None

        for ff_pos in self.upcoming_fields:  # type: Point2
            if ff_pos.distance_to_point2(position) < 1.5:
                return None

        self.upcoming_fields.append(position)
        return Action(position, False, AbilityId.FORCEFIELD_FORCEFIELD)
    def closest_group(self, start: Point2, combat_groups: List[CombatUnits]) -> Optional[CombatUnits]:
        group = None
        best_distance = 50  # doesn't find enemy groups closer than this

        for combat_group in combat_groups:
            center = combat_group.center

            if center == start:
                continue  # it's the same group!

            distance = start.distance_to(center)
            if distance < best_distance:
                best_distance = distance
                group = combat_group

        return group
Exemple #9
0
 def position_blocks_expansion(self, target_position: Point2):
     res = False
     for expansion in self.expansion_locations:
         if target_position.distance_to(expansion) < 6:
             res = True
     return res
Exemple #10
0
 def sort(p: Point2):
     return p.distance_to(reference)