Neural network learns how to drive a car on a track using Evolutionary Algorithms and Reinforcement Learning Simple 2D simulation with pyglet & numpy.
This fork was utilized to write the article Learn to Race: solving with Evolutionary Algorithm and Reinforcement Learning
pip install -r requirements.txt
Should work with Python 3.0
and higher.
For example:
py -3.10 .\__main__.py
Or use a virtual environment.
evolutionary_settings.json
{
"width": 1280,
"height": 720,
"friction": 0.1,
"render_timestep": 0.025, // time between frames in seconds - 0.025s = 40 FPS
"timeout_seconds": 30, // maximum time for each gen
"population": 40, // number of cars
"mutation_rate": 0.6 // mutation rate after gen
}
reinforcement_settings.json
{
"width": 1280,
"height": 720,
"friction": 0.1,
"render_timestep": 0.025,
"timeout_seconds": 30,
"population": 1,
"mutation_rate": 0.0,
"gamma": 0.99,
"batch_size": 256
}
default_nn_config.json - Default car config for new saves.
{
"name": "test",
"acceleration": 1,
"friction": 0.95,
"max_speed": 30,
"rotation_speed": 4,
"shape": [6, 4, 3, 2], // neural network shape - do not change first and last layer
"max_score": 0,
"gen_count": 0
}
ddpg_config.json
{
"name": "DDPG",
"acceleration": 1,
"friction": 0.95,
"max_speed": 30,
"rotation_speed": 4,
"shape": [6, 32, 32, 2],
"max_score": 0,
"gen_count": 0
}
td3_config.json
{
"name": "TD3",
"acceleration": 1,
"friction": 0.95,
"max_speed": 30,
"rotation_speed": 4,
"shape": [6, 32, 32, 2],
"max_score": 0,
"gen_count": 0
}
![]() |
![]() |
---|
Write "e"/"evolutionary" when running the app to choose the evolutionary algorithm to train the MLPs
Write "r"/"reinforcement" when running the app to choose the reinforcement algorithm to train the MLPs
Write down "d"/"ddpg" or "t"/"td3" to choose which algorithm you want to utilize to train.
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.