Crossy Road AI

I’d been watching Trackmania AI experiments and Code Bullet, and wanted to try something along those lines. Teaching a chicken to cross the road seemed like a good place to start.

Watch the chickens · Race the AI · README and source

How the chicken learns

Each chicken has a small neural network. It looks at nearby traffic and obstacles, then picks between waiting, going forward, going backward, or moving left or right. At first, they’re about as good at this as you’d expect.

I run a population of them across a bunch of maps and reward getting farther. The better networks get to pass on their connections, with some mixing and random changes for the next generation. Over time, they start finding ways through the traffic.

The method is called NEAT: NeuroEvolution of Augmenting Topologies. Along with changing the connection weights, it can add neurons and connections as it goes. You can see the networks as well as what the chickens actually do with them.

Two ways to cross

The first version has cars and roads. Later training phases give the chickens more traffic lookahead and some memory of their previous actions, which helps them put longer crossings together.

The second adds trains and rivers with floating logs. The chickens get train warnings and information about whether there’s something to stand on. Getting across a road is one thing; getting onto a log and staying out of a train’s way takes a bit more practice.

Things to try

The replay chooser lets you jump from the early, mostly confused chickens to the later populations. Try another map, pause, scrub through a run, or slow it down to see why a move worked. There are replays for the trains-and-logs version too.

My favorite view mixes ten saved chickens from each of the 150 display generations: 1,500 chickens on the same map. Or play against the AI and see who gets farther.

These are saved networks playing through the map again. They aren’t learning in your browser. The README has the training phases, results and evaluation details if you want to get into that side of it; a highlight’s high score is the population’s best run on that particular map.

Built with TypeScript and Three.js, with original game assets and source adaptations from Evan Bacon’s Expo-Crossy-Road. The credits and notices live with the source. This is an independent project, unaffiliated with Hipster Whale.