Ejemplo n.º 1
0
def diagonal(game_info, opponent_distance, x_sign):
    controller_input = SimpleControllerState()
    current_state = game_info.me
    ball_angle = atan2((game_info.ball.pos - current_state.pos).y,
                       (game_info.ball.pos - current_state.pos).x)
    offset = Vec3(0, 0, 0)

        
    if current_state.pos.y < -2250:
        #Boost towards the first small boost
        controller_input = GroundTurn(current_state,
                                      current_state.copy_state(pos=game_info.ball.pos+offset)).input()
        controller_input.boost = 1

    elif current_state.pos.y < - 1500:
        controller_input = FrontDodge(current_state).input()

    elif current_state.pos.y > -700:
        controller_input = FrontDodge(current_state).input()

    else:
        #If we're on the ground between stages, boost and turn towards the ball
        controller_input = GroundTurn(current_state,
                                      current_state.copy_state(pos=game_info.ball.pos)).input()
        if current_state.wheel_contact:
            controller_input.boost = 1


    return controller_input
Ejemplo n.º 2
0
    def controller(self, agent, angle):
        controller_state = SimpleControllerState()

        steer_value = steer(angle)
        controller_state.steer = steer_value
        controller_state.throttle = 1
        controller_state.handbrake = True

        if self.level == PowerSlideLevel.NORMAL:
            balance_threshold = 0.25 * abs(
                agent.me.angular_velocity.data[2])**2 + 0.05

            if balance_threshold * -1 <= angle <= balance_threshold:
                controller_state.handbrake = False
                controller_state.boost = True
                if abs(agent.me.angular_velocity.data[2]) >= 0.15:
                    controller_state.steer = sign(
                        agent.me.angular_velocity.data[2]) * -1
                else:
                    controller_state.steer = 0
        elif self.level == PowerSlideLevel.U_TURN:
            if abs(angle) < 1.15:
                controller_state.steer = steer_value * -1
                controller_state.throttle = -1
                controller_state.handbrake = False
                controller_state.boost = False

            if abs(angle) < 0.15:
                controller_state.steer = 0

        return controller_state
Ejemplo n.º 3
0
def far_back(game_info, opponent_distance):
    controller_input = SimpleControllerState()
    current_state = game_info.me
    ball_angle = atan2((game_info.ball.pos - current_state.pos).y,
                       (game_info.ball.pos - current_state.pos).x)

    if abs(current_state.pos.y) > 3800:
        #If we're far away, boost to speed up
        controller_input.boost = 1

    elif abs(current_state.pos.y) > 1500:
        #Front flip for speed
        controller_input = FrontDodge(current_state).input()

    elif current_state.pos.y > -700:
        controller_input = FrontDodge(current_state).input()

    elif current_state.wheel_contact:
        #Otherwise if we're on the ground, boost and turn towards the ball
        controller_input = GroundTurn(current_state,
                                      current_state.copy_state(pos=game_info.ball.pos)).input()
        controller_input.boost = 1

    else:
        #Otherwise turn towards the ball (this might not actually do anything)
        controller_input = GroundTurn(current_state,
                                      current_state.copy_state(pos=game_info.ball.pos)).input()

    return controller_input
Ejemplo n.º 4
0
def follow_ball_on_ground(gi: GameInfo) -> Sequence:
    ball_loc = Vec3(gi.packet.game_ball.physics.location)
    ball_loc_flat = ball_loc.flat()
    ball_vel_flat = Vec3(gi.packet.game_ball.physics.velocity).flat()
    ball_ground_speed = ball_vel_flat.length()
    ideal_position = ball_loc_flat

    controls = SimpleControllerState(
        steer=gi.car.steer_toward_target(ideal_position)
    )
    car_ground_speed = gi.car.velocity.flat().length()
    car_to_ball_dist = gi.car.location.flat().dist(ball_loc_flat)
    if car_to_ball_dist > 800:
        controls.throttle = 1.0
        controls.boost = abs(controls.steer) < 0.2 and car_ground_speed < 2300
    else:
        if car_ground_speed - ball_ground_speed > 525 and car_to_ball_dist < 500:
            controls.throttle = min(max((ball_ground_speed - car_ground_speed) / 3600, -1.0), 0)
            controls.boost = False
        else:
            controls.throttle = min(max((ball_ground_speed - car_ground_speed) / 525, 0), 1.0)
            controls.boost = ball_ground_speed - car_ground_speed > 992
            if gi.car.location.flat().dist(ball_loc_flat) > 92.75 and ball_loc.z < 200:
                controls.throttle = min(1.0, controls.throttle + 0.1)

    return Sequence([SingleStep(controls)])
Ejemplo n.º 5
0
def deltaC(
    info: Info, target: Vector3, jt
):  # this controller takes a vector containing the required acceleration to reach a target, and then gets the car there
    c = SimpleControllerState()
    target_local = info.car_matrix.dot(target)
    if info.car.has_wheel_contact:  # if on the ground
        if jt + 1.5 > info.game_time:  # if we haven't jumped in the last 1.5 seconds
            c.jump = True
        else:
            c.jump = False
            jt = info.game_time
    else:
        c.steer, c.yaw, c.pitch, c.roll, error = default_pd(info, target_local, True)
        if target.length > 25:  # stops boosting when "close enough"
            c.boost = True
        if error > 0.9:  # don't boost if we're not facing the right way
            c.boost = False
        tsj = info.game_time - jt  # time since jump
        if tsj < 0.215:
            c.jump = True
        elif tsj < 0.25:
            c.jump = False
        elif (
            tsj >= 0.25 and tsj < 0.27 and target.z > 560
        ):  # considers a double-jump if we still need to go up a lot
            c.jump = True
            c.boost = False
            c.yaw = c.pitch = c.roll = 0
        else:
            c.jump = False
        c.throttle = 1
    return c, jt
Ejemplo n.º 6
0
def exampleController(agent,
                      target_object):  #target_object es un objeto tipo obj

    location = target_object.local_location
    controller_state = SimpleControllerState()
    angle_to_target = math.atan2(location.data[1], location.data[0])
    angle_velocity = math.atan2(agent.me.velocity.data[1],
                                agent.me.velocity.data[1])
    #draw_debug(agent.renderer,location.data)
    draw_debug(agent, agent.renderer, target_object.location.data)
    current_speed = velocity2D(agent.me)
    #steering
    if abs(angle_to_target) < math.pi / 4:
        if agent.me.has_wheel_contact == True:
            controller_state.boost = True
        controller_state.handbrake = False
    else:
        controller_state.boost = False
        controller_state.handbrake = True
    controller_state.steer = sign(angle_to_target) * min(
        1, abs(2 * angle_to_target))
    controller_state.throttle = 1
    #dodging
    if abs(angle_to_target) < math.pi / 2 and abs(
            angle_velocity) < math.pi / 3:
        dodging(agent, target_object, controller_state, angle_to_target)
    return controller_state
Ejemplo n.º 7
0
def arrive_on_time(position: Vector3, velocity: Vector3, target: Vector3,
                   time_taken: float) -> SimpleControllerState:
    to_target = target - position
    distance = to_target.magnitude()
    average_speed = distance / (time_taken + 0.0000001)
    current_speed = velocity.magnitude()
    target_speed = (1 -
                    SPEED_MATCH) * current_speed + SPEED_MATCH * average_speed

    controller = SimpleControllerState()

    if current_speed < target_speed:
        controller.throttle = 1
        controller.boost = target_speed > 1410
    else:
        controller.boost = False
        if current_speed - target_speed > 75:
            controller.throttle = -1
        else:
            controller.throttle = 0

    if current_speed < 100:
        controller.throttle = 0.2

    return controller
Ejemplo n.º 8
0
    def flyController(self, agent):
        controller_state = SimpleControllerState()
        location = toLocal(agent.ball, agent.me)
        angle_to_target = np.arctan2(location[1], location[0])
        location_of_target = toLocal(agent.ball, agent.me)
        '''steering'''
        if angle_to_target > .1:
            controller_state.steer = 1
            #controller_state.yaw = 1
            controller_state.throttle = 1
            if distance2D(agent.ball, agent.me) < 1000:
                controller_state.boost = True

        elif angle_to_target < -.1:
            controller_state.steer = -1
            #controller_state.yaw = -1
            controller_state.throttle = 1
            if distance2D(agent.ball, agent.me) < 1000:
                controller_state.boost = True

        else:
            controller_state.steer = controller_state.yaw = 0
            controller_state.throttle = .5
            if angle_to_target < .1 and angle_to_target > -.1:
                controller_state.boost = True
            else:
                controller_state.boost = False

        #jump
        time_difference = time.time() - agent.start
        if time_difference > 2.2:
            agent.start = time.time()
        elif time_difference < .1 and distance2D(
                agent.ball, agent.me) < 1000 and agent.ball.location[2] > 100:
            controller_state.jump = True
            print("jump")
        else:
            controller_state.jump = False

        if agent.ball.location[2] > agent.me.location[
                2] and agent.me.rotation[0] < verticalangle2D(
                    agent.ball.local_location,
                    agent.me) and agent.me.rotation[1] < angle_to_radians(
                        0):  #change angle, this is wrong
            controller_state.pitch = 1  # nose up

        elif agent.ball.location[2] < agent.me.location[
                2] and agent.me.rotation[0] > verticalangle2D(
                    agent.ball.local_location,
                    agent.me) and agent.me.rotation[1] > angle_to_radians(0):
            controller_state.pitch = -1  # nose down

        #updated code broke this
        # if(agent.ball.location[2] > agent.me.location[2]):
        #     print("ball above car", verticalangle2D(agent.ball.local_location, agent.me)*180/np.pi)
        # if(agent.ball.location[2] < agent.me.location[2]):
        #     print("ball below car", verticalangle2D(agent.ball.local_location, agent.me)*180/np.pi)

        return (controller_state)
Ejemplo n.º 9
0
def ground_controller(game_info, target_location):
    """Gives a set of commands to move the car along the ground toward a target location
    
    Attributes:
        target_location (Vec3): The local location the car wants to aim for
        
    Returns:
        SimpleControllerState: the set of commands to achieve the goal
    """
    controller_state = SimpleControllerState()
    ball_direction = target_location
    distance = target_location.flat().length()
    
    angle = -math.atan2(ball_direction.y, ball_direction.x)

    if angle > math.pi:
        angle -= 2*math.pi
    elif angle < -math.pi:
        angle += 2*math.pi
    
    speed = 0.0
    turn_rate = 0.0
    r1 = 250
    r2 = 1000
    # adjust angle
    if angle > 0.02:
        turn_rate = -1.0
    elif angle < -0.02:
        turn_rate = 1.0
    else:
        turn_rate = 0
    if distance <= r1:
        # if toward ball move forward
        if abs(angle) < math.pi / 4:
            speed = 1.0
        else:
            # if not toward ball reverse, flips turn rate to adjust
            turn_rate = turn_rate * -1.0
            speed = -1.0
    # if far away, move at full speed forward
    elif distance >= r2:
        speed = 1.0
        if game_info.me.velocity.length() < 2250:
            controller_state.boost = True
    # if mid range, adjust forward
    else:
        # adjust speed
        if game_info.me.velocity.length() < 2250:
            controller_state.boost = True
        if abs(angle) < math.pi / 2:
            speed = 1.0
        else:
            speed = 0.5

    controller_state.throttle = speed
    controller_state.steer = turn_rate
    controller_state.jump = False
    return controller_state
Ejemplo n.º 10
0
def offcenter(game_info=None, x_sign=None, persistent=None):

    controller_input = SimpleControllerState()
    current_state = game_info.me
    ball = game_info.ball
    team_sign = game_info.team_sign

    ball = game_info.ball

    #Set which boost we want based on team and side.
    if team_sign == 1:
        first_boost = 7
    else:
        first_boost = 26

    if abs(current_state.pos.x) > 150 and abs(current_state.pos.y) > 1100:
        #If we're not near the center-line of the field, boost towards the first small boost
        controller_input = GroundTurn(
            current_state,
            current_state.copy_state(pos=Vec3(0, -3000, 0))).input()
        controller_input.boost = 1

    elif abs(current_state.pos.y) > 1500 and current_state.pos.z < 30:
        controller_input.jump = 1
        controller_input.boost = 1

    elif abs(current_state.pos.y) > 1000 and not current_state.double_jumped:
        #If we're far away, fast dodge to speed up.
        controller_input = CancelledFastDodge(current_state,
                                              Vec3(1, x_sign, 0)).input()

    elif abs(current_state.pos.y) > 355 and current_state.double_jumped:
        if persistent.aerial_turn.action == None:
            persistent.aerial_turn.initialize = True
            vector_to_ball = game_info.ball.pos - current_state.pos
            yaw_to_ball = atan2(vector_to_ball.y, vector_to_ball.x)
            target_rot = Orientation(pitch=pi / 3, yaw=yaw_to_ball, roll=0)
            persistent.aerial_turn.target_orientation = target_rot

        else:
            controller_input, persistent = aerial_rotation(
                game_info.dt, persistent)
        controller_input.boost = 1

    elif abs(current_state.pos.y) > 355:
        controller_input = GroundTurn(
            current_state,
            current_state.copy_state(pos=Vec3(0, -team_sign *
                                              100, 0))).input()

    else:
        controller_input = FrontDodge(current_state).input()

    return controller_input, persistent
Ejemplo n.º 11
0
    def update(self):
        stateController = SimpleControllerState()

        if not self.firstJump:
            self.firstJump = True
            stateController.jump = True
            self.jumpTimer = time.time()

        elif self.firstJump and not self.secondJump:
            if time.time() - self.jumpTimer < self.firstJumpHold:
                stateController.jump = True

            elif time.time() - self.jumpTimer > self.firstJumpHold and time.time() - self.jumpTimer < self.firstJumpHold +.05:
                stateController.boost = True
                stateController.jump = False

            else:
                self.secondJump = True
                stateController.boost = True
                self.jumpTimer = time.time()

        else:
            if time.time() - self.jumpTimer < self.secondJumpHold:
                stateController.jump = True
                stateController.boost = True

            else:
                self.active = False
                self.jump = False
                #self.agent.activeState = flightSystems(self.agent)

        if time.time() - self.jumpTimer > 0.15:

            pitchAngle = math.degrees(self.agent.me.rotation[1])
            y_vel = self.agent.me.avelocity[1]
            pitch = 0
            if pitchAngle > 50:
                if y_vel > -.4:
                    pitch = clamp(1,-1,-1 + abs(y_vel))
            elif pitchAngle < 50:
                if y_vel < .4:
                    pitch = clamp(1,-1,1 - abs(y_vel))

            #print(pitchAngle)

            if y_vel > 1:
                pitch = -1
            elif y_vel < -1:
                pitch = 1

            stateController.pitch = pitch
        #print(math.degrees(self.agent.me.rotation[1]))
        return stateController
Ejemplo n.º 12
0
def diagonal(game_info=None, x_sign=None, persistent=None):

    current_state = game_info.me
    controls = SimpleControllerState()

    #Set which boost we want based on team and side.
    if x_sign == -1:
        first_boost = 11
    else:
        first_boost = 10

    if game_info.boosts[first_boost].is_active:
        #If we haven't taken the small boost yet, drive towards it
        controls = GroundTurn(
            current_state,
            current_state.copy_state(pos=Vec3(0, -1000, 0))).input()
        controls.boost = 1

    elif abs(current_state.pos.y) > 1100 and current_state.wheel_contact:
        controls.jump = 1
        controls.boost = 1

    elif abs(current_state.pos.y) > 1100 and current_state.pos.z < 40:
        controls.jump = 1
        controls.boost = 1

    elif abs(current_state.pos.y) > 500 and not current_state.double_jumped:
        controls = CancelledFastDodge(current_state, Vec3(1, x_sign,
                                                          0)).input()

    elif abs(current_state.pos.y) > 250 and not current_state.wheel_contact:
        if persistent.aerial_turn.action == None:
            persistent.aerial_turn.initialize = True
            target_rot = Orientation(pitch=pi / 3,
                                     yaw=current_state.rot.yaw,
                                     roll=0)
            persistent.aerial_turn.target_orientation = target_rot

        else:
            controls, persistent = aerial_rotation(game_info.dt, persistent)
        controls.boost = 1
        controls.steer = x_sign  #Turn into the ball

    elif abs(current_state.pos.y) > 235:
        controls.throttle = 1
        controls.boost = 1
        controls.steer = x_sign

    else:
        controls = FrontDodge(current_state).input()

    return controls, persistent
Ejemplo n.º 13
0
def go_to_and_stop(data: Data, point, boost=True, slide=True):
    controller_state = SimpleControllerState()

    car_to_point = point - data.car.location
    point_rel = data.car.relative_location(point)
    dist = car_to_point.length()
    steer_correction_radians = point_rel.ang()

    set_normal_steering_and_slide(controller_state, steer_correction_radians,
                                  dist, slide)

    vel_f = data.car.velocity.proj_onto_size(data.car.orientation.front)
    ex_brake_dist = (vel_f**2) / 2800
    if dist > ex_brake_dist * 1.05:
        controller_state.throttle = 1
        if dist > ex_brake_dist * 1.5 and boost:
            if not data.car.is_on_wall and not controller_state.handbrake and data.car.velocity.length(
            ) < 2000:
                if is_heading_towards2(steer_correction_radians,
                                       car_to_point.length()):
                    if data.car.orientation.up.ang_to(UP) < math.pi * 0.3:
                        controller_state.boost = True
    elif dist < ex_brake_dist:
        controller_state.throttle = -1

    return controller_state
Ejemplo n.º 14
0
    def controller(self, agent):
        controller_state = SimpleControllerState()

        controller_state.pitch = 1
        controller_state.throttle = -1

        self.time_difference = agent.game_info.seconds_elapsed - self.start

        if self.time_difference <= 0.1:
            controller_state.jump = True
        elif 0.1 <= self.time_difference <= 0.15:
            controller_state.jump = False
        elif 0.15 <= self.time_difference <= 0.35:
            controller_state.jump = True
        elif 0.4 <= self.time_difference <= 1.75:
            controller_state.pitch = -1

        if 1.2 <= self.time_difference:
            controller_state.throttle = 1

        if 0.575 <= self.time_difference <= 1.2:
            controller_state.boost = True
            controller_state.roll = 1

        if 0.7 <= self.time_difference <= 1.5:
            controller_state.yaw = .5

        return controller_state
Ejemplo n.º 15
0
def go_nuts(gi: GameInfo) -> Sequence:
    ball_location = Vec3(gi.packet.game_ball.physics.location)
    if gi.car.location.flat().dist(ball_location.flat()) > 2000:
        # We're far away from the ball, let's try to lead it a little bit
        ball_prediction = gi.bot.get_ball_prediction_struct()  # This can predict bounces, etc
        ball_in_future_location = Vec3(find_slice_at_time(ball_prediction, gi.packet.game_info.seconds_elapsed + 2).physics.location)
        target_location = ball_in_future_location.flat() + (ball_in_future_location.flat() - Vec3(gi.field.opponent_goal.location)).rescale(2200).flat()
        with Renderer(gi.bot.renderer) as r:
            r.draw_line_3d(ball_location, target_location, r.cyan())
    else:
        target_location = ball_location + (ball_location - Vec3(gi.field.opponent_goal.location)).rescale(100)

    # Draw some things to help understand what the bot is thinking
    with Renderer(gi.bot.renderer) as r:
        r.draw_line_3d(gi.car.location, target_location, r.white())
        r.draw_string_3d(gi.car.location, 1, 1, f'Speed: {gi.car.velocity.length():.1f}', r.white())
        r.draw_rect_3d(target_location, 8, 8, True, r.cyan(), centered=True)

    controls = SimpleControllerState()
    controls.steer = gi.car.steer_toward_target(target_location)
    controls.throttle = 1.0
    controls.boost = abs(controls.steer) < 0.2 and gi.car.velocity.length() < 2000
    # controls.handbrake = abs(controls.steer) > 0.99 and gi.car.location.dist(ball_location) > 1000

    return Sequence([SingleStep(controls)])
Ejemplo n.º 16
0
    def get_output(self,
                   game_tick_packet: GameTickPacket) -> SimpleControllerState:
        # Get the direction to the ball
        car = game_tick_packet.game_cars[self.index]
        ball_pos = game_tick_packet.game_ball.physics.location
        to_ball_x = ball_pos.x - car.physics.location.x
        to_ball_y = ball_pos.y - car.physics.location.y
        dist_to_ball = math.sqrt(to_ball_x**2 + to_ball_y**2)
        if dist_to_ball == 0: return SimpleControllerState()
        to_ball_x /= dist_to_ball
        to_ball_y /= dist_to_ball

        # How is the car aligned with the direction to the ball?
        yaw = float(car.physics.rotation.yaw)
        car_left_x = -math.sin(yaw)
        car_left_y = math.cos(yaw)
        dot_product = to_ball_x * car_left_x + to_ball_y * car_left_y

        # Act on the information above.
        controller_state = SimpleControllerState()
        controller_state.throttle = 1.0
        controller_state.steer = min(
            1, max(-1, self.steering_coefficient * dot_product))
        controller_state.boost = abs(dot_product) < .1
        controller_state.handbrake = abs(dot_product) > .9
        return controller_state
Ejemplo n.º 17
0
 def get_output(self, game_tick_packet: GameTickPacket) -> SimpleControllerState:
     controller_state = SimpleControllerState()
     controller_state.throttle = 1
     controller_state.boost = True
     controller_state.steer = -1 if int(game_tick_packet.game_info.seconds_elapsed) % 2 == 0 else 1
     self.renderer.draw_line_3d((0, 0, 50), (0, 0, 2000), self.renderer.orange())
     return controller_state
Ejemplo n.º 18
0
def go_towards_point_with_timing(data: Data,
                                 point: Vec3,
                                 eta: float,
                                 slide=False,
                                 alpha=1.25):
    controller_state = SimpleControllerState()

    car_to_point = point - data.car.location
    point_rel = data.car.relative_location(point)
    steer_correction_radians = point_rel.ang()
    dist = car_to_point.length()

    set_normal_steering_and_slide(controller_state, steer_correction_radians,
                                  dist, slide)

    vel_f = data.car.velocity.proj_onto(car_to_point).length()
    avg_vel_f = dist / eta
    target_vel_f = rlmath.lerp(vel_f, avg_vel_f, alpha)

    if vel_f < target_vel_f:
        controller_state.throttle = 1.0
        # boost?
        if target_vel_f > 1410:
            if not data.car.is_on_wall and not controller_state.handbrake and data.car.velocity.length(
            ) < 2000:
                if is_heading_towards2(steer_correction_radians, dist):
                    if data.car.orientation.up.ang_to(UP) < math.pi * 0.3:
                        controller_state.boost = True
    elif (vel_f - target_vel_f) > 80:
        controller_state.throttle = -0.6
    elif (vel_f - target_vel_f) > 100:
        controller_state.throttle = -1.0

    return controller_state
Ejemplo n.º 19
0
def exampleController(agent, target_object, target_speed):
    location = toLocal(target_object, agent.me)
    controller_state = SimpleControllerState()
    angle_to_ball = math.atan2(location.data[1], location.data[0])

    current_speed = velocity2D(agent.me)
    #steering
    controller_state.steer = steer(angle_to_ball)

    #throttle
    if target_speed > current_speed:
        controller_state.throttle = 1.0
        if target_speed > 1400 and agent.start > 2.2 and current_speed < 2250:
            controller_state.boost = True
    elif target_speed < current_speed:
        controller_state.throttle = 0

    #dodging
    time_difference = time.time() - agent.start
    if time_difference > 2.2 and distance2D(target_object, agent.me) > (
            velocity2D(agent.me) * 2.5) and abs(angle_to_ball) < 1.3:
        agent.start = time.time()
    elif time_difference <= 0.1:
        controller_state.jump = True
        controller_state.pitch = -1
    elif time_difference >= 0.1 and time_difference <= 0.15:
        controller_state.jump = False
        controller_state.pitch = -1
    elif time_difference > 0.15 and time_difference < 1:
        controller_state.jump = True
        controller_state.yaw = controller_state.steer
        controller_state.pitch = -1

    return controller_state
Ejemplo n.º 20
0
 def run(self, my_car, packet, agent):
     car_location = Vec3(my_car.physics.location)
     vertical_vel = my_car.physics.velocity.z
     controls = SimpleControllerState()
     controls.yaw = steer_toward_target(
         my_car, self.target, -my_car.physics.angular_velocity.z / 6)
     controls.boost = not (vertical_vel < 0 and car_location.z > 40
                           and self.tick < 20)
     controls.use_item = car_location.dist(
         Vec3(packet.game_ball.physics.location
              )) < 200 and relative_location(
                  car_location, Orientation(my_car.physics.rotation),
                  Vec3(packet.game_ball.physics.location)).z < 75
     if self.tick == 0:
         controls.jump = True
         self.tick = 1
     else:
         if self.tick <= 10: self.tick += 1
         elif my_car.has_wheel_contact: agent.stack.pop()
         if vertical_vel < 0 and car_location.z > 40 and self.tick < 20:
             self.tick += 1
             controls.pitch = 1
         if vertical_vel < 0 and car_location.z < 40:
             controls.jump = True
             controls.pitch = -1
             controls.yaw = 0
     return controls
Ejemplo n.º 21
0
def exampleController(agent, target_object,target_speed):
    distance = distance2D(agent.me.location,target_object.location)
    if distance > 400:
        #print("switching to efficient")
        agent.state = efficientMover
        return efficientMover(agent,target_object,target_speed)

    controller_state = SimpleControllerState()
    controller_state.handbrake = False

    car_direction = get_car_facing_vector(agent.me)
    car_to_ball =  agent.me.location - target_object.location

    steer_correction_radians = steer(car_direction.correction_to(car_to_ball))

    current_speed = getVelocity(agent.me.velocity)
    #steering
    controller_state.steer = steer(steer_correction_radians)

    #throttle
    if target_speed > current_speed:
        controller_state.throttle = 1.0
        if target_speed > 1400 and current_speed < 2250:
            controller_state.boost = True
    elif target_speed < current_speed:
        controller_state.throttle = 0

    return controller_state
Ejemplo n.º 22
0
def reach_point_with_timing_and_vel(data: Data,
                                    point: Vec3,
                                    eta: float,
                                    vel_d: float,
                                    slide=False):
    controller_state = SimpleControllerState()

    car_to_point = point.flat() - data.car.location
    point_rel = data.car.relative_location(point)
    steer_correction_radians = point_rel.ang()
    dist = car_to_point.length()

    set_normal_steering_and_slide(controller_state, steer_correction_radians,
                                  dist, slide)

    vel_f = data.car.velocity.proj_onto(car_to_point).length()
    acc_f = -2 * (2 * vel_f * eta + eta * vel_d - 3 * dist) / (eta * eta)
    if abs(steer_correction_radians) > 1:
        acc_f = acc_f * steer_correction_radians * steer_correction_radians

    force = acc_f / (1410 - vel_f)

    controller_state.throttle = min(max(-1, force), 1)
    # boost?
    if force > 1:
        if not data.car.is_on_wall and not controller_state.handbrake and data.car.velocity.length(
        ) < 2000:
            if is_heading_towards2(steer_correction_radians, dist):
                if data.car.orientation.up.ang_to(UP) < math.pi * 0.3:
                    controller_state.boost = True

    return controller_state
Ejemplo n.º 23
0
    def action_goto(self, my_car, car_location, target_location):
        controller = SimpleControllerState()

        if target_location is None:
            return controller
        car_to_target = target_location - car_location

        # Find the direction of our car using the Orientation class
        car_orientation = Orientation(my_car.physics.rotation)
        car_direction = car_orientation.forward

        steer_correction_radians = find_correction(car_direction,
                                                   car_to_target)

        if steer_correction_radians > 0:
            # Positive radians in the unit circle is a turn to the left.
            turn = -1.0  # Negative value for a turn to the left.
            self.action_display = "turn left"
        else:
            turn = 1.0
            self.action_display = "turn right"

        controller.throttle = 1.0
        controller.steer = turn
        controller.boost = True

        return controller
Ejemplo n.º 24
0
    def exec(self, bot) -> SimpleControllerState:
        ct = time.time() - self._start_time
        controls = SimpleControllerState()
        controls.throttle = 1

        car = bot.data.my_car

        # Target is allowed to be a function that takes bot as a parameter. Check what it is
        if callable(self.target):
            target = self.target(bot)
        else:
            target = self.target

        # To boost or not to boost, that is the question
        car_to_target = target - car.pos
        vel_p = proj_onto_size(car.vel, car_to_target)
        angle = angle_between(car_to_target, car.forward())
        controls.boost = self.boost and angle < self._boost_ang_req and vel_p < self._max_speed

        # States of dodge (note reversed order)
        # Land on ground
        if ct >= self._t_finishing:
            self._almost_finished = True
            if car.on_ground:
                self.done = True
            else:
                bot.maneuver = RecoveryManeuver(bot)
                self.done = True
            return controls
        elif ct >= self._t_second_unjump:
            # Stop pressing jump and rotate and wait for flip is done
            pass
        elif ct >= self._t_aim:
            if ct >= self._t_second_jump:
                controls.jump = 1

            # Direction, yaw, pitch, roll
            if self.target is None:
                controls.roll = 0
                controls.pitch = -1
                controls.yaw = 0
            else:
                target_local = dot(car_to_target, car.rot)
                target_local.z = 0

                direction = normalize(target_local)

                controls.roll = 0
                controls.pitch = -direction.x
                controls.yaw = sign(car.rot.get(2, 2)) * direction.y

        # Stop pressing jump
        elif ct >= self._t_first_unjump:
            pass

        # First jump
        else:
            controls.jump = 1

        return controls
Ejemplo n.º 25
0
 def move_towards_point(self, my_car, point, boost: bool) -> SimpleControllerState:
      # Set the final controls based off of above decision making
     controls = SimpleControllerState()
     controls.steer = steer_toward_target(my_car, point)
     controls.throttle = 1.0
     if boost:
         controls.boost = True
     return controls
Ejemplo n.º 26
0
 def input(self):
     controller_input = SimpleControllerState()
     controller_input.throttle = 1
     if self.boost == 1:
         controller_input.boost = 1
     controller_input.handbrake = 1
     controller_input.steer = self.direction
     return controller_input
Ejemplo n.º 27
0
def hermite_update(fieldstate):
    spline_pos, spline_d = h_spline.get(
        fieldstate.elapsed_time() - spline_start, spline_scale)

    goal_position = spline_pos
    error_vector = goal_position - fieldstate.car_location()

    correction_angle = fieldstate.car_facing_vector().correction_to(
        error_vector)

    goal_velocity = spline_d
    goal_angle = fieldstate.car_facing_vector().correction_to(spline_d)

    output = SimpleControllerState()

    #velocity PID
    vel_pid_out = vel_pid.update(goal_velocity.length(),
                                 fieldstate.car_velocity().length(),
                                 fieldstate.delta_time())

    position_pid_out = position_pid.update(error_vector.length(), 0,
                                           fieldstate.delta_time())

    output.throttle = clamp(vel_pid_out + position_pid_out, 1.0, -1.0)

    #heading PID

    heading_pid_out = heading_pid.update(-goal_angle * sign(output.throttle),
                                         0, fieldstate.delta_time())

    heading_abs_pid_out = heading_abs_pid.update(
        -correction_angle * sign(output.throttle), 0, fieldstate.delta_time())

    output.steer = clamp(heading_pid_out + heading_abs_pid_out, 1.0, -1.0)

    # fi.write("{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format(
    #     fieldstate.elapsed_time(),
    #     error_vector.length() * sign(Vector3.dot(error_vector, fieldstate.car_facing_vector().normalize())),
    #     goal_position.x,
    #     goal_position.y,
    #     fieldstate.car_location().x,
    #     fieldstate.car_location().y,
    #     goal_velocity.length(),
    #     fieldstate.car_velocity().length(),
    #     math.atan2(spline_d.y, spline_d.x),
    #     math.atan2(fieldstate.car_facing_vector().y, fieldstate.car_facing_vector().x),
    #     vel_pid_out,
    #     position_pid_out,
    #     heading_pid_out,
    #     heading_abs_pid_out,
    #     output.throttle,
    #     output.steer
    # ))

    if goal_velocity.length() > 1400:
        output.boost = True

    return output
Ejemplo n.º 28
0
 def get_controller_state_from_actions(
         action: np.ndarray) -> SimpleControllerState:
     controls = action.clip(-1, 1)
     controller_state = SimpleControllerState()
     controller_state.pitch = controls[0]
     controller_state.yaw = controls[1]
     controller_state.roll = controls[2]
     controller_state.boost = bool(controls[3] >= 0)
     return controller_state
Ejemplo n.º 29
0
def get_controls(game_info, sub_state_machine):

    controls = SimpleControllerState()
    controls.throttle = 1
    controls.boost = 1
    controls.steer = -1

    persistent = game_info.persistent
    return controls, persistent
Ejemplo n.º 30
-1
def goto(target_location, target_speed, my_car, agent, packet):
    car_speed = Vec3(my_car.physics.velocity).length()
    distance = Vec3(my_car.physics.location).flat().dist(
        target_location.flat())
    angle = Orientation(
        my_car.physics.rotation).forward.ang_to(target_location -
                                                Vec3(my_car.physics.location))
    controls = SimpleControllerState()
    controls.steer = steer_toward_target(my_car, target_location, 0)
    controls.yaw = steer_toward_target(my_car, target_location,
                                       -my_car.physics.angular_velocity.z / 6)
    controls.throttle = cap(target_speed - car_speed, -1, 1)
    controls.boost = (target_speed > 1410
                      and abs(target_speed - car_speed) > 20 and angle < 0.3)
    controls.handbrake = angle > 2.3
    controls.jump = (1 if my_car.physics.location.y >= 0 else -1) == (
        1 if agent.team == 1 else -1
    ) and abs(
        my_car.physics.location.y) > 5000 and my_car.physics.location.z > 200
    controls.use_item = Vec3(my_car.physics.location).dist(
        Vec3(packet.game_ball.physics.location)) < 200 and relative_location(
            Vec3(my_car.physics.location), Orientation(
                my_car.physics.rotation),
            Vec3(packet.game_ball.physics.location)).z < 75
    if (abs(target_speed - car_speed) > 20 and angle < 0.3 and
            distance > 600) and ((target_speed > 1410 and my_car.boost == 0)
                                 or 700 < car_speed < 800):
        agent.stack.append(wavedash(target_location))
    return controls