コード例 #1
0
ファイル: World.py プロジェクト: mominoes/OrbisChallenge2016
    def get_nearest_control_point(self, position):
        """Find and return the control point with the closest linear distance (i.e. ignoring any obstacles/walls;
        "as the crow flies") to the given point. If no control points on the map, returns None.

        :param position: The Point to look from
        """
        if len(self.control_points) == 0:
            return None

        return min(self.control_points,
                   key=lambda control_point: chebyshev_distance(
                       control_point.position, position))
コード例 #2
0
ファイル: World.py プロジェクト: mominoes/OrbisChallenge2016
        def get_distance_to_shooter(enemy):
            if enemy.health <= 0 or direction.from_to(
                    shooter.position, enemy.position) != direction:
                return MAX_DISTANCE_INT

            distance = chebyshev_distance(shooter.position, enemy.position)

            if not self.can_shooter_shoot_target(
                    shooter.position, enemy.position,
                    shooter.current_weapon_type.get_range()):
                return MAX_DISTANCE_INT

            return distance
コード例 #3
0
ファイル: World.py プロジェクト: mominoes/OrbisChallenge2016
    def can_shooter_shoot_target(self,
                                 shooter_pos,
                                 target_pos,
                                 max_distance=MAX_DISTANCE_INT):
        """
        Returns true iff there is a clear line of fire from shooter to
        target. This takes walls into account.

        :param (int,int) shooter_pos: The source of the shot
        :param (int,int) target_pos: The target of the shot
        :param int max_distance: Maximum distance in tiles that the bullet can travel
        """
        if shooter_pos == target_pos or max_distance <= 0 \
                or not self.is_within_bounds(shooter_pos) or not self.is_within_bounds(target_pos) \
                or not are_points_inline(shooter_pos, target_pos) \
                or self.get_tile(shooter_pos).does_block_movement() or self.get_tile(target_pos).does_block_movement():
            return False

        shot_direction = Direction.from_to(shooter_pos, target_pos)

        distance = chebyshev_distance(shooter_pos, target_pos)

        return max_distance >= distance == self._ray_cast_distance(
            shooter_pos, shot_direction, False, True, distance)
コード例 #4
0
 def get_num_enemy_units_around(self):
     """
     Returns the number of enemy units that are on tiles adjacent to or on this control point.
     """
     return len([enemy for enemy in self._enemies if
                 (enemy.health > 0 and chebyshev_distance(enemy.position, self.position) <= 1)])