A gymnasium 2D racing environment
Project description
RacingEnv
A simple 2D racing environment using gymnasium
Installation
Requirements python 3.8+
, C++17 compiler
Package requirements:
scikit-build-core >=0.4.3
nanobind >=1.3.2
gymnasium>=0.26.0
pygame>=2.1.0
numpy>=1.19
Registered Environments
The package registers three environments
racingenv/Racing-v1
racingenv/Racing-features-v1
racingenv/Racing-pixels-v1
Environment Arguments
The environment can be customized using the following kwargs:
- render_mode
- human
- rgb_array
- debug
- agent
- obs_type (this should only be specified when using
racingenv/Racing-v1
)- pixels
- features
- resolution, a tuple of the form
(width, height)
(Note that, when training the agent on pixels, the resolution will affect the observation returned by the environment) - pyhsics_settings, a dictionary containing the physics settings (a more details below)
- map, path to a map file (again more details below)
Feature Space
The environment defines the following features (Shape 37x1):
- Agent x-position
[0.0, 1.0]
- Agent y-position
[0.0, 1.0]
- Agent normalized x-direction
[-1.0, 1.0]
- Agent normalized y-direction
[-1.0, 1.0]
- Distance to the inner bound of the next checkpoint or MAX_RAY_LENGTH
[0.0, 1.0]
- Normalized x-direction to the inner bound of the next checkpoint
[-1.0, 1.0]
- Normalized y-direction to the inner bound of the next checkpoint
[-1.0, 1.0]
- Distance to the outer bound of the next checkpoint or MAX_RAY_LENGTH
[0.0, 1.0]
- Normalized x-direction to the outer bound of the next checkpoint
[-1.0, 1.0]
- Normalized y-direction to the outer bound of the next checkpoint
[-1.0, 1.0]
- Agent forward velocity
[-1.0, 1.0]
- Agent angular velocity
[-1.0, 1.0]
- Agent lateral velocity
[-1.0, 1.0]
- For each of the 8 rays
- Distance to the intersection or MAX_RAY_LENGTH if no intersection occurred
[0.0, 1.0]
- x-position of the intersection or the furthest point that could be an intersection
[0.0, 1.0]
- y-position of the intersection or the furthest point that could be an intersection
[0.0, 1.0]
- Distance to the intersection or MAX_RAY_LENGTH if no intersection occurred
Pixel Space
Image scaled down to 64x64 as np.array
. (Shape 12288x1)
Rewards
On the track there are several checkpoints that can only be taken in order, passing a checkpoint gives the agent a one time reward of 1.0. Hitting a wall gives the agent a reward of -1.0. Should the agent ever come to a complete standstill the environment will truncate.
Physics settings
There are several physics settings that can be customized by passing a dictionary when creating the environment, which needs to specify all the keys below:
- max_velocity, the maximum possible forwards or backwards velocity of the agent
- acceleration, the acceleration applied by the forward and backward action
- drag, drag applied every frame the agent is not accelerating
- max_lateral_velocity, maximum velocity in the lateral direction (aka. drift)
- lateral_acceleration, acceleration in lateral direction
- lateral_drag, drag applied in the lateral direction
- angular_velocity, strength of the agents steering
- drift_threshold, minimum lateral velocity needed to drift
Custom maps
In progress
Rendering Modes
The environment supports 4 rendering modes
Human
Implements human rendering, additionally a resolution tuple (width, height) maybe be passed when creating the environment via resolution=(width, height)
.
RGB_Array
Renders the same frame as in human mode, but the resolution is fixed to be 800 by 600, additionally render()
returns the frame as np.array
instead of blitting it onto the screen.
Agent
Renders the game in the same way the agent "sees" it.
Debug
Human rendering with additional debug information.
Credits
The AE86 sprite has been created by u/cropmania.
This environment was created as part of the Fachprojekt Applied Deep Reinforcement Learning at TU-Dortmund.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file racingenv-2.0.4.tar.gz
.
File metadata
- Download URL: racingenv-2.0.4.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 517c41996a4ee3706eb79869f99bb4b790e426269e8973f576fc98a3d678d9db |
|
MD5 | a555d37398f113bf63fbe5c9bca615c7 |
|
BLAKE2b-256 | 0c08355368dace8507166f02ab8eeb7fa28e91702c2e0d6945f9ce597d9663fa |
File details
Details for the file racingenv-2.0.4-cp312-abi3-manylinux_2_35_x86_64.whl
.
File metadata
- Download URL: racingenv-2.0.4-cp312-abi3-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 86.6 kB
- Tags: CPython 3.12+, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f35001c07c6bd8f76f28d42867d298b94e01801532c7d61dc614c3f57e2c1ba3 |
|
MD5 | b3eea38bcd75c4a14a0000436e433181 |
|
BLAKE2b-256 | 6f4e73fc4f87ffd43042035a114103504a0a8119d974145505bade2d68a9b641 |