A buggy that learns to climb endless hills. AI drives, survives and evolves
— powered by neuroevolution and Matter.js.
Overview
Hill Climber is an AI hill-climbing training game. A fleet of buggies tries to climb
over endless randomly generated terrain — a chaser wall pushes them
from behind, fuel barrels keep them alive, and water
zones
slow them down while draining fuel twice as fast.
The twist: nobody writes the driving logic. The AI learns it from scratch. Each
generation
of buggies is controlled by a tiny neural network; the ones that drive furthest survive
and breed. Generation after generation, the swarm gets better at climbing hills all by
itself.
The project started after I played
FlappyLearning
— an AI game where a neural network learns to play Flappy Bird live in your browser. I
found it so fascinating that I decided to build my own AI-driving game and see the magic
with my own eyes.
How the AI Learns to Drive
The core of the project is Neuroevolution — a hybrid of neural networks
and genetic algorithms, implemented from scratch in Neuroevolution.js:
Neural network. Each buggy has a small brain that reads its state —
current speed, wheel velocity, terrain angle — and outputs controls like throttle
and brake.
Fitness. A buggy's score is simply how far it survives. Getting
stuck on a hill face, flipping over, or running out of fuel all end the run.
Evolution. Top performers are selected, their genes crossover and
mutate, and the next generation starts where the last one failed.
Live training. You can watch the fitness curve climb, change
evolution parameters from the side panel, and restart training at any speed
(x1 / x2 / x3 / MAX).
This is exactly the question I wanted to answer: how does an AI actually learn to
drive by itself? Hill Climber turned that curiosity into something I could
watch, tweak and break in real time.
Game Modes
Player Mode — drive manually with A/D or arrow keys, just to feel
how hard the hills really are.
AI Training — let the neuroevolution swarm learn the terrain from
zero, generation by generation.
Four difficulty maps are included — gentle, hills, mountains, watery — so you
can
watch the same brain adapt to completely different physics. Training progress can be
saved to localStorage or exported / imported as JSON.
Engineering Notes
The first version was a single-file prototype. Following the project structure of
FlappyLearning-gh-pages,
I refactored it into a clean multi-file codebase:
Neuroevolution.js — network, genes, breeding and generation management
terrain.js / physics.js — endless terrain generation and
Matter.js world
game.js / state.js — AI input, round & evolution flow,
main loop
render.js — Canvas rendering with live training curve
persist.js — localStorage save / JSON export / reset
Reflection
Hill Climber started with a feeling I got from FlappyLearning: watching a neural network
learn to play a game in front of you, live, with no script. I wanted to see that happen
with something I built myself. So I made a buggy that climbs endless hills — and nobody
writes the driving logic. The AI learns it from scratch, generation by generation.
What the project quietly flipped: in every game I had built before, I
started with rules. I defined the physics, the inputs, the win conditions, and the
outcome was whatever fell out of that system. The rules came first; the result was a
consequence. Hill Climber works the other way around. I define the data — the buggy's
state, the terrain — and the result I want — how far it should get — and the AI is left
to discover the rules on its own. Nobody hands it a driving manual. It has to invent
one.
What that inversion taught me: training an AI is not writing a game with
a smarter opponent. It is a different relationship to the rules. The neuroevolution loop
— observe, act, fail, select, mutate, repeat — does not care what I think the buggy
should do. It only cares what survives. Watching stupid, spinning buggies slowly turn
into skilled hill climbers across a few dozen generations was strangely emotional,
because the improvement was not something I designed. It was something the system found.
What I carry forward: this project is where playing with AI became
curiosity about AI. I stopped asking "how do I make the buggy climb?" and started asking
"how does anything learn to climb at all?" That question — what actually happens inside
those numbers when a buggy figures out it should brake before a hill — is why I now want
to understand the inside of the black box, not just watch it work.