コード例 #1
0
ファイル: kickoff_step.py プロジェクト: TheBlocks/BeepBoop
    def prepare_kickoff(self, packet: GameTickPacket) -> None:
        bot_pos = Vector3(packet.game_cars[self.agent.index].physics.location)

        # Centre kickoff
        if abs(bot_pos.x) < 250:
            pad = self.get_closest_small_pad(bot_pos).location
            first_target: vec3 = vec3(
                pad.x, pad.y,
                pad.z) - vec3(0, 250, 0) * (1 if self.agent.team else -1)
            second_target: vec3 = vec3(0, 850,
                                       0) * (1 if self.agent.team else -1)

            self.kickoff_steps = [
                Drive(self.agent.game_info.my_car, first_target, 2400),
                AirDodge(self.agent.game_info.my_car, 0.075, vec3(0, 0, 0)),
                Drive(self.agent.game_info.my_car, second_target, 2400),
                AirDodge(self.agent.game_info.my_car, 0.075, vec3(0, 0, 0))
            ]
        # Off-centre kickoff
        elif abs(bot_pos.x) < 1000:
            target: vec3 = normalize(self.agent.game_info.my_car.pos) * 500

            self.kickoff_steps = [
                Drive(
                    self.agent.game_info.my_car,
                    vec3(self.agent.game_info.my_car.pos[0],
                         3477 * (1 if self.agent.team else -1), 0), 2400),
                AirDodge(self.agent.game_info.my_car, 0.075, vec3(0, 0, 0)),
                Drive(self.agent.game_info.my_car, target, 2400),
                AirDodge(self.agent.game_info.my_car, 0.075, vec3(0, 0, 0))
            ]
        # Diagonal kickoff
        else:
            pad = self.get_closest_small_pad(bot_pos).location
            car_to_pad: vec3 = vec3(pad.x, pad.y,
                                    pad.z) - self.agent.game_info.my_car.pos
            first_target: vec3 = self.agent.game_info.my_car.pos + 1.425 * car_to_pad
            second_target: vec3 = vec3(0, 150,
                                       0) * (1 if self.agent.team else -1)
            third_target: vec3 = normalize(
                self.agent.game_info.my_car.pos) * 850

            self.kickoff_steps = [
                Drive(self.agent.game_info.my_car, first_target, 2300),
                AirDodge(self.agent.game_info.my_car, 0.035, second_target),
                Drive(self.agent.game_info.my_car, third_target, 2400),
                AirDodge(self.agent.game_info.my_car, 0.1, vec3(0, 0, 0))
            ]
コード例 #2
0
 def predict(self):
     self.bounces = []
     ball_prediction = self.get_ball_prediction_struct()
     for i in range(ball_prediction.num_slices):
         location = vec3(ball_prediction.slices[i].physics.location.x,
                         ball_prediction.slices[i].physics.location.y,
                         ball_prediction.slices[i].physics.location.z)
         prev_ang_vel = ball_prediction.slices[i -
                                               1].physics.angular_velocity
         prev_normalized_ang_vel = normalize(
             vec3(prev_ang_vel.x, prev_ang_vel.y, prev_ang_vel.z))
         current_ang_vel = ball_prediction.slices[
             i].physics.angular_velocity
         current_normalized_ang_vel = normalize(
             vec3(current_ang_vel.x, current_ang_vel.y, current_ang_vel.z))
         if prev_normalized_ang_vel != current_normalized_ang_vel and location[
                 2] < 125:
             self.bounces.append((location, i * 1 / 60))
コード例 #3
0
ファイル: shooting.py プロジェクト: meckern/RLBotPack
def shooting_target(agent):
    ball = agent.info.ball
    car = agent.info.my_car
    car_to_ball = ball.pos - car.pos
    backline_intersect = line_backline_intersect(
        agent.info.their_goal.center[1], vec2(car.pos), vec2(car_to_ball))
    if -500 < backline_intersect < 500:
        goal_to_ball = normalize(car.pos - ball.pos)
        error = cap(distance_2d(ball.pos, car.pos) / 1000, 0, 1)
    else:
        # Right of the ball
        if -500 > backline_intersect:
            target = agent.info.their_goal.corners[3] + vec3(400, 0, 0)
        # Left of the ball
        elif 500 < backline_intersect:
            target = agent.info.their_goal.corners[2] - vec3(400, 0, 0)
        goal_to_ball = normalize(ball.pos - target)
        goal_to_car = normalize(car.pos - target)
        difference = goal_to_ball - goal_to_car
        error = cap(abs(difference[0]) + abs(difference[1]), 1, 10)

    goal_to_ball_2d = vec2(goal_to_ball[0], goal_to_ball[1])
    test_vector_2d = dot(rotation(0.5 * math.pi), goal_to_ball_2d)
    test_vector = vec3(test_vector_2d[0], test_vector_2d[1], 0)

    distance = cap((40 + distance_2d(ball.pos, car.pos) * (error**2)) / 1.8, 0,
                   4000)
    location = ball.pos + vec3(
        (goal_to_ball[0] * distance), goal_to_ball[1] * distance, 0)

    # this adjusts the target based on the ball velocity perpendicular to the direction we're trying to hit it
    multiplier = cap(distance_2d(car.pos, location) / 1500, 0, 2)
    distance_modifier = cap(
        dot(test_vector, ball.vel) * multiplier, -1000, 1000)
    modified_vector = vec3(test_vector[0] * distance_modifier,
                           test_vector[1] * distance_modifier, 0)
    location += modified_vector

    # another target adjustment that applies if the ball is close to the wall
    extra = 3850 - abs(location[0])
    if extra < 0:
        location[0] = cap(location[0], -3850, 3850)
        location[1] = location[1] + (-sign(agent.team) * cap(extra, -800, 800))
    return location
コード例 #4
0
    def pathplan(self):
        car = self.info.my_car
        k = 50  #number of guides on path
        p0_ = car.pos
        p1_ = car.pos + car.vel * 2  #compensation for velocity

        self.guides = []

        if len(self.targets) == 1:
            p2_ = self.targets[0]

            for i in range(k):
                self.guides.append(bezier(p0_, p1_, p2_, p2_, (i / k)))

        else:
            p2_ = self.targets[0] + normalize(
                self.targets[0] - self.targets[1]
            ) * 100  #number not final, adjusts curve so that car ends up facing next target
            p3_ = self.targets[0]
            for i in range(k):
                self.guides.append(bezier(p0_, p1_, p2_, p3_, (i / k)))
コード例 #5
0
 def __init__(self, anchor, normal):
     self.anchor = anchor
     self.normal = normalize(normal)
     self.offset_anchor = anchor + DropshotBall.RADIUS * self.normal
コード例 #6
0
def kick_off(agent):
    if agent.kickoffStart == "Diagonal_Scrub":
        if agent.step == "Drive":
            agent.drive.step(agent.FPS)
            agent.controls = agent.drive.controls
            if agent.drive.finished:
                agent.step = "Dodge1"
                # target = agent.info.ball.pos
                target = normalize(z0(agent.info.my_car.forward())) * 1000
                agent.dodge = AirDodge(agent.info.my_car, 0.075, target)
        elif agent.step == "Dodge1":
            agent.dodge.step(agent.FPS)
            agent.controls = agent.dodge.controls
            if agent.dodge.finished:
                agent.step = "Steer"
                target = agent.info.ball.pos
                agent.drive = Drive(agent.info.my_car, target, 1399)
        elif agent.step == "Steer":
            agent.drive.step(agent.FPS)
            agent.controls = agent.drive.controls
            if agent.info.my_car.on_ground:
                agent.drive.target_speed = 2400
            if distance_2d(agent.info.ball.pos, agent.info.my_car.pos) < 750:
                agent.step = "Dodge2"
                agent.dodge = AirDodge(agent.info.my_car, 0.075,
                                       agent.info.ball.pos)
        elif agent.step == "Dodge2":
            agent.dodge.step(agent.FPS)
            agent.controls = agent.dodge.controls
            if agent.dodge.finished and agent.info.my_car.on_ground:
                agent.step = "Catching"
    elif agent.kickoffStart == "Diagonal":
        if agent.step == "Drive":
            agent.drive.step(agent.FPS)
            agent.controls = agent.drive.controls
            if distance_2d(agent.info.ball.pos, agent.info.my_car.pos) < 850:
                agent.step = "Dodge"
                agent.dodge = AirDodge(agent.info.my_car, 0.075,
                                       agent.info.ball.pos)
        elif agent.step == "Dodge":
            agent.dodge.step(agent.FPS)
            agent.controls = agent.dodge.controls
            if agent.dodge.finished and agent.info.my_car.on_ground:
                agent.step = "Catching"
    elif agent.kickoffStart == "Center":
        if agent.step == "Drive":
            agent.drive.step(agent.FPS)
            agent.controls = agent.drive.controls
            if agent.drive.finished:
                agent.step = "Dodge1"
                agent.dodge = AirDodge(agent.info.my_car, 0.075,
                                       agent.info.ball.pos)
        elif agent.step == "Dodge1":
            agent.dodge.step(agent.FPS)
            agent.controls = agent.dodge.controls
            agent.controls.boost = 0
            if agent.dodge.finished and agent.info.my_car.on_ground:
                agent.step = "Steer"
                target = agent.info.ball.pos + sign(agent.team) * vec3(
                    0, 850, 0)
                agent.drive = Drive(agent.info.my_car, target, 2400)
        elif agent.step == "Steer":
            agent.drive.step(agent.FPS)
            agent.controls = agent.drive.controls
            if agent.drive.finished:
                agent.step = "Dodge2"
                agent.dodge = AirDodge(agent.info.my_car, 0.075,
                                       agent.info.ball.pos)
        elif agent.step == "Dodge2":
            agent.dodge.step(agent.FPS)
            agent.controls = agent.dodge.controls
            if agent.dodge.finished and agent.info.my_car.on_ground:
                agent.step = "Catching"
    elif agent.kickoffStart == "offCenter":
        if agent.step == "Drive":
            agent.drive.step(agent.FPS)
            agent.controls = agent.drive.controls
            if agent.info.my_car.boost < 15 or agent.drive.finished:
                agent.step = "Dodge1"
                agent.dodge = AirDodge(agent.info.my_car, 0.075,
                                       agent.info.ball.pos)
        elif agent.step == "Dodge1":
            agent.dodge.step(agent.FPS)
            agent.controls = agent.dodge.controls
            agent.controls.boost = 0
            if agent.dodge.finished and agent.info.my_car.on_ground:
                agent.step = "Steer"
                target = agent.info.ball.pos
                agent.drive = Drive(agent.info.my_car, target, 2400)
        elif agent.step == "Steer":
            agent.drive.step(agent.FPS)
            agent.controls = agent.drive.controls
            if distance_2d(agent.info.ball.pos, agent.info.my_car.pos) < 850:
                agent.step = "Dodge2"
                agent.dodge = AirDodge(agent.info.my_car, 0.075,
                                       agent.info.ball.pos)
        elif agent.step == "Dodge2":
            agent.dodge.step(agent.FPS)
            agent.controls = agent.dodge.controls
            if agent.dodge.finished and agent.info.my_car.on_ground:
                agent.step = "Catching"
コード例 #7
0
ファイル: vector_math.py プロジェクト: meckern/RLBotPack
def ground_direction(source, target) -> vec3:
    return normalize(ground(target) - ground(source))
コード例 #8
0
ファイル: vector_math.py プロジェクト: meckern/RLBotPack
def direction(source, target) -> vec3:
    return normalize(loc(target) - loc(source))
コード例 #9
0
ファイル: util.py プロジェクト: Supersilver10/RLBotPack
def get_bounce(agent):
    for i in range(len(agent.bounces)):
        goal_to_ball = normalize(z0(agent.bounces[i][0] - agent.info.their_goal.center))
        target = agent.bounces[i][0] + 40 * goal_to_ball
        if is_reachable(agent, target, agent.bounces[i][1]):
            return [target, agent.bounces[i][1]]