예제 #1
0
    def compute_wall_segment(self):
        """
            We compute the position where the wall's robot can block the field of view of opposing robot with the ball.
            The field of view is defined as the triangle created by the ball and the goal_line extremities.
        """

        nb_robots = len(self.robots_in_formation)
        wall_segment_length = nb_robots * ROBOT_DIAMETER + GAP_IN_WALL * (nb_robots - 1)

        goal_line = self.game_state.field.our_goal_line
        bisection_angle = angle_between_three_points(goal_line.p2, self.object_to_block.position, goal_line.p1)

        # We calculate the farthest distance from the object which completely block its FOV of the goal
        object_to_center_formation_dist = wall_segment_length / tan(bisection_angle)

        self.bisect_inter = find_bisector_of_triangle(self.object_to_block.position, goal_line.p1, goal_line.p2)
        vec_object_to_goal_line_bisect = self.bisect_inter - self.object_to_block.position

        # The penalty zone used to be a circle and thus really easy to handle, but now it's a rectangle...
        # It easier to first create the smallest circle that fit the rectangle.
        min_radius_over_penality_zone = ROBOT_RADIUS + (self.game_state.field.our_goal_area.upper_left - self.game_state.field.our_goal).norm
        object_to_block_to_center_formation_dist = min(vec_object_to_goal_line_bisect.norm - min_radius_over_penality_zone,
                                                       object_to_center_formation_dist)

        self.center_formation = object_to_block_to_center_formation_dist * normalize(vec_object_to_goal_line_bisect) + self.object_to_block.position

        if self.stay_away_from_ball:
            if (self.game_state.ball_position - self.center_formation).norm < KEEPOUT_DISTANCE_FROM_BALL:
                self.center_formation = self._closest_point_away_from_ball()

        half_wall_segment = 0.5 * wall_segment_length * perpendicular(normalize(vec_object_to_goal_line_bisect))
        self.wall_segment = Line(self.center_formation + half_wall_segment,
                                 self.center_formation - half_wall_segment)
    def compute_wall_arc(self):
        nb_robots = len(self.robots_in_formation)

        # Angle d'un robot sur le cercle de rayon self.dist_from_ball
        self.robot_angle = 2 * atan(ROBOT_RADIUS / self.dist_from_ball)

        # Angle totale couvert par le wall
        self.wall_angle = nb_robots * self.robot_angle + GAP_ANGLE * (
            nb_robots - 1)

        goal_line = self.game_state.field.goal_line

        self.center_of_goal = find_bisector_of_triangle(
            self.game_state.ball_position, goal_line.p1, goal_line.p2)
        vec_ball_to_center_of_goal = self.center_of_goal - self.game_state.ball_position

        # Centre de la formation sur le cercle de rayon self.dist_from_ball
        self.center_formation = self.dist_from_ball * normalize(
            vec_ball_to_center_of_goal) + self.game_state.ball_position

        # J'ajoute robot_angle / 2, sinon, avec 1 seul robot, il ne se positionne pas dans le centre de la formation
        self.first_robot_angle = vec_ball_to_center_of_goal.angle - self.wall_angle / 2 + self.robot_angle / 2

        self.first_robot_position = Position(cos(self.first_robot_angle),
                                             sin(self.first_robot_angle)) * self.dist_from_ball + \
                                    self.game_state.ball_position

        self.last_robot_angle = self.first_robot_angle + self.wall_angle
    def compute_wall_arc(self):
        nb_robots = len(self.robots_in_formation)

        # Angle d'un robot sur le cercle de rayon self.dist_from_ball
        self.robot_angle = 2 * atan(ROBOT_RADIUS / self.dist_from_ball)

        # Angle totale couvert par le wall
        self.wall_angle = nb_robots * self.robot_angle + GAP_ANGLE * (nb_robots - 1)

        goal_line = self.game_state.field.goal_line

        self.center_of_goal = find_bisector_of_triangle(self.game_state.ball_position, goal_line.p1, goal_line.p2)
        vec_ball_to_center_of_goal = self.center_of_goal - self.game_state.ball_position

        # Centre de la formation sur le cercle de rayon self.dist_from_ball
        self.center_formation = self.dist_from_ball * normalize(
            vec_ball_to_center_of_goal) + self.game_state.ball_position

        # J'ajoute robot_angle / 2, sinon, avec 1 seul robot, il ne se positionne pas dans le centre de la formation
        self.first_robot_angle = vec_ball_to_center_of_goal.angle - self.wall_angle / 2 + self.robot_angle / 2

        self.first_robot_position = Position(cos(self.first_robot_angle),
                                             sin(self.first_robot_angle)) * self.dist_from_ball + \
                                    self.game_state.ball_position

        self.last_robot_angle = self.first_robot_angle + self.wall_angle
예제 #4
0
    def _best_target_into_goal(self):
        if 0 < len(self.game_state.enemy_team.available_players):
            enemy_player_with_ball = player_with_ball(min_dist_from_ball=200, our_team=False)
            if enemy_player_with_ball is not None:
                if player_pointing_toward_segment(enemy_player_with_ball, self.GOAL_LINE):
                    ball = self.game_state.ball
                    where_ball_enter_goal = intersection_between_lines(self.GOAL_LINE.p1,
                                                                       self.GOAL_LINE.p2,
                                                                       ball.position,
                                                                       ball.position +
                                                                       Position(1000 * np.cos(enemy_player_with_ball.pose.orientation),
                                                                                1000 * np.sin(enemy_player_with_ball.pose.orientation)))
                    where_ball_enter_goal = closest_point_on_segment(where_ball_enter_goal,
                                                                     self.GOAL_LINE.p1,
                                                                     self.GOAL_LINE.p2)
                    return where_ball_enter_goal

        return find_bisector_of_triangle(self.game_state.ball.position,
                                         self.GOAL_LINE.p2,
                                         self.GOAL_LINE.p1)
예제 #5
0
    def _best_target_into_goal(self):
        if 0 < len(self.game_state.enemy_team.available_players):
            enemy_player_with_ball = player_with_ball(min_dist_from_ball=200,
                                                      our_team=False)
            if enemy_player_with_ball is not None:
                if player_pointing_toward_segment(enemy_player_with_ball,
                                                  self.GOAL_LINE):
                    ball = self.game_state.ball
                    where_ball_enter_goal = intersection_between_lines(
                        self.GOAL_LINE.p1, self.GOAL_LINE.p2, ball.position,
                        ball.position + Position(
                            1000 *
                            np.cos(enemy_player_with_ball.pose.orientation),
                            1000 *
                            np.sin(enemy_player_with_ball.pose.orientation)))
                    where_ball_enter_goal = closest_point_on_segment(
                        where_ball_enter_goal, self.GOAL_LINE.p1,
                        self.GOAL_LINE.p2)
                    return where_ball_enter_goal

        return find_bisector_of_triangle(self.game_state.ball.position,
                                         self.GOAL_LINE.p2, self.GOAL_LINE.p1)
예제 #6
0
def test_bisector_angle_between_the_intersection_is_the_same():
    A_RANDOM_POINT = Position(np.random.randn(1, 1), 1)
    inter = find_bisector_of_triangle(A_RANDOM_POINT, A_LINE[0], A_LINE[1])
    angle1 = angle_between_three_points(A_LINE[0], A_RANDOM_POINT, inter)
    angle2 = angle_between_three_points(inter, A_RANDOM_POINT, A_LINE[1])
    assert compare_angle(angle1, angle2, abs_tol=0.01)
예제 #7
0
def test_bisector_of_squared_triangle():
    assert Position(0,
                    0) == find_bisector_of_triangle(A_PERP_POINT_TO_BISECTION,
                                                    A_LINE[0], A_LINE[1])
예제 #8
0
def test_bisector_angle_between_the_intersection_is_the_same():
    A_RANDOM_POINT = Position(np.random.randn(1, 1), 1)
    inter = find_bisector_of_triangle(A_RANDOM_POINT, A_LINE[0], A_LINE[1])
    angle1 = angle_between_three_points(A_LINE[0], A_RANDOM_POINT, inter)
    angle2 = angle_between_three_points(inter, A_RANDOM_POINT, A_LINE[1])
    assert compare_angle(angle1, angle2, abs_tol=0.01)
예제 #9
0
def test_bisector_of_squared_triangle():
    assert Position(0, 0) == find_bisector_of_triangle(A_PERP_POINT_TO_BISECTION,
                                                       A_LINE[0],
                                                       A_LINE[1])