Evolutionary Robotics

Soft Robot Evolution

A soft-body physics engine built from scratch in C++, used to evolve squishy voxel robots that learn to move — no motors, no fixed design, just simulated muscle and natural selection.

Evolved soft voxel robot in a chimpanzee outline
Type
Physics Engine / Evolution
Built
From scratch
Language
C++

The idea

Most robots are rigid: fixed links, motors at the joints, a design a human drew up front. This project asks the opposite question — what if you don't design the robot at all? Instead you build a world with physics, fill it with soft, deformable material, and let an evolutionary algorithm discover both the body and the movement on its own.

To do that I needed two things from scratch: a soft-body physics engine to simulate squishy material realistically, and an evolutionary loop to mutate and select robots over many generations. The result is creatures that aren't built so much as grown — and they figure out how to crawl, shuffle, and hop entirely on their own.

Part 1 — The physics engine

A soft body can't be modeled as a single rigid shape — it bends, squashes, and wobbles. The standard way to capture that is a mass-spring system: represent the body as a lattice of point masses connected by springs. Each voxel of the robot is a little cube of masses held together by springs; springs resist stretching and compression, so the whole structure behaves like jelly with a stiffness you can dial in.

Every simulation step does three things: apply forces (gravity, plus the "muscle" forces that make voxels contract and expand), integrate the masses forward in time, and resolve constraints and collisions so the body holds together and doesn't sink through the floor. Get the integration or the stiffness wrong and the whole thing explodes — keeping it stable across a wide range of material stiffness is most of the engineering.

Here's the core mechanic, live. This is a single soft block — drop it and use the sliders to feel how stiffness and bounciness change its behavior. Low stiffness splats like a beanbag; high stiffness bounces like a rigid box:

A mass-spring soft body running position-based dynamics — the same model the full engine uses for every voxel, here in 2D so you can play with it.

Part 2 — Morphology: how a robot is described

If evolution is going to invent bodies, it needs a way to write down a body. I represent each robot as a grid of voxels, where every voxel has a material type:

  • Empty — no material there (this is what carves out the shape).
  • Structural / bone — stiff, passive support that holds the body up.
  • Muscle — active material that rhythmically contracts and expands, driving motion.

So a robot's entire "genome" is just which material sits in each voxel. That single idea is powerful: by changing voxel types, evolution can reshape the body, move the muscles around, and change how it pushes against the ground — all in the same representation.

Part 3 — Why a chimpanzee outline

Letting evolution choose every voxel from a blank canvas means most of its effort goes into discovering a basic blob shape before it can even start improving movement — a huge, slow search. So instead I fixed the silhouette to a chimpanzee outline and let evolution optimize only what happens inside that shape: where the bone goes, where the muscle goes, and how it actuates.

The chimp outline was a deliberate choice:

  • It constrains the search to the interesting part. Shape is fixed, so every generation is spent improving the material layout and gait — not rediscovering "have limbs," which makes evolution converge far faster.
  • The limbs give evolution something to work with. Arms and legs are natural places for muscle to develop into pushing, swinging, and crawling motions — a recognizable body plan with real locomotion potential.
  • It's legible. When the creature moves, you can actually read what it's doing — an arm pulling, a leg pushing — which makes debugging and showing the results far easier than watching an anonymous blob.

The result is the creature at the top of this page: a chimp-shaped block of voxels whose internal muscle and bone were evolved, not designed.

Part 4 — The evolutionary loop

With a physics engine to test bodies and a voxel genome to describe them, evolution is a loop:

  • Population: start with a batch of robots whose internal voxels are randomly assigned bone/muscle/empty.
  • Evaluate: drop each one into the physics simulation, let its muscles cycle, and score it by how far it travels — the fitness function.
  • Select: keep the best performers, discard the worst.
  • Mutate & repeat: create the next generation by copying winners and randomly flipping some voxels, then run the whole thing again.

Over many generations, average fitness climbs. Designs that happen to push against the ground more effectively survive and spread, and the population drifts toward genuinely good gaits — without anyone ever telling it how to walk.

What emerged

  • Robots that started as random noise evolved into coordinated movers — muscle settling into the limbs and firing in rhythms that produce real locomotion.
  • Strategies appeared that I never designed: shuffling, dragging, and hopping gaits that exploit the soft body's bounce and the chimp morphology's limbs.
  • The project is end-to-end proof I can build the hard parts myself — a stable physics simulator and an optimization loop on top of it — not just call a library.

Challenges & what they taught me

  • Numerical stability. Stiff springs + large time steps make a mass-spring system blow up instantly. Choosing the integration scheme and constraint solving so the body stays stable across soft and stiff materials was the core engine challenge.
  • Compute cost. Evolution means simulating hundreds of robots across many generations — every wasted millisecond per step multiplies enormously, which is why the engine is in C++ and the simulation kept lean.
  • Designing the fitness function. Reward only raw distance and evolution finds cheats (falling over and counting it as travel). Shaping the objective so it rewards actual locomotion is its own craft.

Skills & Tools

C++ Custom Physics Engine Mass-Spring Soft Body Numerical Integration Evolutionary Algorithms Optimization Collision Handling