https://github.com/visheshbons/self-driving-car
A self-driving-car AI training program with an interface
https://github.com/visheshbons/self-driving-car
ai autopilot canvas-game genetic-algorithm html-css-javascript no-libraries self-driving-car
Last synced: 6 months ago
JSON representation
A self-driving-car AI training program with an interface
- Host: GitHub
- URL: https://github.com/visheshbons/self-driving-car
- Owner: Visheshbons
- Created: 2025-04-22T08:31:37.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-06-16T20:08:43.000Z (about 1 year ago)
- Last Synced: 2025-06-16T21:23:05.268Z (about 1 year ago)
- Topics: ai, autopilot, canvas-game, genetic-algorithm, html-css-javascript, no-libraries, self-driving-car
- Language: JavaScript
- Homepage: https://v-autopilot-ai-trainer.onrender.com/
- Size: 1.21 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Self-Driving Car
You can see this at work [here](https://v-autopilot-ai-trainer.onrender.com/).
This is a self-driving car program, which runs using a _genetic algorithm_.
Our AI has 16 neurons: 6 input neurons, 6 hidden layer neurons, and 4 output neurons.
Our _"world"_ is a 4-lane highway, with traffic moving in the same direction as our AI.
## How to use
When you first load the site, you will see 750 randomly generated _"brains"_ controlling a car each.
By random chance, a few should survive the longest. This will narrow down to one quite fast.
When you are focused on the _"best"_ car, simply press the `save` button, then reload the page.
The new 750 AI cars will be 15% mutated from the previously selected _"best car"_.
Keep doing this until you get an AI that can do reasonably well.
## Game modes
There are four game modes so far: **Challenge**, **LIDAR**, **25 Lanes**, and **City**.
### Challenge mode
In challenge mode, you are tasked with driving the car, but you can only see what the AI gets as inputs.
IE: Sensors and Car Position.
Based on this data, you need to drive the car using the arrow keys on your keyboard.
When you 'die', you can see how you died, and can reload the page to try again.
### LIDAR mode
This is just an easier version of Challenge mode, as you get 75 sensors in 360 degrees of vision.
I made this purely for fun and to see what would happen.
This mode demonstrates how LIDAR cannot see through objects, hence they cast long shadows.
You still drive using the arrow keys on your keyboard for this one as well.
Again, death causes you to be able to see where you crashed.
### 25 Lanes
#### Base Version (Stable)
In the 25 Lanes mode, you drive with an overpowered car with ridiculously high steering sensitivity.
Unlike the other game modes, this version lets you see the road in actual vision.
It also has the greatest death screen of all time.
Here, you can also break using your spacebar, which is 3 times more powerful than your acceleration.
Press N for nitrous, and R for the Rocket booster.
It also shows you your Y value as a score, and also shows you the highest speed you travelled at.
It is great! (`Car.maxSpeed = infinity`)
#### Touchscreen (Unstable)
This is a feeble attempt to make the game accecable by mobile users. \
Can only ba accessed via `"/Game/index.html"`. \
Linked: [here](https://v-autopilot-ai-trainer.onrender.com/Game/index.html).
### City
**IMPORTANT**: This does not work on the main page, go to [the Github Pages version](https://visheshbons.github.io/self-driving-car/Test/index.html) for a functional version. \
This is a newly added game mode, which is also an AI trainer. \
To use as a gamemode, simply press the `I wanna drive!` button, and you will spawn in a green car! \
This also happens to be the only gamemode with drifting in it. \
Be careful though, as your car goes _fast_, and also drifts a _lot_.
## Some good starter `bestBrain`s
One is:
```
'{"levels":[{"inputs":[1,0,1,1,1,1],"outputs":[0,0,1,1,1,1],"biases":[-0.01182040785823895,0.35406253191755443,-0.05206691814153308,0.20706919974535298,-0.10797246745394426,-0.23915153622827912],"weights":[[0.19312911183954673,-0.09200335328741513,0.41928911838014143,0.15297713944334845,-0.04963911292127097,0.12303722951415212],[0.3178589608680969,0.09724358964010252,0.03966817114944489,-0.015354983530439542,-0.014024368521189802,0.20644620364912813],[-0.06321847932962285,-0.10468754111231586,-0.06270737103616492,0.09457287954791482,0.20359037014142134,-0.07448118111569169],[-0.06472104156669874,0.23197740767251976,0.057441868930755965,0.15651838211236999,-0.024679343794898834,-0.04954557468760923],[-0.17152075936864145,0.06016540124731053,-0.17836976458073597,-0.26353788716794463,-0.00535062805458851,-0.03793241134860208],[-0.18091575649800412,0.16530744602794284,0.07591930049720866,0.20541665678103702,0.3861037689937129,-0.05784733953840896]]},{"inputs":[0,0,1,1,1,1],"outputs":[0,0,1,0],"biases":[0.08100829849580543,-0.11582416749187557,0.08617079080799692,0.12353568590423061],"weights":[[0.21891338356855222,-0.04158431449605559,0.3198489768019803,0.06679566228150612],[-0.29106956239817205,-0.06287517874909779,-0.07416431961277913,0.2769391796878701],[0.09183320386748935,-0.25377431673830075,0.17482845683703083,0.09930874948178121],[-0.1024929932356744,-0.15928341595908885,0.09406043178031394,-0.3177475675790124],[0.052974337185940856,0.181291337827442,-0.0043183264061466,-0.17002953494170442],[-0.03523973878923449,-0.2695064766892798,0.17600868823366508,-0.04530570929298176]]}]}'
```
Here is one that works quite well:
```
'{"levels":[{"inputs":[1,1,1,1,1,0],"outputs":[1,0,0,1,0,0],"biases":[-0.8015295505748071,0.16402454003219774,-0.13557887057989346,-0.46627823531690527,-0.5573039339618608,0.6252767642102464],"weights":[[-0.08788868362163726,-0.19141351481720972,0.5972440483635926,0.719610998551176,-0.45747194385540235,-0.16057115879411837],[0.6031438486027343,-0.6999427673871438,-0.41492634539463924,0.5934173613477278,0.09388247178564521,0.6951598775048287],[0.6637302038220694,0.599348906459284,0.6162795995541905,-0.012979784593679811,-0.8897734600368571,-0.05900793002421835],[-0.6751111693325845,0.16751111741080488,-0.7697944482792696,0.4154761960085519,0.37711619801602636,-0.8560602523605734],[-0.7061738731969122,-0.09537334896249502,-0.35118078561531996,0.8921224731760574,0.24371666604507172,0.36146244974296815],[0.6472049233378152,-0.3728486169973035,-0.7511488578987026,-0.18310691039561877,0.8242115053107268,-0.23902482164489433]]},{"inputs":[1,0,0,1,0,0],"outputs":[1,0,1,1],"biases":[-0.7301406055230281,0.5329896647664943,-0.5872254774964993,-0.04157364414213194],"weights":[[0.1819636224173754,-0.13252896797126057,0.9117387724364578,0.42661882928319667],[-0.05913536157406675,-0.555951418884002,-0.8624768676880631,-0.27030989965922503],[-0.7008230336559248,0.00927840833900433,0.11446700112752704,-0.7681573366742185],[0.31624485167103084,0.22974554159259494,0.46961987453564447,0.40655967071142984],[0.4537824475234096,0.4725517233392736,0.8796929947775654,0.7217406787677544],[-0.39773051002817406,0.3875558221829135,0.028458320869851242,0.16603664818334254]]}]}'
```
Another one to expirement with:
```
'{"levels":[{"inputs":[1,0,1,0,1,0],"outputs":[1,1,0,1,1,0],"biases":[-0.45282876159639684,-0.042791408211962575,0.055327476131322995,0.12498208435945445,-0.39545100503808517,0.8267287184720095],"weights":[[0.3041220307250879,-0.6320537960809164,-0.5091812551561063,-0.19890193312270613,0.7324318654826258,-0.6438697105492003],[0.49025576174098007,0.14048534303514124,-0.526069855621555,-0.07576172978173257,0.8269503083141263,0.25913824153405085],[0.4552833168447018,0.47631798690784716,-0.4210334979122529,0.009145944079994917,-0.2696480529665865,-0.6430232333316308],[-0.6233059578136743,0.5572804250475772,-0.647504325604862,0.013534491263447787,0.40393629669631687,-0.26190241324422076],[0.15911691907436842,0.1207283471545299,-0.5872497464655304,0.35398816840489644,0.5142211936920276,-0.40867560679904547],[-0.1405338726423135,-0.37184946857898404,0.5434749136389467,0.021039691171930698,0.10018814640429449,-0.6027110621840615]]},{"inputs":[1,1,0,1,1,0],"outputs":[1,1,1,0],"biases":[-0.9082120585680051,0.18088174122924894,0.7130861959889666,0.037573171310997994],"weights":[[0.019223056936197858,-0.18520101932935956,-0.0013252447774048104,-0.12909180209679494],[-0.12255228418274261,0.5468023796040993,0.15917217306896708,0.21854204836747648],[-0.0015911252193135939,-0.18265231939687143,-0.5162536275855905,0.7544164247290447],[0.32352386883257517,0.1949813308610758,0.47198455296927555,0.29388575374135084],[0.5096939606636164,0.06117427308212814,0.5528634073555992,-0.46310920352366647],[-0.03509644657073123,-0.17526244854517548,-0.48262360233893503,0.1364965502352481]]}]}'
```
Here is a cruise control type:
```
'{"levels":[{"inputs":[0,0,1,1,1,0],"outputs":[0,0,1,0,1,0],"biases":[0.3313179378163656,0.5583293036873695,-0.30855405771498146,0.8438122350518391,-0.20258411119912118,0.053490682915185404],"weights":[[-0.665108850395504,-0.4811169934194633,0.5967249429537239,0.4722064838790454,0.05896786211089167,-0.5343354327691278],[-0.43866816804942194,0.06367784549760239,0.21456624410975053,0.3283729717062446,0.0811356249190107,-0.08558398514760045],[0.30810279241458355,-0.3483569787345495,0.18804353661505974,0.501091953598298,0.37149126245892833,-0.49644969496388114],[-0.30811857721402913,-0.4317546469331067,0.34390116826647577,0.045926742627089644,0.027530665338414473,-0.4532771250537914],[0.3253331055477336,-0.4981301952916265,-0.2099380394682128,-0.07944315919195305,-0.07634467673032735,0.010447986242411],[0.21680261692446656,-0.37644379058451705,-0.2750885644927722,0.32240296800524837,0.07298739936445045,0.45845592241956595]]},{"inputs":[0,0,1,0,1,0],"outputs":[0,0,0,1],"biases":[0.3954114622468069,-0.3268746706637806,0.45947174366644483,-0.24456816031830442],"weights":[[0.6858002654391941,-0.1680157354297042,0.2350532616567922,-0.283338592127384],[0.5993849710110526,0.40309921096857915,-0.16111069727864977,-0.22289699668552954],[0.009630243786152931,-0.18413516654788187,-0.608600742202715,-0.23354388347777844],[0.4821903806853286,-0.1732503997205443,-0.1874178712205598,-0.20648568835331432],[-0.0850065928278867,-0.21990617734279536,-0.24874437089139873,0.20046233267019659],[-0.3079885450920235,-0.33985075057538383,-0.10766588462622827,-0.31408101088022733]]}]}'
```
This is one for the City version.
```
localStorage.bestBrainCity = /** The City AI */
```
```
'{"levels":[{"inputs":[0.5925077576357471,0.36627060045688964,0,0,0.1646478707297654,0.4644813792256032,0.9833333333333334],"outputs":[1,1,0,0,1,1],"biases":[0.047008246461850485,-0.17062515301682396,0.30580506404749286,-0.13835110046412896,-0.15004829128856914,0.21243039463222657],"weights":[[0.2630132844984354,-0.09051157382329404,0.25273200613304414,-0.1107036110715695,0.08443501393972894,-0.04269563735314497],[-0.06115869882148296,0.5158887698503425,-0.27618092577688064,-0.5412096989699655,-0.06855090968048397,0.1373937807134269],[0.2612094313991028,0.23058378963936838,0.27831571732278193,-0.29300681154455804,-0.06718671313430741,0.35205897790253776],[0.04739559894779297,-0.1780106185962334,0.16263591463554644,-0.14360428316442797,0.19362101194625342,-0.25403140571308347],[-0.2787425283059868,0.3714717510843394,-0.19077342883953569,-0.49731286206484476,0.1927328109553258,0.3314483195840118],[-0.19618482654432526,0.18328791713059586,-0.0448484467628912,-0.10824379330971592,0.2441657588807668,-0.11650256370161181],[0.18169827138011702,-0.04233431091177447,-0.09858266119883996,0.05438981750363256,0.37894085804638733,0.20117055356874483]]},{"inputs":[1,1,0,0,1,1],"outputs":[1,1,0,1,1,1],"biases":[0.06732801817760556,-0.19145497549113824,0.11163023649481667,-0.30707771246613474,-0.18356683837802193,-0.15786651122080694],"weights":[[0.2679301944906522,0.3122868563957271,-0.1916329469911441,0.22156796403969164,-0.1615460784813031,0.06298390182577908],[0.28109246034408963,-0.008771281899741475,-0.45812480647391773,0.08201607686153022,-0.07383955197525711,-0.40564209300052245],[0.011474726896080291,-0.21583978562042586,0.22487483054156862,-0.07957026593885692,0.14702173550322223,0.10094834740557206],[0.5254176955138852,0.3015193591108538,0.4118619403733757,0.06011899212245061,-0.02608662845666787,0.2676807827199126],[0.09079017282715751,-0.2625691980232281,0.0538043683226863,0.2557641125721548,-0.07571567642438287,0.4612685253375055],[-0.20857138326838257,-0.03911417458887082,-0.3140091709739814,0.009981784137602513,0.2052501864506196,0.08610393248055595]]},{"inputs":[1,1,0,1,1,1],"outputs":[1,1,1,0],"biases":[0.20737565100899347,0.04908272881576051,-0.41551454611573474,0.48372924832927516],"weights":[[0.439506917130454,0.16735307878322664,0.14419424654845214,-0.08470909886090491],[0.09164040029787149,-0.2375613400237725,0.29055948164820755,-0.062299734387318534],[0.10140463365592159,0.3279627021540135,0.1216694708661637,0.32553620399657174],[-0.22306923039367166,0.003282275523599165,0.22403482870387317,0.024242474712184617],[-0.04396662197160046,0.07903808136182168,-0.261042097552848,-0.13915421014196847],[0.24903477078461705,0.09826659753948423,0.051150072518968914,0.3834624606984478]]}]}'
```
To use these, just run
```
localStorage.bestBrain = /** the brain JSON in question */
```
Then reload.
## Credits
- **Project Developer:** [Vishesh Kudva](https://github.com/Visheshbons)
- **Original Concept & Tutorials:** [Dr. Radu Mariescu-Istodor](https://github.com/gniziemazity/Self-driving-car)
- **AI & Code Assistance:** [ChatGPT by OpenAI](https://openai.com/chatgpt) and [Github Copilot](https://github.com/features/copilot)
- **Source Code:** [GitHub Repository](https://github.com/Visheshbons/self-driving-car)
- **Live Demo:** [v-autopilot-ai-trainer.onrender.com](https://v-autopilot-ai-trainer.onrender.com)
## Features coming up
The next stage is planned to be a full city-style workd, with traffic lights, stop signs, and lane regulations.
So far: City and lanes built, traffic lights, stop signs and lane detection coming up.
---
Version 3.0.0-alpha-1 | © 2025 Vishesh Kudva. | All rights reserved.