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.
npm install
npm run devOpen http://localhost:3000.
Production build:
npm run build
npm start- 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). - Pause / Resume — Freezes or continues the simulation (evolution mode only).
- Reset Track — New random circuit; in evolution mode the current generation index is kept and direction is recomputed for that generation.
- Stop Evolution — Returns to the small demo fleet with scripted steering (not the GA).
- 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).
- 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.
| 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.
- Next.js (App Router) · React · TypeScript · HTML Canvas
Private project; add a license file if you open-source it.