WatchCarsLearn
WatchCarsLearn copied to clipboard
Self driving cars using NEAT
WatchCarsLearn

Watch cars learn right in your browser! https://manassarpatwar.github.io/WatchCarsLearn/
The Car

- Each car has 5 distance sensors which serve as inputs to its brain (neural network)
- Each sensor has a max length and the input passed to the network is a normalized value of the sensor input (length/maxLength)
- The brain of the car outputs 2 values, both between 0 and 1
- The first value controls the throttle and brake of the car. If the value is greater than 0.66, the car accelerates else if it is less than 0.33, it brakes.
- The second value controls the steering of the car. If the value is greater than 0.66, the car steers right, else if it is less than 0.33, it steers left.
- The physics of the car is inspired by spacejack's implementation of Marco Monster's Car Physics for games paper
The Track

Procedural Track Generation
- I followed the steps outlined in a Procedural Race Track Generation algorithm implemented as a tool in Unity by Ian Hudson
- I used voronoi.js for creating the voronoi diagram
Beziers, Beziers, Beziers!
- I used bezier.js for working with beziers
- The track is made up of a lot of bezier curves
- There exists a hidden path of bezier curves that runs through the middle of the track. I use this path to calculate score of each car, and check whether the car is on the track or it has crashed
- The input sensor length is measured on every physics step. It is measured by calculating the intersection point between the sensor line and a nearest bezier curve
Editing and randomizing
- The track is completely editable and randomizable on the fly
- The simulation is paused while the user is editing otherwise the window will freeze up
- To Edit, simply click on the pencil icon and drag any of the control points
Neural Network

Activation
- The network is a feed forward neural network and stops any recurrent connections from being mutated
- The network is activated using a list of nodes sorted topologically(Kahn's algorithm)
Nodes
- Brightness of each node is the output of that node when activated
Connections
- Connections which are green have a positive weight
- Connections which are blue have a negative weight
- Connections which are red are disabled
Neuro Evolution of Augmenting Topologies (NEAT)
- I created my own NEAT implementation in JS
- Alenaksu's implementation of NEAT in typescript helped me a lot in debugging my own
- Kenneth O. Stanley's original NEAT paper
Icons
All icons were created in p5.js web editor by me
Pencil

p5.js editor sketch for pencil
Randomize

p5.js editor sketch for randomize
Steering wheel

p5.js editor sketch for steering wheel
License
MIT
Copyright (c) 2020-present Manas Sarpatwar