Skip to content

Repository files navigation

SkAI

An AI that teaches itself to ski through a gate slalom course, trained from scratch using NEAT (NeuroEvolution of Augmenting Topologies), a genetic algorithm that evolves neural network and topology together, no backpropagation involved.

SkAI demo

What it does

A population of skiers starts with no idea how to ski. Each one is controlled by a small neural network with random weights, and gets a score based on how well it navigates through a procedurally generated slalom course (alternating red/blue gates). Skiers that crash out or miss gates die early, skiers that clear gates and survive get to reproduce.

Over many generations, NEAT evolves both the network's weights and its structure, adding or removing neurons and connections, until the population reliably skis through gate after gate on its own, with no hardcoded skiing logic anywhere in the code.

How it works

  • Inputs (4): the skier's horizontal velocity, its horizontal position, its horizontal offset from the next gate, and its vertical distance to the next gate.
  • Outputs (4): steer left, steer right, accelerate, brake.
  • Fitness function: rewards passing through gates and staying near the center line, penalizes crashing, going out of bounds, or steering left and right simultaneously.
  • Each generation, neat-python handles selection, crossover, mutation, and speciation based on config-feedforward.txt.

Project structure

├── SkAI_NEAT.py
├── SkAI_winner_run.py
├── config-feedforward.txt
├── requirements.txt
├── img/
│   ├── demo.gif
│   └── kenney/          # Tile/sprite assets (see Credits)
└── winners_pickle/      # Examples of saved genomes

Getting started

Requirements

pip install -r requirements.txt

Train a new population

python SkAI_NEAT.py

This runs up to 500 generations (or fewer, if a genome hits the fitness threshold first) and saves the winning genome into winners_pickle/ as a timestamped .pkl file.

Controls while training:

  • S — slow mode (runs at 60 FPS so you can actually watch it)
  • F — fast mode (uncapped framerate, for faster training)
  • Esc — quit

Watch a trained skier

python SkAI_winner_run.py

You'll be prompted for a timestamp, enter the one matching a file in winners_pickle/, for example:

Date and time winner's training : 20260720-211908

Credits

  • Art assets: "Tiny Ski" tileset by Kenney, used under CC0.
  • Built with neat-python, an implementation of Kenneth Stanley and Risto Miikkulainen's NEAT algorithm.

License

The code in this repository is licensed under the MIT License. Third-party assets (Kenney tileset, neat-python) retain their own separate licenses as noted above.

About

Mini ski game featuring an AI agent that learns to ski using NEAT (NeuroEvolution of Augmenting Topologies).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages