Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: VirxEC/rlviser-py
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.6.5
Choose a base ref
...
head repository: VirxEC/rlviser-py
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.6
Choose a head ref
  • 1 commit
  • 8 files changed
  • 1 contributor

Commits on May 5, 2024

  1. Update to latest socket spec

    Add get/report for game speed/paused
    VirxEC committed May 5, 2024
    Copy the full SHA
    31fa0ba View commit details
Showing with 424 additions and 144 deletions.
  1. +54 −47 Cargo.lock
  2. +1 −1 Cargo.toml
  3. +2 −2 gym_renderer.py
  4. +31 −16 pygymtest.py
  5. +36 −0 rlviser_py.pyi
  6. +82 −33 src/bytes.rs
  7. +72 −1 src/lib.rs
  8. +146 −44 src/socket.rs
101 changes: 54 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rlviser-py"
version = "0.6.5"
version = "0.6.6"
edition = "2021"
description = "Python implementation that manages a UDP connection to RLViser"
license = "MIT"
4 changes: 2 additions & 2 deletions gym_renderer.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ def render(self, state: GameState, shared_info: Dict[str, Any]) -> Any:
ball.pos = rsim.Vec(*state.ball.position)
ball.vel = rsim.Vec(*state.ball.linear_velocity)
ball.ang_vel = rsim.Vec(*state.ball.angular_velocity)
ball.rot_mat = rsim.RotMat(*state.ball.rotation_mtx.transpose().flatten())
# ball.rot_mat = rsim.RotMat(*state.ball.rotation_mtx.transpose().flatten())

car_data = []
for idx, car in enumerate(state.cars.values()):
@@ -59,7 +59,7 @@ def _get_car_state(self, car: Car):
car_state.has_double_jumped = car.has_double_jumped
car_state.air_time_since_jump = car.air_time_since_jump
car_state.flip_time = car.flip_time
car_state.last_rel_dodge_torque = rsim.Vec(*car.flip_torque)
car_state.flip_rel_torque = rsim.Vec(*car.flip_torque)

car_state.is_auto_flipping = car.is_autoflipping
car_state.auto_flip_timer = car.autoflip_timer
47 changes: 31 additions & 16 deletions pygymtest.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
import time
import numpy as np
from itertools import chain

import numpy as np
import rlviser_py
from rlgym.api import RLGym
from rlgym.rocket_league.action_parsers import LookupTableAction, RepeatAction
from rlgym.rocket_league.done_conditions import GoalCondition, AnyCondition, TimeoutCondition, NoTouchTimeoutCondition
from rlgym.rocket_league.done_conditions import (
AnyCondition,
GoalCondition,
NoTouchTimeoutCondition,
TimeoutCondition,
)
from rlgym.rocket_league.obs_builders import DefaultObs
from rlgym.rocket_league.reward_functions import CombinedReward, GoalReward, TouchReward
from rlgym.rocket_league.sim import RocketSimEngine
from rlgym.rocket_league.state_mutators import MutatorSequence, FixedTeamSizeMutator, KickoffMutator
from rlgym.rocket_league.state_mutators import (
FixedTeamSizeMutator,
KickoffMutator,
MutatorSequence,
)

from gym_renderer import RLViserRenderer

if __name__ == "__main__":
game_speed = 1

env = RLGym(
state_mutator=MutatorSequence(
FixedTeamSizeMutator(blue_size=2, orange_size=2),
KickoffMutator()
FixedTeamSizeMutator(blue_size=2, orange_size=2), KickoffMutator()
),
obs_builder=DefaultObs(zero_padding=None),
action_parser=RepeatAction(LookupTableAction(), repeats=1),
reward_fn=CombinedReward(
(GoalReward(), 10.),
(TouchReward(), 0.1)
),
reward_fn=CombinedReward((GoalReward(), 10.0), (TouchReward(), 0.1)),
termination_cond=GoalCondition(),
truncation_cond=AnyCondition(
TimeoutCondition(timeout=300.),
NoTouchTimeoutCondition(timeout=30.)
TimeoutCondition(timeout=300.0), NoTouchTimeoutCondition(timeout=30.0)
),
transition_engine=RocketSimEngine(),
renderer=RLViserRenderer(120)
renderer=RLViserRenderer(120),
)

# simulate 2 episodes
for _ in range(2):
obs_dict = env.reset()
steps = 0
ep_reward = {agent_id: 0. for agent_id in env.agents}
ep_reward = {agent_id: 0.0 for agent_id in env.agents}
t0 = time.time()
while True:
actions = {}
@@ -46,9 +53,11 @@
actions[agent_id] = np.random.randint(action_space, size=(1,))

for _ in range(8):
obs_dict, reward_dict, terminated_dict, truncated_dict = env.step(actions)
obs_dict, reward_dict, terminated_dict, truncated_dict = env.step(
actions
)
env.render()
time.sleep(max(0, t0 + steps / 1200 - time.time()))
time.sleep(max(0, t0 + steps / (120 * game_speed) - time.time()))
steps += 1

for agent_id, reward in reward_dict.items():
@@ -57,5 +66,11 @@
if any(chain(terminated_dict.values(), truncated_dict.values())):
break

game_speed = rlviser_py.get_game_speed()

ep_time = time.time() - t0
print(f"Steps per second: {steps / ep_time:.0f} | Episode time: {ep_time:.2f} | Episode Reward: {max(ep_reward.values()):.2f}")
print(
f"Steps per second: {steps / ep_time:.0f} | Episode time: {ep_time:.2f} | Episode Reward: {max(ep_reward.values()):.2f}"
)

env.close()
Loading