Example #1
0
    def flip_generator(self):
        car, target_dir = yield
        car: Player

        while not car.on_ground:
            car, target_dir = yield SimpleControllerState(throttle=1)

        front = car.rotation_matrix[:, 0]
        world_left = cross(np.array([0, 0, 1]), front)
        target_dir = normalize(target_dir)
        pitch = -dot(front, target_dir)
        roll = dot(world_left, target_dir)

        for _ in range(5):
            car, target_dir = yield SimpleControllerState(jump=True,
                                                          handbrake=True)
        for _ in range(1):
            car, target_dir = yield SimpleControllerState(jump=False,
                                                          handbrake=True)

        car, target_dir = yield SimpleControllerState(jump=True,
                                                      pitch=pitch,
                                                      roll=roll,
                                                      handbrake=True)

        while not car.on_ground:
            car, target_dir = yield SimpleControllerState(throttle=1,
                                                          handbrake=True)

        self.finished = True

        yield SimpleControllerState()
        return
Example #2
0
 def get_flip_inputs(self, car, game_packet):
     # mechanic expects target's future coordinate so results are deviant in testing when just given ball's expired position
     front = normalize(flatten(car.rotation_matrix[:, 0]))
     world_left = cross(np.array([0, 0, 1]), front)
     target_dir = normalize(flatten(self.target - car.location))
     pitch = -dot(front, target_dir)
     roll = dot(world_left, target_dir)
     return SimpleControllerState(jump=True, roll=roll, pitch=pitch)
Example #3
0
    def kickoff_generator(self):
        game_data = yield

        while True:
            if self.agent.game_data.kickoff_pause:
                self.kickoff_type = get_kickoff_position(
                    self.agent.game_data.my_car.location)

            relative_ball = game_data.ball.location - game_data.my_car.location

            if self.kickoff_type == 0:  # wide kickoff
                offset = np.array([100, 0, 0]) * sign(relative_ball[0])
            else:
                offset = np.array([50, 0, 0]) * sign(relative_ball[0])

            if game_data.my_car.boost > 15 or norm(relative_ball) < 2200:
                controls = self.mechanic.get_controls(
                    game_data.my_car, game_data.ball.location + offset)
                controls.throttle = 1
                controls.boost = True
                game_data = yield controls
            else:
                flip = Flip(self.agent, self.rendering_enabled)
                while not flip.finished:
                    controls = flip.get_controls(game_data.my_car,
                                                 relative_ball)
                    if dot(game_data.my_car.rotation_matrix[:, 0],
                           normalize(relative_ball)) > 0.5:
                        controls.boost = True
                    game_data = yield controls
Example #4
0
 def jumpshot_valid(self, game_data, target_loc, target_dt,
                    target_dir) -> bool:
     best_dt = (target_loc[2] - game_data.my_car.location[2]) / 300
     future_projection = game_data.my_car.location + game_data.my_car.velocity * target_dt
     difference = future_projection - target_loc
     difference[2] = 0
     return (norm(difference) < 150 and target_dt - best_dt < 0.1 and
             dot(target_loc - game_data.my_car.location, target_dir) > 0)
Example #5
0
    def get_controls(self, game_data: GameData) -> SimpleControllerState:
        dt = norm(game_data.own_goal.location - game_data.ball.location) / 3000
        ball_location = game_data.ball_prediction[int(60 * dt)]["physics"]["location"]
        ball_velocity = game_data.ball_prediction[int(60 * dt)]["physics"]["velocity"]
        target_loc = normalize(game_data.own_goal.location - ball_location) * self.distance + ball_location
        up = game_data.my_car.rotation_matrix[:, 2]
        target_loc = target_loc - dot(target_loc - game_data.my_car.location, up) * up
        target_dir = ball_velocity.astype(float)

        controls = self.mechanic.get_controls(game_data.my_car, game_data.boost_pads, target_loc, dt, target_dir)

        self.finished = self.mechanic.finished
        self.failed = self.mechanic.failed

        return controls
 def is_attacking_team(teammate):
     teammate_velocity = teammate["physics"]["velocity"].astype(float)
     return is_defending_team(teammate) and dot(teammate_velocity,
                                                target_dir) > 0
 def is_defending_team(teammate):
     teammate_location = teammate["physics"]["location"].astype(float)
     return dot(
         (game_data.ball.location - teammate_location), target_dir) > 0