Skip to main content

Car game for reinforcement learning

Project description


Car game for Reinforcement Learning

Key FeaturesGetting StartedAuthorsLicenseAcknowledgments

Key features

forthebadge made-with-python

  • Easy to get started: API close to OpenAI gym

  • Versatility: Because of high abstraction level, it can be used in many scenarios.

  • Create your own track: And this is really easy, you can even do it in paint!

  • Intended bring RL closer to real life application: There are a lot of options to close the domain gap.

  • Examples available: SAC and GTA5

Getting Started

Maybe you want to play the game first manually to get a feeling for the game itself (1.2).

This is a simple car game is relying heavily on image warping (no 3D game), which you can use to test your reinforcement learning algorithms. The game can be played like any other game with a keyboard, but its main intention is to give openai gym-like python functions (consistency with openai gym not guaranteed). The game is giving feedback every frame. Aim is (especially for reinforcement learning) to maximize this score. The game is designed to make the race track creation as easy as possible. Therefore it is accept .png images as racing tracks. You can generate tracks (even multiple tracks) to suit your individual needs, or just rely on the prebuild tracks.

1. Installation

pip install car-rl

or for the newest verion:

pip install git+git://github.com/MatthiasSchinzel/CaRL

2. Play the game manually

Just run the commands in python

import carl
g = carl.carl()
g.play_game_manually()

Accelerate with W, brake with S, turn left with A and right with D. If you want to change the resolution you can do this with (to 320x176)

g.target_size = (320, 176)

3. Let your (reinforcement learning) algorithm play the game

If you ever used an openai gym game you might already be familiar. In case you are not, here the basics. Import the CarGame class first and initialize

import carl
g = carl.carl()

Acceleration goes from -1 to 1, as well as steering. You can also sample the action space with g.action_space.sample, which really is just a random number generator

done = False
direction = 1
acceleration = 1
while done == False:
     action_space, score, done, info = g.step(acceleration, direction)

g.reset()

Once you leave the race track, the game will end (done == True). Since the example above is going hard right with full acceleration, the game will end rather quick.

4. Create your own track

Creating a new racetrack is easy. Open an image manipulation software (GIMP or Inkscape for example). The higher resolution of the workspace, the bigger the map. Background should be plain white. If you can specify, select 8-bit depth. Now draw some line with constant thickness in black color (0, 0, 0) (in (R, G, B) notation). To specify the starting point just set a green point at the starting position (0, 255, 0) and specify the finish point with the color red (255, 0, 0). Make sure to use green (0, 255, 0) and not for example (10, 255, 10). That's it. Save the map as .png, add the path to the list of tracks in the .py file and maybe you should play your track manually first just to verify your track is working as intended.

Check out the supplied PNGs as as reference for getting started.

5. Scoring system

What is increasing the score:

  • Driving over not yet driven parts of the track
  • Smooth cornering
  • The less steering changes the better

What is decreasing the score:

  • Driving over already driven areas of the track (For example if you go straight, and then reverse. Just imagine the car is painting the street below the car in red. If you go again over that area, you won't get points for that again. )
  • Shaky driving
  • Stopping

Just in case it is still unclear: In this game maximizing the score means better driving performance. In case you need to minimize the score just flip the sign.

6. Why no 3D game / High abstraction?

The idea is, that maybe this abstraction of a driveable lane is enough. There exist a lot of methods out there to identify lane markings from images or a driveable area. In short: Real world --> driveable area (binary mask) --> driving directions.

The thing with 3D games in my opinion is, that you will likely have a domain gap between real images and 3D generated images. This method gets rid of all the fancy 3D modeling of houses etc. For Real world --> driveable area you can have a look at BDD100K for example. As a proof of concept please refer to the GTA5 example.

7. What is still missing?

I think a more realistic physical model of the car (so you can do drifting etc.) would be the next step.

After that maybe adding some other cars might be good, so the race track is changing dynamically.

Also a documentation of all possible settings inside the game might be useful.

Authors

License

MIT License, see LICENSE file.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

car-rl-0.0.2.tar.gz (422.7 kB view details)

Uploaded Source

Built Distribution

car_rl-0.0.2-py3-none-any.whl (423.4 kB view details)

Uploaded Python 3

File details

Details for the file car-rl-0.0.2.tar.gz.

File metadata

  • Download URL: car-rl-0.0.2.tar.gz
  • Upload date:
  • Size: 422.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.9

File hashes

Hashes for car-rl-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a84013351d0c0439d404109ae9faa23aa212f6a25c1a850697857bcbd0717e8a
MD5 acb9bafafb975597e8814b80094cd0a0
BLAKE2b-256 baecb99bbce203cbba4d3da6eb73fb29e507d8159e0259d1b6b2cd6472f5494d

See more details on using hashes here.

File details

Details for the file car_rl-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: car_rl-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 423.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.9

File hashes

Hashes for car_rl-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c5dd4f4d76f990b0df44d2e6a8cdd0e3116fc73a549e60f4f268678613ab95fe
MD5 a17a44fe531fcd3128786f440858c590
BLAKE2b-256 f36c1c7031d512e4ef5c3236841704d3ea564ac1c491637974e8da41cce1447f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page