Exemple #1
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
Exemple #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
Exemple #3
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
Exemple #4
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
Exemple #5
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
Exemple #6
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
Exemple #7
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
Exemple #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)
Exemple #9
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
Exemple #10
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
Exemple #11
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
Exemple #12
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
Exemple #13
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
Exemple #14
0
    def get_output(self, packet: GameTickPacket) -> Optional[SimpleControllerState]:
        controller = SimpleControllerState()
        bot = PhysicsObject(packet.game_cars[self.agent.index].physics)

        if packet.game_info.seconds_elapsed > self.next_dodge_time:
            controller.jump = True

            # Calculate pitch and roll based on target and bot position

            # Correct yaw from (0 to pi to -pi to 0), to (0 to 2pi).
            # Then rotate circle by pi/2 degrees. Then flip circle vertically.
            yaw = bot.rotation.z
            if yaw < 0:
                yaw += 2 * math.pi
            yaw -= math.pi / 2
            if yaw < 0:
                yaw += 2 * math.pi
            yaw = 2 * math.pi - yaw

            direction_to_target = (self.target - bot.location).normalised()
            angle_to_target = math.atan2(direction_to_target.y, direction_to_target.x)
            angle = angle_to_target - yaw

            controller.pitch = -math.cos(angle)
            controller.roll = math.sin(angle)

            if self.on_second_jump:
                return None
            else:
                self.on_second_jump = True
                self.next_dodge_time = packet.game_info.seconds_elapsed + self.dodge_time
        else:
            controller.jump = False

        return controller
Exemple #15
0
def shotController(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])

    location = toLocal(target_object, agent.me)
    controller_state = SimpleControllerState()
    angle_to_target = math.atan2(location.data[1], location.data[0])

    current_speed = velocity2D(agent.me)
    #steering
    if angle_to_target > 0.1:
        controller_state.steer = controller_state.yaw = 1
    elif angle_to_target < -0.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 = 0

    #dodging
    time_difference = time.time() - agent.start
    if time_difference > 2.2 and distance2D(target_object, agent.me) <= 270:
        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 = math.sin(goal_angle)
        controller_state.pitch = -abs(math.cos(goal_angle))

    return controller_state
Exemple #16
0
def simple_front_flip_chain():
    first_controller = SimpleControllerState()
    second_controller = SimpleControllerState()
    third_controller = SimpleControllerState()

    first_controller.jump = True
    first_duration = 0.1

    second_controller.jump = False
    second_controller.pitch = -1
    second_duration = 0.1

    third_controller.jump = True
    third_controller.pitch = -1
    third_duration = 0.1

    return Action_chain([first_controller,second_controller,third_controller],[first_duration,second_duration,
                                                                               third_duration])
Exemple #17
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
Exemple #18
0
def shotController(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)

    # 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)

    time_diff = time.time() - agent.start 

    #dodging
    time_diff = time.time() - agent.start 
    if (time_diff > 2.2 and distance <= 270) or (time_diff > 4 and distance >= 1000):
        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
Exemple #19
0
    def update(self):
        controller_state = SimpleControllerState()
        if not self.firstJump:
            controller_state.throttle = -1
            controller_state.jump = True
            controller_state.pitch = 1
            self.firstJump = True
            self.jumpStart = time.time()
            return controller_state

        elif self.firstJump and not self.secondJump:
            jumpTimer = time.time() - self.jumpStart
            controller_state.throttle = -1
            controller_state.pitch = 1
            controller_state.jump = False
            if jumpTimer < 0.12:
                controller_state.jump = True
            if jumpTimer > 0.15:
                controller_state.jump = True
                self.jumpStart = time.time()
                self.secondJump = True
            return controller_state

        elif self.firstJump and self.secondJump:
            timer = time.time() - self.jumpStart
            if timer < 0.15:
                controller_state.throttle = -1
                controller_state.pitch = 1

            else:
                controller_state.pitch = -1
                controller_state.throttle = 1
                controller_state.roll = 1

            if timer > .8:
                controller_state.roll = 0
            if timer > 1.15:
                self.active = False
            return controller_state

        else:
            print(
                "halfFlip else conditional called in update. This should not be happening"
            )
Exemple #20
0
def chase_controller(agent, target_object,
                     target_speed):  #note target location is an obj
    location = toLocal(target_object, agent.car)
    controller_state = SimpleControllerState()
    angle_to_ball = math.atan2(location.data[1], location.data[0])
    current_speed = velocity2D(agent.car)
    ball_path = agent.get_ball_prediction_struct(
    )  #next 6 seconds of ball's path
    print(bal_path[1])

    #to steer
    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

        #adjust speed
    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

        #techniquing
    time_diff = time.time() - agent.start  #time since last technique
    if time_diff > 2.2 and distance2D(
            target_object.location,
            agent.car.location) > 1000 and abs(angle_to_ball) < 1.3:
        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
    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
Exemple #21
0
def shot_controller(agent, target_object,
                    target_speed):  #note target location is an obj
    local_goal_location = toLocal([0, FIELD_LENGTH / 2, 100], agent.car)
    goal_angle = math.atan2(local_goal_location.data[1],
                            local_goal_location.data[0])

    location = toLocal(target_object, agent.car)
    controller_state = SimpleControllerState()
    angle_to_target = math.atan2(location.data[1], location.data[0])
    current_speed = velocity2D(agent.car)

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

        #adjust speed
    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

        #techniquing
    time_diff = time.time() - agent.start  #time since last technique
    if time_diff > 2.2 and distance2D(target_object, agent.car) > 270:
        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))

    return controller_state
Exemple #22
0
def shotController(agent, target_object, target_speed, goal=None):
    if goal == None:
        goal = [0, -sign(agent.team) * FIELD_LENGTH / 2, 100]
    goal_local = toLocal(goal, agent.me)
    goal_angle = math.atan2(goal_local.data[1], goal_local.data[0])
    location = toLocal(target_object, agent.me)
    controller_state = SimpleControllerState()
    angle_to_target = math.atan2(location.data[1], location.data[0])

    current_speed = velocity1D(agent.me).data[1]  #velocity2D(agent.me)
    #steering
    controller_state.steer = steer(angle_to_target)

    #throttle
    if target_speed > 1400 and target_speed > current_speed and agent.start > 2.5 and current_speed < 2250 and agent.me.grounded == True:
        controller_state.boost = True
    if target_speed > current_speed:
        controller_state.throttle = 1.0
    elif target_speed < current_speed:
        controller_state.throttle = -1.0

    #dodging
    closing = distance2D(target_object, agent.me) / cap(
        -dpp(target_object, agent.ball.velocity, agent.me.location,
             agent.me.velocity), 1, 2300)
    time_difference = time.time() - agent.start
    if ballReady(
            agent) and time_difference > 2.2 and closing <= 0.8 and distance2D(
                agent.me, target_object) < 200:
        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 = math.sin(goal_angle)
        controller_state.pitch = -abs(math.cos(goal_angle))

    return controller_state
Exemple #23
0
def take_shot_controller(agent, target_object, target_speed):
    goal_local = toLocation([0, -sign(agent.team) * FIELD_LENGTH / 2, 100])
    goal_angle = math.atan2(goal_local.data[1], goal_local.data[0])

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

    location = toLocation(target_object)
    controller_state = SimpleControllerState()
    angle_to_target = math.atan2(location.data[1], location.data[0])

    current_speed = velocity2D(agent.me)

    controller_state.steer = cap(angle_to_target * 5, -1, 1)

    # 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

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

    if time_difference > 2.2 and abs(angle_to_target) < 1.3 and velocity2D(
            agent.me) > 1200 and distance2D(target_object, agent.me) < 1000:
        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 = cap(math.sin(goal_angle) / math.pi, -1, 1)
        controller_state.pitch = -1

    # print("target: " + str(target_speed) + ", current: " + str(current_speed))
    return controller_state
Exemple #24
0
 def to_simple_controller_state(self):
     controls = SimpleControllerState()
     controls.throttle = self.throttle
     controls.steer = self.steer
     controls.yaw = self.yaw
     controls.pitch = self.pitch
     controls.roll = self.roll
     controls.boost = self.boost
     controls.jump = self.jump
     controls.handbrake = self.handbrake
     return controls
Exemple #25
0
def recoveryController(agent, local): #accepts agent, the agent's controller, and a target (in local coordinates)
    controller_state = SimpleControllerState()

    turn = math.atan2(local.data[1],local.data[0])
    up =  toLocal(agent.me.location + Vector3([0,0,100]), agent.me)
    target = [math.atan2(up.data[1],up.data[2]), math.atan2(local.data[2],local.data[0]), turn] #determining angles each axis must turn
    controller_state.steer = steerPD(turn, 0)
    controller_state.yaw = steerPD(target[2],-agent.me.rvelocity.data[2]/5)
    controller_state.pitch = steerPD(target[1],agent.me.rvelocity.data[1]/5)
    controller_state.roll = steerPD(target[0],agent.me.rvelocity.data[0]/5)
    return controller_state
Exemple #26
0
def speedDodgeController(agent, target_object, goal_angle):

    controller_state = SimpleControllerState()

    #dodging
    time_diff = time.time() - agent.start 
    if time_diff > 2.2:
        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))
    
    return controller_state
Exemple #27
0
def getSensible_thingToCONTROL(magicWariable):
    ThisISTHE_controller = SimpleControllerState()
    ThisISTHE_controller.throttle = magicWariable[magicWariable[0][0]]
    ThisISTHE_controller.steer = magicWariable[magicWariable[0][1]]
    ThisISTHE_controller.pitch = magicWariable[magicWariable[0][2]]
    ThisISTHE_controller.yaw = magicWariable[magicWariable[0][3]]
    ThisISTHE_controller.roll = magicWariable[magicWariable[0][4]]
    ThisISTHE_controller.jump = magicWariable[magicWariable[0][5]]
    ThisISTHE_controller.boost = magicWariable[magicWariable[0][6]]
    ThisISTHE_controller.handbrake = magicWariable[magicWariable[0][7]]
    return ThisISTHE_controller
Exemple #28
0
    def update(self):
        controller_state = SimpleControllerState()
        jump = flipHandler(self.agent, self.flip_obj)
        if jump:
            if self.targetCode == 1:
                controller_state.pitch = -1
                controller_state.steer = 0
                controller_state.throttle = 1

            elif self.targetCode == 0:
                ball_local = toLocal(self.agent.ball.location, self.agent.me)
                ball_angle = math.atan2(ball_local.data[1], ball_local.data[0])
                controller_state.jump = True
                controller_state.yaw = math.sin(ball_angle)
                pitch = -math.cos(ball_angle)
                controller_state.pitch = pitch
                if pitch > 0:
                    controller_state.throttle = -1
                else:
                    controller_state.throttle = 1

            elif self.targetCode == 2:
                controller_state.pitch = 0
                controller_state.steer = 0
                controller_state.yaw = 0
            elif self.targetCode == 3:
                controller_state.pitch = 1
                controller_state.steer = 0
                controller_state.throttle = -1

            elif self.targetCode == -1:
                controller_state.pitch = 0
                controller_state.steer = 0
                controller_state.throttle = 0

        controller_state.jump = jump
        controller_state.boost = False
        if self.flip_obj.flipDone:
            self.active = False

        return controller_state
Exemple #29
0
    def exec(self, bot) -> SimpleControllerState:
        man_ct = bot.info.time - self.maneuver_start_time
        controls = SimpleControllerState()

        car = bot.info.my_car
        vel_f = proj_onto_size(car.vel, car.forward)

        # Reverse a bit
        if vel_f > -50 and man_ct < 0.3:
            controls.throttle = -1
            self.halfflip_start_time = bot.info.time
            return controls

        ct = bot.info.time - self.halfflip_start_time

        # States of jump
        if ct >= self._t_finishing:
            self._almost_finished = True
            controls.throttle = 1
            controls.boost = self.boost
            if car.on_ground:
                self.done = True
            else:
                bot.maneuver = RecoveryManeuver()
                self.done = True
        elif ct >= self._t_roll_begin:
            controls.pitch = -1
            controls.roll = 1
        elif ct >= self._t_second_jump_end:
            controls.pitch = -1
        elif ct >= self._t_second_jump_begin:
            controls.jump = 1
            controls.pitch = 1
        elif ct >= self._t_first_jump_end:
            controls.pitch = 1
        else:
            controls.jump = 1
            controls.throttle = -1
            controls.pitch = 1

        return controls
Exemple #30
0
def deltaC(agent, target):
    c = SimpleControllerState()
    target = target  # - agent.me.velocity
    target_local = toLocal(agent.me.location + target, agent.me)
    angle_to_target = math.atan2(target_local.data[1], target_local.data[0])
    pitch_to_target = math.atan2(target_local.data[2], target_local.data[0])

    if agent.me.grounded:
        if agent.jt + 1.5 > time.time():
            c.jump = True
        else:
            c.jump = False
            agent.jt = time.time()
    else:
        c.yaw = steerPD(angle_to_target, -agent.me.rvelocity.data[1] / 4)
        c.pitch = steerPD(pitch_to_target, agent.me.rvelocity.data[0] / 4)
        if target.magnitude() > 10:
            c.boost = True
        if abs(pitch_to_target) + abs(angle_to_target) > 0.9:
            c.boost = False
        else:
            top = toLocal([
                agent.me.location.data[0], agent.me.location.data[1],
                agent.me.location.data[2] + 1000
            ], agent.me)
            roll_to_target = math.atan2(top.data[1], top.data[2])
            c.roll = steerPD(roll_to_target, agent.me.rvelocity.data[2] * 0.5)
        tsj = time.time() - agent.jt
        if tsj < 0.215:
            c.jump = True
        elif tsj < 0.25:
            c.jump = False
        elif tsj >= 0.25 and tsj < 0.27 and target.data[2] > 560:
            c.jump = True
            c.boost = False
            c.yaw = 0
            c.pitch = 0
            c.roll = 0
        else:
            c.jump = False
    return c