Example #1
0
def get_hit_frame_numbers(df: pd.DataFrame):
    ball_df = df[DF_BALL_PREFIX]

    hit_frame_numbers = get_hit_frame_numbers_by_ball_ang_vel(df)
    # Filter by hit_team_no
    hit_frame_numbers = ball_df.loc[hit_frame_numbers].index[~ball_df.loc[
        hit_frame_numbers, "hit_team_no"].isna()].tolist()
    logger.info(f"hit: {hit_frame_numbers}")

    delta_df = df.loc[:, (DF_GAME_PREFIX, 'delta')]
    RLUGame.set_mode("soccar")
    filtered_hit_frame_numbers = []
    for frame_number in hit_frame_numbers:
        previous_frame_number = frame_number - 1
        ball_previous_frame = ball_df.loc[previous_frame_number, :]
        initial_ang_vel = ball_previous_frame.loc[[
            'ang_vel_x', 'ang_vel_y', 'ang_vel_z'
        ]].values

        ball = Ball()
        # noinspection PyPropertyAccess
        ball.location = vec3(
            *ball_previous_frame.loc[['pos_x', 'pos_y', 'pos_z']])
        # noinspection PyPropertyAccess
        ball.velocity = vec3(
            *ball_previous_frame.loc[['vel_x', 'vel_y', 'vel_z']])
        # noinspection PyPropertyAccess
        ball.angular_velocity = vec3(*initial_ang_vel)

        frame_delta = delta_df[frame_number]
        delta_simulated = 0
        while delta_simulated < frame_delta:
            dt = 1 / 120
            time_to_simulate = min(dt, frame_delta - delta_simulated)
            ball.step(time_to_simulate)
            delta_simulated += time_to_simulate

        simulated_ball_ang_vel = np.array([
            ball.angular_velocity[0], ball.angular_velocity[1],
            ball.angular_velocity[2]
        ])
        actual_ball_ang_vel = ball_df.loc[
            frame_number, ['ang_vel_x', 'ang_vel_y', 'ang_vel_z']].values
        actual_ang_vel_change = ((actual_ball_ang_vel -
                                  initial_ang_vel)**2).sum()**0.5
        end_ang_vel_difference = ((simulated_ball_ang_vel -
                                   actual_ball_ang_vel)**2).sum()**0.5

        relative_ang_vel_difference = end_ang_vel_difference / actual_ang_vel_change
        if relative_ang_vel_difference > 0.8:
            filtered_hit_frame_numbers.append(frame_number)
    return filtered_hit_frame_numbers
Example #2
0
    def reset_gamestate(self):
        print('> reset_gamestate()')

        # Initialize inputs
        self.reset_for_ground_shots()
        t = self.target
        b = Ball(self.game.ball)
        c = Car(self.game.cars[self.index])
        b.location = to_vec3(self.initial_ball_location)
        b.velocity = to_vec3(self.initial_ball_velocity)
        c.location = to_vec3(self.initial_car_location)
        c.velocity = to_vec3(self.initial_car_velocity)

        # Point car at ball
        c.rotation = look_at(
            vec3(b.location[0] - c.location[0], b.location[1] - c.location[1],
                 0), vec3(0, 0, 1))
        rotator = rotation_to_euler(c.rotation)

        # Reset
        self.aerial = None
        self.dodge = None
        self.rotation_input = None
        self.timer = 0.0

        # Set gamestate
        car_state = CarState(boost_amount=100,
                             physics=Physics(
                                 location=self.initial_car_location,
                                 velocity=self.initial_car_velocity,
                                 rotation=rotator,
                                 angular_velocity=Vector3(0, 0, 0)))
        ball_state = BallState(
            Physics(location=self.initial_ball_location,
                    velocity=self.initial_ball_velocity,
                    rotation=Rotator(0, 0, 0),
                    angular_velocity=Vector3(0, 0, 0)))
        game_state = GameState(ball=ball_state, cars={self.index: car_state})
        self.set_game_state(game_state)
Example #3
0
def set_shots(hits_by_goal_number: Dict[int, Hit], game: Game,
              df: pd.DataFrame):
    ball_df = df[DF_BALL_PREFIX]
    player_id_to_team = {
        player.id.id: player.is_orange
        for player in game.players
    }

    for hits_list in hits_by_goal_number.values():
        for hit in hits_list:
            direction_factor = -1**player_id_to_team[
                hit.player_id.id]  # -1 if orange, 1 if blue
            ball_data = ball_df.loc[hit.frame_number]

            ball = Ball()
            # noinspection PyPropertyAccess
            ball_location = ball_data.loc[['pos_x', 'pos_y', 'pos_z']]
            ball.location = vec3(*ball_location)
            # noinspection PyPropertyAccess
            ball_velocity = ball_data.loc[['vel_x', 'vel_y', 'vel_z']]
            ball.velocity = vec3(*ball_velocity)
            # noinspection PyPropertyAccess
            ball_angular_velocity = ball_data.loc[[
                'ang_vel_x', 'ang_vel_y', 'ang_vel_z'
            ]]
            ball.angular_velocity = vec3(*ball_angular_velocity)

            delta_simulated = 0
            while delta_simulated < SHOT_SECONDS_SIMULATED:
                dt = 1 / 120
                ball.step(min(dt, SHOT_SECONDS_SIMULATED - delta_simulated))
                delta_simulated += dt

                ball_y = ball.location[1]
                if ball_y * direction_factor > FIELD_Y_LIM:
                    hit.shot = True
                    break
Example #4
0
 def set_ball_state(self, ball: Ball):
     ball.position = vec3(0, 0, 3000)
     ball.velocity = vec3(0, 0, 0)
     ball.angular_velocity = vec3(0, 0, 0)
Example #5
0
 def set_ball_state(self, ball: Ball):
     ball.position = vec3(-11390, -6950, 470)
     ball.velocity = vec3(0, 0, 0)
     ball.angular_velocity = vec3(0, 0, 0)
Example #6
0
from rlutilities.simulation import Game, Car, Ball, intersect

Game.set_mode("dropshot")

c = Car()

c.location = vec3(-164.13, 0, 88.79)
c.velocity = vec3(1835.87, 0, 372.271)
c.angular_velocity = vec3(0, 3.78721, 0)
c.rotation = mat3(0.9983, -5.23521e-6, 0.0582877, 5.5498e-6, 1.0, -5.23521e-6,
                  -0.0582877, 5.5498e-6, 0.9983)

b = Ball()

b.location = vec3(0, 0, 150)
b.velocity = vec3(0, 0, 0)
b.angular_velocity = vec3(0, 0, 0)

print("before:")
print(b.location)
print(b.velocity)
print(b.angular_velocity)
print("overlapping: ", intersect(c.hitbox(), b.hitbox()))

print()

b.step(0.008333, c)

print("after:")
print(b.location)
print(b.velocity)