Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Rolv-Arild committed Jan 10, 2025
2 parents f644517 + 9bc24d8 commit 7b94de6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 16 additions & 1 deletion rlgym_tools/rocket_league/misc/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import numpy as np

INVERT_ACTION = np.array([1, -1, 1, -1, -1, 1, 1, 1], dtype=np.float32) # Invert steer, yaw and roll


@dataclass(slots=True)
class Action:
"""
Dataclass representing an action in the environment.
RLGym uses numpy arrays, but this class can be used in place of them for better readability,
type hints and pretty printing.
"""
throttle: float = 0.0
steer: float = 0.0
Expand All @@ -23,10 +27,21 @@ def from_numpy(cls, action: np.ndarray):

def to_numpy(self):
return np.array(
[self.throttle, self.steer, self.pitch, self.yaw, self.roll, self.jump, self.boost, self.handbrake],
(self.throttle, self.steer, self.pitch, self.yaw, self.roll, self.jump, self.boost, self.handbrake),
dtype=np.float32
)

def mirror(self):
return ~self

def __invert__(self):
# ~ operator mirrors the action
return Action.from_numpy(self.to_numpy() * INVERT_ACTION)

def __array__(self):
# Make this class compatible with numpy functions
return self.to_numpy()

def __repr__(self):
def format_bool(b):
return int(b)
Expand Down
14 changes: 7 additions & 7 deletions rlgym_tools/rocket_league/replays/replay_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

@dataclass(slots=True)
class ReplayFrame:
state: GameState
actions: Dict[int, np.ndarray]
update_age: Dict[int, float]
scoreboard: ScoreboardInfo
episode_seconds_remaining: float
next_scoring_team: Optional[int]
winning_team: Optional[int]
state: GameState # Current state of the game
actions: Dict[int, np.ndarray] # Actions for each player
update_age: Dict[int, float] # Time since the replay updated values for each car (>0 means state is interpolated)
scoreboard: ScoreboardInfo # Current scoreboard
episode_seconds_remaining: float # Time remaining until someone scores or ball hits ground at 0s
next_scoring_team: Optional[int] # Team that scores the next goal, None if ball hits ground at 0s
winning_team: Optional[int] # Team that wins the game, None if game ended without a winner

0 comments on commit 7b94de6

Please sign in to comment.