Example #1
0
    def __init__(self, car, target, t_arrival, up=vec3(0, 0, 1)):

        self.car = car
        self.target = target
        self.t_arrival = t_arrival
        self.up = up

        self.controls = Input()

        self.action = None
        self.state = self.JUMP if car.on_ground else self.AERIAL_APPROACH

        self.jump_duration = 0.2
        self.double_jump = AirDodge(car, self.jump_duration)
        self.aerial_turn = AerialTurn(car, self.car.theta)

        self.A = vec3(0, 0, 0)
        self.f = vec3(0, 0, 0)
        self.B_avg = 0

        self.counter = 0
        self.state_timer = 0.0
        self.total_timer = 0.0
        self.boost_counter = 0.0

        self.finished = False
Example #2
0
    def __init__(self, car, target='Recovery', timeout=5.0):

        self.found = False
        self.car = car
        self.trajectory = []

        if target == 'Recovery':

            self.find_landing_orientation(200)

        else:

            self.target = target

        self.timeout = timeout

        self.epsilon_omega = 0.01
        self.epsilon_theta = 0.04

        self.controls = Input()

        self.timer = 0.0
        self.finished = False
        self.relative_rotation = vec3(0, 0, 0)
        self.geodesic_local = vec3(0, 0, 0)
Example #3
0
    def __init__(self, car, target_pos=vec3(0, 0, 0), target_speed=0):

        self.car = car
        self.target_pos = target_pos
        self.target_speed = target_speed
        self.controls = Input()

        self.finished = False
Example #4
0
    def __init__(self, duration):

        self.duration = duration
        self.controls = Input()

        self.timer = 0
        self.counter = 0

        self.finished = False
Example #5
0
    def __init__(self, car, ball, goal):

        self.car = car
        self.ball = ball
        self.goal = goal
        self.controls = Input()
        self.p_s = 0

        self.finished = False
Example #6
0
 def car_trajectory(self, car: Car, end_time: float, dt: float = 1 / 10):
     steps = []
     test_car = Car(car)
     while test_car.time < end_time:
         dt = min(dt, end_time - test_car.time)
         test_car.step(Input(), dt)
         test_car.time += dt
         steps.append(vec3(test_car.pos))
     self.polyline(steps)
Example #7
0
    def __init__(self, car, use_boost=False):
        self.car = car
        self.use_boost = use_boost
        self.controls = Input()

        duration = 0.12
        behind = car.pos - 1000.0 * car.forward()
        self.dodge = AirDodge(self.car, duration, behind)

        self.s = 0.95 * sgn(dot(self.car.omega, self.car.up()) + 0.01)

        self.timer = 0.0

        self.finished = False
Example #8
0
    def __init__(self, car, duration=0.0, target=None, dodge_time=None):

        self.car = car
        self.target = target
        self.controls = Input()

        self.jump = Jump(duration)

        if duration <= 0:
            self.jump.finished = True

        self.counter = 0
        self.state_timer = 0.0
        self.total_timer = 0.0

        self.finished = False
Example #9
0
    def __init__(self, car, target):

        self.car = car
        self.target = target

        self.controls = Input()
        self.controls.handbrake = True

        direction = normalize(xy(target - car.pos))

        R = axis_rotation(-0.6 * cross(vec3(0, 0, 1), direction))

        self.turn = AerialTurn(car, dot(R, car.theta))

        self.counter = 0
        self.timer = 0.0

        self.finished = False
Example #10
0
    def find_landing_orientation(self, num_points):

        f = vec3(0, 0, 0)
        l = vec3(0, 0, 0)
        u = vec3(0, 0, 0)

        dummy = Car(self.car)
        self.trajectory.append(vec3(dummy.pos))
        for i in range(0, num_points):
            dummy.step(Input(), 0.0333)
            self.trajectory.append(vec3(dummy.pos))
            u = dummy.pitch_surface_normal()
            if norm(u) > 0.0 and i > 10:
                f = normalize(dummy.vel - dot(dummy.vel, u) * u)
                l = normalize(cross(u, f))
                self.found = True
                break

        if self.found:
            self.target = mat3(f[0], l[0], u[0], f[1], l[1], u[1], f[2], l[2],
                               u[2])
        else:
            self.target = self.car.theta
Example #11
0
 def __init__(self):
     self.controls = Input()
     self.finished = True
Example #12
0
    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        self.info.read_packet(packet)
        self.controls = SimpleControllerState()

        if self.timer == 0.0:

            self.csign = random.choice([-1, 1])

            # this just initializes the car and ball
            # to different starting points each time
            c_position = Vector3(random.uniform(-1000, 1000),
                                 random.uniform(-4500, -4000),
                                 25)

            car_state = CarState(physics=Physics(
                location=c_position,
                velocity=Vector3(0, 1000, 0),
                rotation=Rotator(0, 1.5 * self.csign, 0),
                angular_velocity=Vector3(0, 0, 0)
            ))

            self.bsign = random.choice([-1, 1])

            b_position = Vector3(random.uniform(-3500, -3000) * self.bsign,
                                 random.uniform(-1500,  1500),
                                 random.uniform(  150,   500))

            b_velocity = Vector3(random.uniform( 1000, 1500) * self.bsign,
                                 random.uniform(- 500,  500),
                                 random.uniform( 1000, 1500))

            ball_state = BallState(physics=Physics(
                location=b_position,
                velocity=b_velocity,
                rotation=Rotator(0, 0, 0),
                angular_velocity=Vector3(0, 0, 0)
            ))

            self.set_game_state(GameState(
                ball=ball_state,
                cars={self.index: car_state})
            )

            self.increment_timer = True

        if self.timer < 0.3:
            self.controls.throttle = 1 * self.csign
        else:
            if self.action == None:

                # set empty values for target and t_arrival initially
                self.action = Aerial(self.info.my_car, vec3(0,0,0), 0)

                # predict where the ball will be
                prediction = Ball(self.info.ball)
                self.ball_predictions = [vec3(prediction.pos)]

                for i in range(150):
                    prediction.step(0.016666)
                    prediction.step(0.016666)
                    self.ball_predictions.append(vec3(prediction.pos))

                    # if the ball is in the air
                    if prediction.pos[2] > 100:

                        self.action.target = prediction.pos
                        self.action.t_arrival = prediction.t

                        # check if we can reach it by an aerial
                        if self.action.is_viable():
                            break

            nsteps = 30
            delta_t = self.action.t_arrival - self.info.my_car.time
            prediction = Car(self.info.my_car)
            self.car_predictions = [vec3(prediction.pos)]
            for i in range(nsteps):
                prediction.step(Input(), delta_t / nsteps)
                self.car_predictions.append(vec3(prediction.pos))

            r = 200
            self.renderer.begin_rendering()
            purple = self.renderer.create_color(255, 230, 30, 230)
            white  = self.renderer.create_color(255, 230, 230, 230)

            x = vec3(r,0,0)
            y = vec3(0,r,0)
            z = vec3(0,0,r)
            target = self.action.target
            future = self.action.target - self.action.A

            self.renderer.draw_polyline_3d(self.ball_predictions, purple)
            self.renderer.draw_line_3d(target - x, target + x, purple)
            self.renderer.draw_line_3d(target - y, target + y, purple)
            self.renderer.draw_line_3d(target - z, target + z, purple)

            self.renderer.draw_polyline_3d(self.car_predictions, white)
            self.renderer.draw_line_3d(future - x, future + x, white)
            self.renderer.draw_line_3d(future - y, future + y, white)
            self.renderer.draw_line_3d(future - z, future + z, white)
            self.renderer.end_rendering()

            self.action.step(1.0 / 60.0)
            self.controls = self.action.controls

            if self.action.finished or self.timer > 10.0:
                self.timer = 0.0
                self.action = None
                self.increment_timer = False
                self.predictions = []

        if self.increment_timer:
            self.timer += 1.0 / 60.0

        self.info.my_car.last_input.roll  = self.controls.roll
        self.info.my_car.last_input.pitch = self.controls.pitch
        self.info.my_car.last_input.yaw   = self.controls.yaw
        self.info.my_car.last_input.boost = self.controls.boost

        return self.controls