Genetic Tanks

genetic tanks

The plan: make a simple environment with simple rules and populate it with entities that compete with each other. Hopefully better robots would evolve, and their genetics would dominate the pool until even better robots evolved.

Two versions to download (Windows) — they need a long time to run, but exhibit genuine learning and behavioural evolution: GeneticTanks.exe and GeneticTanks2.exe.

rules

Ten robots are put into an arena. Each may face up, down, left or right, move forward, or fire its gun. A hit damages the target. When two robots are left they mate and repopulate the arena, each parent contributing 50% of the genetic code. Fitness is defined only as survival.

the mind of a single robot

Each robot needs a 'mind' that can be passed to its children and evolve. The first approach was based on how humans perceive the world — a kind of spatial memory hologram. I gave each robot a 2D mind-map grid and placed objects into it, modelled on how I sense my own surroundings:

X Flatmate Me X Door X Flatmate
Demonstration mind map — where things sit around "me".
X Threat Robot
The robot's equivalent: a threat located in the grid.

For each square, the robot holds six probabilities — one per action — totalling 100%. To decide, it picks a random action and a random number 0–100; if the number is below that action's probability it acts, otherwise it rolls again. A well-trained killer vs a poorly-evolved one, both facing a threat directly above:

Face up50%
Face down0%
Face left0%
Face right0%
Move forward0%
Fire gun50%
A well-trained killer: faces up and fires.
Face up5%
Face down2%
Face left42%
Face right51%
Move forward5%
Fire gun20%
A poor one: spends its life vibrating between left and right, and gets destroyed.
what actually happened

The robots evolved for two weeks on a P166 at IBM Hursley (state of the art back then). The results surprised me.

Gen 0 — all random, shooting each other by accident.
Gen 500 — reasonable killers at point-blank range, useless at distance.
Gen 1000 — a second breed appeared: robots that fled at close range, dominating in bursts until the killers wiped them out.
Gen 2000 — highly evolved killers and prey both dominant; the screen looked exciting.
Gen 2500 — the prey were becoming dominant. Odd.
Gen 3000 — killers had vanished entirely. A peaceful utopia: few deaths, long generations.
Gen 4000 — stupid robots creeping back; running away no longer mattered.
Gen 4500 — stupid random robots completely dominant.
Gen 5000 — good close-range killers re-emerging. Evolution had gone full circle — the utopia de-evolved, its primitive sons wiping out the peaceful forefathers.

better robots

The precursors were primitive. The next generation rotated instead of facing four ways, and their brains became short programs controlling the left wheel, right wheel and gun in parallel — so a tank could turn, reverse and fire at once. Threats are read by quadrant around the tank's facing:

Robot with six quadrants around it
Six quadrants around the tank — each holds a little L/R/F program.
QuadrantL  R  F
1 (ahead)0  0  1
21  0  1
31 −1  0
4−1  1  0
5−1  1  0
6−1  0  1
A simple killer: fire if ahead, spin toward threats behind.
mapping the mind

Choosing a quadrant by screen X/Y is easy until the tank faces another way — then a threat "ahead" and a threat "to the right" both look like quadrant 1. So targets are selected by angle: a normal projects from the tank's facing, checked against screen vertical to get the offset.

Tank facing up
Facing up…
Tank facing right
…vs facing right: same screen position, different relative quadrant.
Angle diagram Angle diagram
θ = tan⁻¹(dx/dy), with a correction (+180°) when dy is negative.
results, and teaching them

Run for a week, the tanks developed gun-turret characteristics: moving back and forth randomly while firing constantly at the nearest threat. Then a happy accident — because of how the minds worked, you could teach them. Let a human drive a robot, and instead of reading the relevant memory, write the human's responses to it: the baby robots quickly picked up the human's style of play, even inheriting personality — a tendency to turn left, or the instinct to run when damaged. I tried it while at EA, and it worked. Converting the same system from a robot to, say, outlining and counting human faces wouldn't be hard — I just wanted to see if it would work.