-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustomObsBuilder.py
27 lines (21 loc) · 944 Bytes
/
customObsBuilder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from rlgym.utils.obs_builders import ObsBuilder
from rlgym.utils import common_values
from rlgym.utils.gamestates import PlayerData, GameState
import numpy as np
class BaseObsBuilder(ObsBuilder):
def reset(self, initial_state: GameState):
pass
def build_obs(self, player: PlayerData, state: GameState, previous_action: np.ndarray):
obs = []
#If this observation is being built for a player on the orange team, we need to invert all the physics data we use.
inverted = player.team_num == common_values.ORANGE_TEAM
if inverted:
obs += state.inverted_ball.serialize()
else:
obs += state.ball.serialize()
for player in state.players:
if inverted:
obs += player.inverted_car_data.serialize()
else:
obs += player.car_data.serialize()
return np.asarray(obs, dtype=np.float32)