コード例 #1
0
    def execute(self, game_info: GameInformation):
        """Attempts to drive into the ball in a direction that hits the ball towards the goal.

        Overrides the State class's execute function.
        The ground controller is automatically used.
        The target location is on the outside of the ball on a line connecting the ball and the opponents goal.

        Attributes:
            game_info: information detailing the current status of various game objects

        """

        team = util.sign(game_info.me.team)
        target_goal = util.GOAL_HOME * -team

        ball_to_goal = target_goal - game_info.ball.location
        # distance_to_goal = ball_to_goal.length()
        direction_to_goal = ball_to_goal.normalized()

        aim_location = game_info.ball.location - (direction_to_goal *
                                                  util.BALL_RADIUS)
        local_target = relative_location(game_info.me.location,
                                         game_info.me.rotation, aim_location)
        self.debug['target'] = aim_location

        self.next_controller_state = ground_controller(game_info, local_target)
コード例 #2
0
    def execute(self, game_info):
        # aim to hit ball to the side
        # detect of ball is east or west of bot
        east_multiplier = util.sign(game_info.me.location.x -
                                    game_info.ball.location.x)
        # aim for side of the ball
        aim_location = game_info.ball.location + Vec3(
            east_multiplier * util.BALL_RADIUS, 0, 0)
        target_location = relative_location(game_info.me.location,
                                            game_info.me.rotation,
                                            aim_location)
        self.debug['target'] = aim_location

        self.next_controller_state = ground_controller(game_info,
                                                       target_location)
コード例 #3
0
ファイル: kickoff.py プロジェクト: sDauenbaugh/AwesamBot
    def execute(self, game_info: GameInformation):
        self.debug["target"] = game_info.ball.location
        # flip once when at appropriate distance
        if self.flipped is False and (game_info.me.location -
                                      game_info.ball.location).length() < 3600:
            self.flipped = True
            angle = -math.atan2(game_info.ball.local_location.y,
                                game_info.ball.local_location.x)

            if angle > math.pi:
                angle -= 2 * math.pi
            elif angle < -math.pi:
                angle += 2 * math.pi
            self.sequence = flip_sequence(angle=angle, boosting=True)
        # otherwise steer toward ball and boost
        else:
            target = game_info.ball.local_location
            self.next_controller_state = ground_controller(game_info, target)
            self.next_controller_state.boost = True
            self.next_controller_state.throttle = 1
コード例 #4
0
ファイル: aimshot.py プロジェクト: sDauenbaugh/AwesamBot
    def execute(self, game_info):
        team = util.sign(game_info.me.team)

        self.next_controller_state = ground_controller(
            game_info, util.GOAL_HOME * team * -1)
コード例 #5
0
def hit_controller(game_info, hit_target):
    """Gives a set of commands to make the car shoot the ball

    This function will flip the car into the ball in order to make a shot and
    it will adjust the car's speed and positioning to help make the shot.

    Attributes:
        hit_target (Vec3): The position that we want to hit the ball toward

    Returns:
        SimpleControllerState: the set of commands to achieve the goal
    """
    controller_state = SimpleControllerState()
    # get ball distance and angle from car
    ball_direction = game_info.ball.local_location
    ball_distance = game_info.ball.local_location.flat().length()
    ball_angle = -math.atan2(ball_direction.y, ball_direction.x)
    if ball_angle > math.pi:
        ball_angle -= 2 * math.pi
    elif ball_angle < -math.pi:
        ball_angle += 2 * math.pi
    # get target distance and angle from ball
    ball_to_target = hit_target - game_info.ball.location
    target_distance = ball_to_target.length()
    ball_to_target_unit = ball_to_target.normalized()
    flip_ready = False
    if ball_distance < 400:
        flip_ready = True

    # flipping
    if flip_ready:
        time_diff = time.time() - game_info.timer1
        if time_diff > 2.2:
            game_info.timer1 = time.time()
        elif time_diff <= 0.1:
            # jump and turn toward the ball
            controller_state.jump = True
            if ball_angle > 0:
                controller_state.yaw = -1
            elif ball_angle < 0:
                controller_state.yaw = 1
        elif 0.1 <= time_diff <= 0.15:
            # keep turning
            controller_state.jump = False
            if ball_angle > 0:
                controller_state.yaw = -1
            elif ball_angle < 0:
                controller_state.yaw = 1
        elif 0.15 < time_diff < 1:
            # flip
            controller_state.jump = True
            if ball_angle > 0:
                controller_state.yaw = -1
            elif ball_angle < 0:
                controller_state.yaw = 1
            if math.fabs(ball_angle) > math.pi:
                controller_state.pitch = 1
            else:
                controller_state.pitch = -1
        else:
            flip_ready = False
            controller_state.jump = False
    else:
        aim_location = game_info.ball.location - (ball_to_target_unit *
                                                  util.BALL_RADIUS)
        local_target = relative_location(game_info.me.location,
                                         game_info.me.rotation, aim_location)
        controller_state = ground_controller(game_info, local_target)

    return controller_state