Exemple #1
0
def time_till_reach_ball(ball, car):
    car_to_ball = (ball.location - car.location).flat()
    dist = car_to_ball.length() - datalibs.BALL_RADIUS - 25
    vel_c_f = car.velocity.proj_onto_size(car_to_ball)
    vel_b_f = ball.velocity.proj_onto_size(car_to_ball)
    vel_c_amp = rlmath.lerp(vel_c_f, car.velocity.length(), 0.6)
    vel_f = vel_c_amp - vel_b_f
    dist_long_01 = min(max(0, dist / 10_000.0), 1)**2
    time_normal = dist / max(250, vel_f)
    time_long = dist / max(car.velocity.length(), 1400)
    time = rlmath.lerp(time_normal, time_long, dist_long_01)
    return time
Exemple #2
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
Exemple #3
0
    def execute(self, bot):
        bot.renderer.draw_string_3d(bot.info.my_car.pos, 1, 1, "DefWait",
                                    bot.renderer.yellow())

        ball_pos = bot.info.ball.pos
        target = vec3(ball_pos[0], -ball_pos[1], 0)
        target = rlmath.lerp(target, vec3(0, 0, 0),
                             bot.analyzer.team_mate_is_defensive_01)

        for car in bot.info.teammates:
            to_me_n = normalize(bot.info.my_car.pos - car.pos)
            target += to_me_n * 400

        bot.renderer.draw_line_3d(bot.info.my_car.pos, target,
                                  bot.renderer.yellow())

        distance = norm(target - bot.info.my_car.pos)
        if distance > 2000:
            ctt_n = normalize(target - bot.info.my_car.pos)
            vtt = dot(bot.info.my_car.vel, ctt_n) / dot(ctt_n, ctt_n)
            if vtt > 750:
                bot.plan = DodgeTowardsPlan(target)

        speed = min(1410, distance / 3)
        self.drive.car = bot.info.my_car
        self.drive.target_pos = target
        self.drive.target_speed = speed
        self.drive.step(0.016666)
        bot.controls = self.drive.controls
Exemple #4
0
    def utility(self, bot):
        car_to_ball = bot.info.my_car.pos - bot.info.ball.pos

        bouncing_b = bot.info.ball.pos[2] > 130 or abs(
            bot.info.ball.vel[2]) > 300
        if not bouncing_b:
            return 0

        dist_01 = rlmath.clamp01(1 - norm(car_to_ball) / 3000)

        head_dir = rlmath.lerp(vec3(0, 0, 1), bot.info.my_car.forward(), 0.1)
        ang = angle_between(head_dir, car_to_ball)
        ang_01 = rlmath.clamp01(1 - ang / (math.pi / 2))
        on_my_side_b = (sgn(bot.info.ball.pos[1]) == bot.tsgn)

        ball_landing_pos = bot.info.ball.next_landing().data
        tile = tiles.point_to_tile(bot.info, ball_landing_pos)
        protect_tile_b = (tile != None and tile.team == bot.team
                          and (tile.state == tiles.Tile.OPEN
                               or bot.info.ball.team != bot.team))

        return rlmath.clamp01(0.3 * on_my_side_b + 0.3 * ang_01 +
                              0.3 * dist_01 + 0.8 * protect_tile_b -
                              0.3 * bot.analyzer.team_mate_has_ball_01 +
                              self.is_dribbling * self.extra_utility_bias)
Exemple #5
0
    def execute(self, bot):
        bot.renderer.draw_string_3d(bot.info.my_car.pos, 1, 1, "Dribble",
                                    bot.renderer.pink())

        ball = bot.info.ball
        car = bot.info.my_car
        aim = bot.analyzer.best_target_tile.location

        car_to_ball = ball.pos - car.pos
        ctb_n = normalize(car_to_ball)
        dist = norm(car_to_ball) - 100
        vel_delta = ball.vel - car.vel
        vel_d = norm(vel_delta)
        time = max(0, dist / (1.5 * vel_d)) if vel_d != 0 else 0
        bvel = norm(ball.vel)

        ball_to_aim_n = normalize(aim - ball.pos)

        nbp = DropshotBall(ball).step_ds(time).pos
        target = nbp - 120 * ball_to_aim_n
        dist_t = norm(target - car.pos)
        speed = min(rlmath.lerp(1.3 * bvel, 2300, dist_t / 1000), 2300)

        bot.renderer.draw_line_3d(ball.pos, nbp, bot.renderer.green())
        bot.renderer.draw_rect_3d(nbp, 10, 10, True, bot.renderer.green())
        bot.renderer.draw_rect_3d(target, 10, 10, True, bot.renderer.pink())

        self.drive.car = bot.info.my_car
        self.drive.target_pos = target
        self.drive.target_speed = speed
        self.drive.step(0.016666)
        bot.controls = self.drive.controls