Ejemplo n.º 1
0
 def initialize_agent(self):
     """Initializing all parameters which require the field info"""
     self.my_goal = Goal(self.team, self.get_field_info())
     self.their_goal = Goal(1 - self.team, self.get_field_info())
     init_boostpads(self)
     """Setting all the mechanics to not none"""
     self.drive = Drive(self.info.my_car)
     self.catching = Drive(self.info.my_car)
     self.dodge = Dodge(self.info.my_car)
     self.dribble = Dribbling(self.info.my_car, self.info.ball,
                              self.their_goal)
Ejemplo n.º 2
0
def set_steer(agent):
    if agent.info.my_car.on_ground:
        agent.step = Step.Steer
        target = agent.info.ball.position
        agent.drive = Drive(agent.info.my_car)
        agent.drive.target = target
        agent.drive.speed = 2400
Ejemplo n.º 3
0
def init_kickoff(agent):
    """"Method that initializes the kickoff"""
    if abs(agent.info.my_car.location[0]) < 250:
        pad = get_closest_small_pad(agent, vec3(0,
                                                sign(agent.team) * 4608, 18))
        target = vec3(pad.location[0], pad.location[1],
                      pad.location[2]) + sign(agent.team) * vec3(20, 0, 0)
        agent.kickoffStart = "Center"
    elif abs(agent.info.my_car.location[0]) < 1000:
        target = vec3(0.0,
                      sign(agent.team) * 2816.0,
                      70.0) + sign(agent.team) * vec3(0, 300, 0)
        agent.kickoffStart = "offCenter"
    else:
        target = agent.info.my_car.location + 300 * agent.info.my_car.forward()
        agent.kickoffStart = "Diagonal"
    agent.drive = Drive(agent.info.my_car)
    agent.drive.target = target
    agent.drive.speed = 2400
    agent.step = Step.Drive
    agent.drive.step(agent.info.time_delta)
    agent.controls = agent.drive.controls
Ejemplo n.º 4
0
def kick_off(agent):
    ball = agent.info.ball
    car = agent.info.my_car
    t = distance_2d(ball.position, car.position) / 2200
    batmobile_resting = 18.65
    robbies_constant = (ball.position - vec3(0, 0, 92.75 - batmobile_resting) -
                        car.position - car.velocity * t) * 2 * t**-2
    robbies_boost_constant = dot(normalize(xy(
        car.forward())), normalize(
            xy(robbies_constant))) > (0.3 if car.on_ground else 0.1)
    """"Module that performs the kickoffs"""
    if agent.kickoffStart == "Diagonal":
        if agent.step is Step.Drive:
            agent.drive.step(agent.info.time_delta)
            agent.controls = agent.drive.controls
            if agent.drive.finished:
                ball_location = ball.position + vec3(
                    0, -sign(agent.team) * 500, 0)
                target = car.position + 250 * normalize(ball_location -
                                                        car.position)
                agent.drive = Drive(car)
                agent.drive.target = target
                agent.drive.speed = 2400
                agent.step = Step.Drive_1
        if agent.step is Step.Drive_1:
            agent.drive.step(agent.info.time_delta)
            agent.controls = agent.drive.controls
            if agent.drive.finished:
                target = vec3(
                    dot(
                        rotation(
                            math.radians(-sign(agent.info.team) *
                                         sign(car.position[0]) * 60)),
                        vec2(car.forward())) * 10000)
                preorientation = dot(
                    axis_to_rotation(
                        vec3(
                            0, 0,
                            math.radians(-sign(agent.info.team) *
                                         -sign(car.position[0]) * 30))),
                    car.orientation)
                setup_first_dodge(agent, 0.05, 0.3, target, preorientation)
        elif agent.step is Step.Dodge_1:
            agent.timer += agent.info.time_delta
            if agent.timer > 0.8:
                lerp_var = lerp(
                    normalize(robbies_constant),
                    normalize(ball.position -
                              vec3(0, 0, 92.75 - batmobile_resting) -
                              car.position), 0.8)
                agent.turn.target = look_at(lerp_var, vec3(0, 0, 1))
                agent.turn.step(agent.info.time_delta)
                agent.controls = agent.turn.controls
                if car.on_ground:
                    agent.time = 0
                    agent.set_state = True
                    agent.step = Step.Shooting
            else:
                agent.dodge.step(agent.info.time_delta)
                agent.controls = agent.dodge.controls
            agent.controls.boost = robbies_boost_constant
    elif agent.kickoffStart == "Center":
        if agent.step is Step.Drive:
            agent.drive.step(agent.info.time_delta)
            agent.controls = agent.drive.controls
            if agent.drive.finished:
                target = vec3(
                    dot(rotation(math.radians(-65)), vec2(car.forward())) *
                    10000)
                preorientation = dot(
                    axis_to_rotation(vec3(0, 0, math.radians(45))),
                    car.orientation)
                setup_first_dodge(agent, 0.05, 0.4, target, preorientation)
        elif agent.step is Step.Dodge_1:
            agent.timer += agent.info.time_delta
            if agent.timer > 0.8:
                agent.turn.target = look_at(xy(ball.position - car.position),
                                            vec3(0, 0, 1))
                agent.turn.step(agent.info.time_delta)
                agent.controls = agent.turn.controls
                set_steer(agent)
            else:
                agent.dodge.step(agent.info.time_delta)
                agent.controls = agent.dodge.controls
            agent.controls.boost = robbies_boost_constant
        elif agent.step is Step.Steer:
            agent.drive.step(agent.info.time_delta)
            agent.controls = agent.drive.controls
            if distance_2d(car.position, ball.position) < 800:
                agent.step = Step.Dodge_2
                agent.dodge = Dodge(car)
                agent.dodge.duration = 0.075
                agent.dodge.target = ball.position
        elif agent.step is Step.Dodge_2:
            agent.dodge.step(agent.info.time_delta)
            agent.controls = agent.dodge.controls
            if agent.dodge.finished and car.on_ground:
                agent.time = 0
                agent.set_state = True
                agent.step = Step.Shooting
    elif agent.kickoffStart == "offCenter":
        if agent.step is Step.Drive:
            agent.drive.step(agent.info.time_delta)
            agent.controls = agent.drive.controls
            if distance_2d(car.position, agent.drive.target) < 650:
                target = vec3(
                    dot(
                        rotation(
                            math.radians(-sign(agent.info.team) *
                                         -sign(car.position[0]) * 100)),
                        vec2(car.forward())) * 10000)
                preorientation = dot(
                    axis_to_rotation(
                        vec3(
                            0, 0,
                            math.radians(-sign(agent.info.team) *
                                         sign(car.position[0]) * 30))),
                    car.orientation)
                print("PYTHON: ", agent.info.my_car.position)
                print(
                    "PYTHON: ",
                    math.radians(-sign(agent.info.team) *
                                 -sign(car.position[0]) * 100))
                setup_first_dodge(agent, 0.05, 0.4, target, preorientation)
        elif agent.step is Step.Dodge_1:
            agent.timer += agent.info.time_delta
            if agent.timer > 0.8:
                lerp_var = lerp(
                    normalize(robbies_constant),
                    normalize(ball.position -
                              vec3(0, 0, 92.75 - batmobile_resting) -
                              car.position), 0.25)
                agent.turn.target = look_at(lerp_var, vec3(0, 0, 1))
                agent.turn.step(agent.info.time_delta)
                agent.controls = agent.turn.controls
                set_steer(agent)
            else:
                agent.dodge.step(agent.info.time_delta)
                agent.controls = agent.dodge.controls
            agent.controls.boost = robbies_boost_constant
        elif agent.step is Step.Steer:
            agent.drive.step(agent.info.time_delta)
            agent.controls = agent.drive.controls
            if distance_2d(ball.position, car.position) < 800:
                agent.step = Step.Dodge_2
                agent.dodge = Dodge(car)
                agent.dodge.duration = 0.075
                agent.dodge.target = ball.position
        elif agent.step is Step.Dodge_2:
            agent.dodge.step(agent.info.time_delta)
            agent.controls = agent.dodge.controls
            if agent.dodge.finished and car.on_ground:
                agent.time = 0
                agent.set_state = True
                agent.step = Step.Shooting