Skip to content

Leo-Strijbos/DarwinGP

Repository files navigation

DarwinGP

DarwinGP is a client-side neuroevolution toy: hundreds of tiny feed-forward networks drive neon “Tron-style” cars on procedural closed circuits. A genetic algorithm selects parents, crosses them over, mutates weights, and keeps elites—no server, no ML frameworks, just Next.js and a canvas.

Quick start

npm install
npm run dev

Open http://localhost:3000.

Production build:

npm run build
npm start

How to use the app

  1. Start Evolution — Begins a new run: random track, population of 100 networks, generation 1. Cars spawn near the start/finish line; mandated drive direction (CW / CCW) is held for 3–5 generations, then flips for the next block (shown in the HUD as e.g. 3/4 gens this dir).
  2. Pause / Resume — Freezes or continues the simulation (evolution mode only).
  3. Reset Track — New random circuit; in evolution mode the current generation index is kept and direction is recomputed for that generation.
  4. Stop Evolution — Returns to the small demo fleet with scripted steering (not the GA).

What you’re watching

  • Top-left HUD — Generation, lap progress toward advancing, fitness stats, stall / hard-cap hints.
  • Top-right panel — Dynamic hard cap timer for the generation and how many cars have completed ≥1 lap.
  • Start/finish — Red line; arrow shows mandated lap direction for that generation.
  • Sensors — Shown for the current best car (cyan rays).

Expectations

  • Early generations are noisy: many cars spin, hug walls, or die off-track.
  • Roughly 10–15 generations is a reasonable ballpark before you often see smoother laps and clearer racing lines—highly dependent on track randomness and direction blocks.
  • Each generation uses a new track, so policies must generalise a bit; mandated direction alternates in blocks (not every gen) to reduce thrashing.

How it works (engineering sketch)

Piece Role
Genome Weights for a small MLP: distance rays + speed + direction bit → hidden ReLU → steer + throttle.
Fitness Mostly forward progress along the track centreline in the mandated direction, plus small on-track bonuses and a light penalty for hugging walls (via ray distances).
GA Sort by fitness; top 10 copy unchanged; others from weighted elite parents, crossover, mutation (stronger early in a run).
Laps Start/finish seam in arc-length space; guards reduce bogus laps from spawn / sensor glitches.

Code lives under lib/ (evolution/, track/, car/, controller/, etc.) and components/RaceCanvas.tsx ties the sim loop to the UI.

Stack

  • Next.js (App Router) · React · TypeScript · HTML Canvas

License

Private project; add a license file if you open-source it.

About

Genetic algorithms to learn to race around randomly-generated circuits in your browser.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors