Example #1
0
def waitController(agent, target, speed):
    controller_state = SimpleControllerState()
    loc = toLocal(target, agent.me)
    angle_to_target = math.atan2(loc.data[1], loc.data[0])


    controller_state.steer = steer(angle_to_target)

    current_speed = velocity2D(agent.me) 
    if current_speed < speed:
        controller_state.throttle = 1.0
    elif current_speed - 50 > speed:
        controller_state.throttle = -1.0
    else:
        controller_state.throttle = 0

    time_diff = time.time() - agent.start
    if time_diff > 2.2 and distance2D(target,agent.me) > (velocity2D(agent.me)*2.3) and abs(angle_to_target) < 1 and current_speed < speed:
        agent.start = time.time()
    elif time_diff <= 0.1:
        controller_state.jump = True
        controller_state.pitch = -1
    elif time_diff >= 0.1 and time_diff <= 0.15:
        controller_state.jump = False
        controller_state.pitch = -1
    elif time_diff > 0.15 and time_diff < 1:
        controller_state.jump = True
        controller_state.yaw = controller_state.steer
        controller_state.pitch = -1

    return controller_state
Example #2
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
Example #3
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
Example #4
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
Example #5
0
    def setHalfFlip(self):
        #_time = self.time
        #if _time - self.flipTimer >= 1.9:
        controls = []
        timers = []

        control_1 = SimpleControllerState()
        control_1.throttle = -1
        control_1.jump = True

        controls.append(control_1)
        timers.append(0.125)

        controls.append(SimpleControllerState())
        timers.append(self.fakeDeltaTime * 4)

        control_3 = SimpleControllerState()
        control_3.throttle = -1
        control_3.pitch = 1
        control_3.jump = True
        controls.append(control_3)
        timers.append(self.fakeDeltaTime * 4)

        control_4 = SimpleControllerState()
        control_4.throttle = -1
        control_4.pitch = -1
        control_4.roll = -.1
        #control_4.jump = True

        controls.append(control_4)
        timers.append(0.5)

        self.activeState = Divine_Mandate(self, controls, timers)

        self.flipTimer = self.time
Example #6
0
def frugal_controller(agent, target, speed):
    controller_state = SimpleControllerState()
    location = return_local_location(target, agent.me)
    angle_to_target = math.atan2(location.data[1], location.data[0])

    controller_state.steer = steer(angle_to_target)

    current_speed = velocity_2d(agent.me)
    if current_speed < speed:
        controller_state.throttle = 1.0
    elif current_speed - 50 > speed:
        controller_state.throttle = -1.0
    else:
        controller_state.throttle = 0

    if distance_2d(agent.me.location.data, target) < 250:
        controller_state.handbrake = 1

    # time_difference = time.time() - agent.start
    # if time_difference > 2.2 and distance_2d(target, agent.me) > (velocity_2d(agent.me) * 2.3) and abs(
    #         angle_to_target) < 1 and current_speed < speed:
    #     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
Example #7
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
Example #8
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
Example #9
0
    def input(self):

        controller_input = SimpleControllerState()
        theta = self.current_state.rot.yaw
        correction_vector = self.target_state.pos - self.current_state.pos

        facing_vector = Vec3(cos(theta), sin(theta), 0)


        car_to_target = (self.target_state.pos - self.current_state.pos).normalize()
        #Rotated to the car's reference frame on the ground.
        rel_correction_vector = Vec3((correction_vector.x*cos(theta)) + (correction_vector.y * sin(theta)),
                                     (-(correction_vector.x*sin(theta))) + (correction_vector.y * cos(theta)),
                                     0)

        if self.can_reverse and facing_vector.dot(car_to_target) < - 0.5:
            correction_angle = atan2(rel_correction_vector.y, rel_correction_vector.x)
            
            controller_input.throttle = - 1.0
            if abs(correction_angle) > 1.25:
                controller_input.handbrake = 1
            controller_input.steer = cap_magnitude(-5*correction_angle, 1)

        else:
            correction_angle = atan2(rel_correction_vector.y, rel_correction_vector.x)
            
            controller_input.throttle = 1.0
            if abs(correction_angle) > 1.25:
                controller_input.handbrake = 1
            controller_input.steer = cap_magnitude(5*correction_angle, 1)

        return controller_input
Example #10
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)])
Example #11
0
    def update(self):
        if self.agent.me.location[2] < 600:
            if self.agent.onSurface or self.agent.me.location[2] < 100:
                self.active = False
            controller_state = SimpleControllerState()

            if self.agent.me.rotation[2] > 0:
                controller_state.roll = -1

            elif self.agent.me.rotation[2] < 0:
                controller_state.roll = 1

            if self.agent.me.rotation[0] > self.agent.velAngle:
                controller_state.yaw = -1

            elif self.agent.me.rotation[0] < self.agent.velAngle:
                controller_state.yaw = 1

            if self.active:
                controller_state.throttle = 1
            else:
                controller_state.throttle = 0
        else:
            controller_state = SimpleControllerState()

        return controller_state
Example #12
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
Example #13
0
    def input(self):
        controller_input = SimpleControllerState()
        current_angle_vec = Vec3(cos(self.current_state.rot.yaw), sin(self.current_state.rot.yaw), 0)
        goal_angle_vec = Vec3(cos(self.goal_state.rot.yaw), sin(self.goal_state.rot.yaw), 0)
        vel_2d = Vec3(self.current_state.vel.x, self.current_state.vel.y, 0)



        if (self.current_state.pos - self.goal_state.pos).magnitude() > 400:

            #Turn towards target. Hold throttle until we're close enough to start stopping.
            controller_input = GroundTurn(self.current_state, self.goal_state).input()

        elif vel_2d.magnitude() < 50 and current_angle_vec.dot(goal_angle_vec) < 0:

            #If we're moving slowly, but not facing the right way, jump to turn in the air.
            #Decide which way to turn.  Make sure we don't have wraparound issues.

            goal_x = goal_angle_vec.x
            goal_y = goal_angle_vec.y
            car_theta = self.current_state.rot.yaw


            #Rotated to the car's reference frame on the ground.
            rel_vector = Vec3((goal_x*cos(car_theta)) + (goal_y * sin(car_theta)),
                              (-(goal_x*sin(car_theta))) + (goal_y * cos(car_theta)),
                              0)

            correction_angle = atan2(rel_vector.y, rel_vector.x)

            #Jump and turn to reach goal yaw.
            if self.current_state.wheel_contact:
                controller_input.jump = 1
            else:
                controller_input.yaw = cap_magnitude(correction_angle, 1)

        elif self.current_state.vel.magnitude() > 400:
            #TODO: Proportional controller to stop in the right place
            controller_input.throttle = -1


        else:
            #Wiggle to face ball
            #Check if the goal is ahead of or behind us, and throttle in that direction
            goal_angle = atan2((self.goal_state.pos - self.current_state.pos).y, (self.goal_state.pos - self.current_state.pos).x)
            if abs(angle_difference(goal_angle,self.current_state.rot.yaw)) > pi/2:
                correction_sign = -1
            else:
                correction_sign = 1
            controller_input.throttle = correction_sign

            #Correct as we wiggle so that we face goal_yaw.
            if angle_difference(self.goal_state.rot.yaw, self.current_state.rot.yaw) > 0:
                angle_sign = 1
            else:
                angle_sign = -1

            controller_input.steer = correction_sign*angle_sign

        return controller_input
Example #14
0
def frugalController(agent, target, speed):
    controller_state = SimpleControllerState()
    location = toLocal(target, agent.me)
    angle_to_target = math.atan2(location.data[1], location.data[0])

    controller_state.steer = steer(angle_to_target)

    speed -= ((angle_to_target**2) * 300)
    current_speed = velocity1D(agent.me).data[1]
    if current_speed < speed:
        controller_state.throttle = 1.0
    elif current_speed - 50 > speed:
        controller_state.throttle = -1.0
    else:
        controller_state.throttle = 0

    time_difference = time.time() - agent.start
    if time_difference > 2.2 and distance2D(
            target, agent.me) > (velocity2D(agent.me) * 2.3) and abs(
                angle_to_target
            ) < 0.9 and current_speed < speed and current_speed > 220:
        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
Example #15
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
Example #16
0
    def resolve(self, prev_status, car, packet: GameTickPacket):
        point = self.pointFunc(car, packet)
        car_location = Vec3(car.physics.location.x, car.physics.location.y)
        car_direction = rlmath.get_car_facing_vector(car)
        yaw_velocity = car.physics.angular_velocity.x
        car_velocity = Vec3(car.physics.velocity.x, car.physics.velocity.y)
        car_to_point = point - car_location

        steer_correction_radians = rlmath.fix_ang(
            car_direction.ang_to_flat(car_to_point) + yaw_velocity * 0.2)
        velocity_correction_radians = car_velocity.ang_to_flat(car_to_point)

        controller = SimpleControllerState()

        if abs(steer_correction_radians) > 0.5:
            controller.handbrake = True
        else:
            return (SUCCESS, self.parent, None)

        if steer_correction_radians > 0:
            controller.steer = 1
        elif steer_correction_radians < 0:
            controller.steer = -1

        controller.throttle = 0.3
        # In these cases we want to brake instead
        if car_velocity.length() > 500:
            controller.throttle = 0

        return (ACTION, self, controller)
Example #17
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)
Example #18
0
    def exampleController(self, target_object, target_speed):
        location = target_object.local_location
        controller_state = SimpleControllerState()
        angle_to_ball = math.atan2(location.data[1], location.data[0])
        current_speed = velocity2D(self.me)

        #team
        team = sign(self.team)
        # if team<=0:   #blue
        #try to get the ball to orange goal
        #else:    #orange
        #try to get the ball to blue goal

        #steering
        if angle_to_ball > 0.1:
            controller_state.steer = controller_state.yaw = 1
        elif angle_to_ball < -0.1:
            controller_state.steer = controller_state.yaw = -1
        else:
            controller_state.steer = controller_state.yaw = 0

        #powersliding
        if angle_to_ball > 0.8:
            controller_state.handbrake = True
        elif angle_to_ball < -0.8:
            controller_state.handbrake = True
        else:
            controller_state.handbrake = False

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

        #dodging front only
        time_difference = time.time() - self.start
        if time_difference > 2.2 and distance2D(
                target_object.location,
                self.me.location) > 1000 and abs(angle_to_ball) < 1.3:
            self.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
Example #19
0
def calcController(agent, target_object, target_speed):
    goal_local = toLocal([0, -sign(agent.team)*FIELD_LENGTH/2, 100], agent.me)
    goal_angle = math.atan2(goal_local.data[1], goal_local.data[0])
    
    loc = toLocal(target_object, agent.me)
    controller_state = SimpleControllerState()
    
    angle_to_targ = math.atan2(loc.data[1],loc.data[0])

    current_speed = velocity2D(agent.me)
    distance = distance2D(target_object, agent.me)

    #steering 
    controller_state.steer = steer(angle_to_targ)

    r = radius(current_speed)
    slowdown = (Vector3([0,sign(target_object.data[0])*(r+40),0])-loc.flatten()).magnitude() / cap(r*1.5,1,1200)
    target_speed = cap(current_speed*slowdown,0,current_speed)


    # throttle
    if agent.ball.location.data[0] == 0 and agent.ball.location.data[1] == 0:
        controller_state.throttle, controller_state.boost = 1, True
    else:
        controller_state.throttle, controller_state.boost = throttle(target_speed,current_speed)


    #dodging
    time_diff = time.time() - agent.start 
    if (time_diff > 2.2 and distance <= 150) or (time_diff > 4 and distance >= 1000) and not kickoff(agent):
        agent.start = time.time()
    elif time_diff <= 0.1:
        controller_state.jump = True
        controller_state.pitch = -1
    elif time_diff >= 0.1 and time_diff <= 0.15:
        controller_state.jump = False
        controller_state.pitch = -1
    elif time_diff > 0.15 and time_diff < 1:
        controller_state.jump = True
        controller_state.yaw = math.sin(goal_angle)
        controller_state.pitch = -abs(math.cos(goal_angle))
        
    if not dodging(agent) and not agent.me.grounded:
        target = agent.me.velocity.normalize()
        targ_local = to_local(target.scale(500), agent.me)

        return recoveryController(agent, targ_local)
    
    return controller_state
Example #20
0
    def shotController(self, agent):
        controller_state = SimpleControllerState()
        goal_location = toLocal(
            [0, -sign(agent.team) * FIELD_LENGTH / 2, 0],
            agent.me)  #100 is arbitrary since math is in 2D still
        goal_angle = np.arctan2(goal_location[1], goal_location[0])
        #print(goal_angle * 180 / np.pi)

        location = toLocal(agent.ball, agent.me)
        angle_to_target = np.arctan2(location[1], location[0])
        target_speed = velocity2D(
            agent.ball) + (distance2D(agent.ball, agent.me) / 1.5)

        current_speed = velocity2D(agent.me)
        #steering
        if angle_to_target > .1:
            controller_state.steer = controller_state.yaw = 1
        elif angle_to_target < -.1:
            controller_state.steer = controller_state.yaw = -1
        else:
            controller_state.steer = controller_state.yaw = 0
        #throttle
        if angle_to_target >= 1.4:
            target_speed -= 1400
        else:
            if (target_speed > 1400 and target_speed > current_speed
                    and agent.start > 2.2 and current_speed < 2250):
                controller_state.boost = True
        if target_speed > current_speed:
            controller_state.throttle = 1.0
        elif target_speed < current_speed:
            controller_state.throttle = 1

        #dodging
        time_difference = time.time() - agent.start
        if time_difference > 2.2 and distance2D(agent.ball, agent.me) <= 270:
            agent.start = time.time()
        elif time_difference <= .1:
            controller_state.jump = True
            controller_state.pitch = -1
        elif time_difference >= .1 and time_difference <= .15:
            controller_state.jump = False
            controller_state.pitch = -1
        elif time_difference > .15 and time_difference < 1:
            controller_state.jump = True
            controller_state.yaw = math.sin(goal_angle)
            controller_state.pitch = -abs(math.cos(goal_angle))

        return controller_state
Example #21
0
def follow_controller(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)

    pitch = agent.me.location.data[0] % math.pi
    roll = agent.me.location.data[2] % math.pi

    # Turn dem wheels
    controller_state.steer = cap(angle_to_ball * 5, -1, 1)
    print(velocity2D(agent.me))

    if abs(angle_to_ball) > (math.pi / 3.):
        controller_state.handbrake = True
    else:
        controller_state.handbrake = False

    # throttle
    if target_speed > current_speed:
        controller_state.throttle = 1.0
        if target_speed > 1400 and agent.start > 2.2 and current_speed < 2250 and abs(
                angle_to_ball) < (math.pi / 3.):
            controller_state.boost = True
    elif target_speed < current_speed:
        controller_state.throttle = 0

    # doging
    time_difference = time.time() - agent.start

    if time_difference > 2.2 and distance2D(
            target_object,
            agent.me) > 1000 and abs(angle_to_ball) < 1.3 and velocity2D(
                agent.me) > 1200:
        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

    # print("target: " + str(target_speed) + ", current: " + str(current_speed))
    return controller_state
Example #22
0
def CeilingRushController(
        agent, target_object1,
        target_object2):  #target_object es un objeto tipo obj
    controller_state = SimpleControllerState()
    '''if distance2D(agent.me,agent.pointA)<distance2D(agent.me,agent.pointB) and agent.me.location.data[2]>2800:
            target_object = target_object2
            location = agent.pointB.local_location
            angle_to_target = math.atan2(location.data[1],location.data[0])
        else:
            target_object = target_object1
            location = agent.pointA.local_location
            angle_to_target = math.atan2(location.data[1],location.data[0])'''
    target_object = target_object1
    location = agent.pointA.local_location
    angle_to_target = math.atan2(location.data[1], location.data[0])
    draw_debug(agent, agent.renderer, target_object.location.data)
    angle_velocity = math.atan2(agent.me.velocity.data[1],
                                agent.me.velocity.data[1])
    #draw_debug(agent.renderer,target_object.location.data)

    current_speed = velocity2D(agent.me)
    #steering
    if abs(angle_to_target) < math.pi / 4:
        controller_state.handbrake = False
    elif abs(angle_to_target) < math.pi and abs(angle_to_target) > math.pi / 2:
        controller_state.handbrake = True
    if agent.me.location.data[2] < 1800:
        controller_state.steer = sign(angle_to_target) * min(
            1, abs(2 * angle_to_target))
    else:
        controller_state.steer = 0
    #throttle
    controller_state.throttle = 1

    return controller_state
Example #23
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
Example #24
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
Example #25
0
def pid_steer(game_info, target_location, pid: SteerPID):
    """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

    angle = -np.arctan2(ball_direction.y, ball_direction.x)

    if angle > np.pi:
        angle -= 2 * np.pi
    elif angle < -np.pi:
        angle += 2 * np.pi

    # adjust angle
    turn_rate = pid.get_steer(angle)

    controller_state.throttle = 1
    controller_state.steer = turn_rate
    controller_state.jump = False
    return controller_state
Example #26
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
Example #27
0
def fix_orientation(data: Data, point=None):
    controller = SimpleControllerState()

    strength = 0.22
    ori = data.car.orientation

    if point is None and data.car.velocity.flat().length2() != 0:
        point = data.car.location + data.car.velocity.flat().rescale(500)

    pitch_error = -ori.pitch * strength
    controller.pitch = data.agent.pid_pitch.calc(pitch_error)

    roll_error = -ori.roll * strength
    controller.roll = data.agent.pid_roll.calc(roll_error)

    if point is not None:
        # yaw rotation can f up the other's so we scale it down until we are more confident about landing on the wheels
        car_to_point = point - data.car.location
        yaw_error = ori.front.ang_to_flat(car_to_point) * strength * 1.5
        land_on_wheels01 = 1 - ori.up.ang_to(UP) / (math.pi * 2)
        controller.yaw = data.agent.pid_yaw.calc(yaw_error) * (land_on_wheels01
                                                               **6)

    # !
    controller.throttle = 1
    return controller
Example #28
0
def calcController(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)
    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 = -1.0
    return controller_state
Example #29
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
Example #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