예제 #1
0
    def exec(self):
        self.target_player = closest_player_to_point(
            self.game_state.get_ball_position(), our_team=False).player
        orientation_opponent = np.array([
            math.cos(self.target_player.pose.orientation),
            math.sin(self.target_player.pose.orientation)
        ])
        destination_position = self.target_player.pose.position + self.distance * orientation_opponent
        ball_to_player = self.game_state.get_ball_position(
        ) - self.player.pose.orientation
        destination_orientation = ball_to_player.angle()
        destination_pose = Pose(destination_position, destination_orientation)

        if self.check_success():
            self.status_flag = Flags.SUCCESS
        else:
            self.status_flag = Flags.WIP

        return MoveToPosition(self.game_state,
                              self.player,
                              destination_pose,
                              pathfinder_on=True,
                              cruise_speed=self.cruise_speed,
                              collision_ball=self.collision_ball,
                              charge_kick=self.charge_kick,
                              end_speed=self.end_speed,
                              dribbler_on=self.dribbler_on).exec()
예제 #2
0
    def protect_goal(self):
        if not self.penalty_kick:
            if not self._is_ball_too_far and \
                    self.player == closest_player_to_point(self.game_state.get_ball_position()).player and\
                    self._get_distance_from_ball() < ROBOT_RADIUS *3:
                self.next_state = self.go_behind_ball
            else:
                self.next_state = self.protect_goal
            return ProtectGoal(self.game_state,
                               self.player,
                               self.is_yellow,
                               minimum_distance=300,
                               maximum_distance=self.game_state.game.field.
                               constant["FIELD_GOAL_RADIUS"] / 2)
        else:
            our_goal = Position(
                self.game_state.const["FIELD_OUR_GOAL_X_EXTERNAL"], 0)
            opponent_kicker = player_with_ball(2 * ROBOT_RADIUS)
            ball_position = self.game_state.get_ball_position()
            if opponent_kicker is not None:
                ball_to_goal = our_goal.x - ball_position.x

                if self.game_state.field.our_side is FieldSide.POSITIVE:
                    opponent_kicker_orientation = clamp(
                        opponent_kicker.pose.orientation, -pi / 5, pi / 5)
                    goalkeeper_orientation = wrap_to_pi(
                        opponent_kicker_orientation - pi)
                else:
                    opponent_kicker_orientation = clamp(
                        wrap_to_pi(opponent_kicker.pose.orientation - pi),
                        -pi / 5, pi / 5)
                    goalkeeper_orientation = opponent_kicker_orientation

                y_position_on_line = ball_to_goal * tan(
                    opponent_kicker_orientation)
                width = self.game_state.const["FIELD_GOAL_WIDTH"]
                y_position_on_line = clamp(y_position_on_line, -width, width)

                destination = Pose(our_goal.x, y_position_on_line,
                                   goalkeeper_orientation)

            else:
                destination = Pose(our_goal)
            return MoveToPosition(self.game_state,
                                  self.player,
                                  destination,
                                  pathfinder_on=True,
                                  cruise_speed=2)
예제 #3
0
    def main_state(self):
        target_player = closest_player_to_point(self.game_state.ball_position, our_team=False).player
        orientation_opponent = np.array([math.cos(target_player.pose.orientation),
                                         math.sin(target_player.pose.orientation)])
        destination_position = target_player.pose.position + self.distance * orientation_opponent
        ball_to_player = self.game_state.ball_position - self.player.pose.orientation
        destination_orientation = ball_to_player.angle

        if self.check_success():
            self.status_flag = Flags.SUCCESS
        else:
            self.status_flag = Flags.WIP

        return CmdBuilder().addMoveTo(Pose(destination_position, destination_orientation),
                                      cruise_speed=self.cruise_speed,
                                      ball_collision=self.ball_collision,
                                      end_speed=self.end_speed).addChargeKicker().addForceDribbler().build()
예제 #4
0
    def main_state(self):
        target_player = closest_player_to_point(self.game_state.ball_position,
                                                our_team=False).player
        orientation_opponent = np.array([
            math.cos(target_player.pose.orientation),
            math.sin(target_player.pose.orientation)
        ])
        destination_position = target_player.pose.position + self.distance * orientation_opponent
        ball_to_player = self.game_state.ball_position - self.player.pose.orientation
        destination_orientation = ball_to_player.angle

        if self.check_success():
            self.status_flag = Flags.SUCCESS
        else:
            self.status_flag = Flags.WIP

        return CmdBuilder().addMoveTo(
            Pose(destination_position, destination_orientation),
            cruise_speed=self.cruise_speed,
            ball_collision=self.ball_collision,
            end_speed=self.end_speed).addChargeKicker().addForceDribbler(
            ).build()
 def is_not_closest(self, player):
     return player != closest_player_to_point(
         GameState().get_ball_position(), True).player
예제 #6
0
 def is_closest(self, player):
     return player == closest_player_to_point(
         GameState().get_ball_position(), True, robots=self.robots).player