Random Policy Car Racing Game#

Shows how to use a random policy for an agent and visualize the environment.

Set up the environment and prt_rl wrapper#

Import the Gymnasium robot game and the environment wrapper

[ ]:
from prt_rl.common.policy import RandomPolicy
from prt_rl.env.wrappers import GymnasiumWrapper
from prt_rl.common.runners import Runner
from prt_rl.common.recorders import GifRecorder

Create the environment#

[2]:
env = GymnasiumWrapper(
    gym_name="CarRacing-v3",
    render_mode="rgb_array",
    continuous=True,
)

Initialize Random policy#

Create a random policy that takes in the environment parameters.

[3]:
policy = RandomPolicy(env_params=env.get_parameters())

Create a Runner#

Run the environment for a single episode until it is done.

[4]:
runner = Runner(
    env=env,
    policy=policy,
    recorder=GifRecorder(
        filename="car_race.gif",
        fps=50
    ),
)
[5]:
runner.run()
Car Race