Bot programming tutorials Mighty Professional
Build a Legend Bot · The series

Build a Legend Bot

You know one programming language and you want to compete in CodinGame's bot contests, where your program plays everyone else's and climbs the leagues from Wood to Legend. This page maps the twenty tutorials that get you there and shows where to start. Every page answers part of one question: how much of the bot to write by hand, how much to search, and whether to train any of it.

FormatA hub plus 20 tutorials PathFirst bot to Legend, by search or by a trained network LevelBeginner to advanced, per page StackC++20 & Rust · Python & PyTorch for training · browser demos
What you'll be able to do by the end

01How to read this

A bot is a program that plays a game for you. On CodinGame it reads the state of the game from standard input each turn, prints its move to standard output, and has a fraction of a second to do it. A referee, the program that owns the true game state, checks every move and applies the rules. CodinGame runs these games as contests with a fixed end date and as permanent multiplayer puzzles you can play any day.[1]

This series teaches you to build such a bot and climb the leagues with it, from the first league to Legend at the top. It assumes you read and write code in one language (loops, arrays, structs, a hash map, recursion) and remember high-school algebra. It doesn't assume you know what a game tree, a neural network or a confidence interval is: each page defines its terms where they first appear.

The right mix of hand-written rules, search and training depends on the game. In the author's lab, a search bot won every game it played against a trained network at Ultimate Tic-Tac-Toe, and at Spring Challenge 2022 a trained network beat the lab's best search bot by nearly the same margin. §5 has the numbers, and the case studies at the end go through the lab's games one at a time.

Three games carry most of the examples. Tron Battle, where light cycles leave walls behind them, is the running example for evaluation, alpha-beta, measurement and the machine-learning project. Ultimate Tic-Tac-Toe is the one for Monte Carlo tree search, and Mad Pod Racing for a first bot and evolutionary planning. All three are permanent games, so you can test your bot on them whether or not a contest is running. Listings come in C++20 and Rust side by side, and the machine-learning pages add Python with PyTorch, which does the training. Everything you submit has to fit in one source file of at most 100,000 characters.[2]

Where to start

If you're new to CodinGame, start at How Bot Contests Work (page 1) and read in order. If your bot is already in Gold, start at Measuring Bot Strength (page 9): it leans only on pages 1 to 4. If you came for machine learning, When to Use Machine Learning (page 11) needs pages 1 to 4 and 9, and it tells you whether your game is worth training for before you build anything. The graph in §4 shows what each page leans on.

02Leagues and phases

CodinGame ranks the players of each bot game in leagues: one or more Wood leagues, then Bronze, Silver, Gold and Legend, although a game can stop at a lower top league.[3] Every league below the top has a boss, a bot copied into the league that you have to beat to move up. Legend has no boss. Once you're in it, you climb by rating alone.

How you beat the boss changes on the way up. In the Wood leagues you usually play a short series against the boss alone and need a set number of outright wins, for example 3 of 5. From Bronze up, your bot plays ranked games against the other players in its league, and it's promoted once its rating reaches the boss's. A promotion can bring new rules, so read the statement again after each one. In a live contest the top leagues, usually Silver, Gold and Legend, stay closed until dates set in advance.[3]

The series' phases line up with that climb, from the bottom of the ladder up. Read the ladder as where each phase starts to pay, not as a requirement: no league demands a particular technique.

  1. Legend

    No boss is left, so you climb by rating. Near the top a real improvement can be smaller than the spread between two submissions of the same code, and measuring is what decides which version you keep.

    Phase 4 · MeasurementAdvanced · Search with a network
  2. Gold

    The last boss before Legend. In the author's lab, five games got past it with search or rule-based strategy, tuned by measurement, and three with networks trained by self-play.

    Phase 3 · SearchPhase 4 · MeasurementPhase 5 · Machine learning
  3. Bronze and Silver

    Your bot is now rated against the other players in its league. Phase 2 puts the rules into code you can run thousands of times a turn and gives every position a score, and Phase 3 uses both to try moves before playing one.

    Phase 2 · Rules in codePhase 3 · Search
  4. Wood

    A short series against the boss. Leaving Wood takes a bot that reads every input line, answers inside the time limit and follows a few sensible rules.

    Phase 1 · The arena

The phases are named for skills because the lab's results don't line up with one technique per league. Of the eight games the author's lab took to Legend, five got there with search or rule-based bots and no machine learning, and three with self-play networks, bots trained by playing copies of themselves.[4] A network is a second route through the same leagues. It paid off in some games and not in others, and page 11 is about telling which kind of game you have.

03The curriculum

The series has twenty pages in eight groups. Phases 1 to 4 build a search bot and the tools to tune it, with no machine learning. Phase 5 builds one trained bot from start to finish. The milestone puts every piece into one repository, and the last three pages go further.

Worked example

In reading order the capstone is page 17 of 20. A search bot needs fewer pages: pages 1 to 9 take you from the protocol to a verified simulator, an evaluation, all three searches, a fast implementation and the measurements to tune it. Phase 5 is optional, and five of the lab's eight Legend bots never used it.

Phase 1

The arena

How a contest runs, and a first bot that plays legal moves inside the time limit.
Phase 2

Rules in code

The game's rules as code you can run thousands of times a turn, and a number for how good a position is.
Phase 4

Measurement

How to tell a real improvement from luck, and how to learn from the players above you.
Phase 5

Machine learning

When learning pays, then one light-cycle bot, taken from an untrained network to a shipped submission.
Milestone

The lab

Every piece in one repository, ready for the next contest.
Advanced

Search with a network

A trained network and a search inside the same bot.
Adjacent

Case studies

The lab's games in detail, from its records. No page depends on them.

The site's other curricula are Build a Game Engine and Build a Language Model. Several pages here lean on them for depth: Graph Traversal for the breadth-first search behind territory counts, Neural Networks and Reinforcement Learning for the basics under Phase 5, and Inference & Quantization for the arithmetic behind shipping a network.

04What to read first

Reading straight through always works, because every page comes after everything it leans on. If you came for one page, the graph below shows a shorter route to it.

Worked example

Say you came for Self-Play Reinforcement Learning, page 14. It leans on Behavior Cloning and Measuring Bot Strength, and following those back gives 8 pages to read first: 1 to 4, 9, 11, 12 and 13. Straight through puts 13 pages in front of it. The five you can skip are the four search pages and Learning from the Leaderboard.

What to read first

Each box is a page, numbered in reading order and colored by phase, and each arrow runs from a page to a page that builds on it. Click a box, or pick a page from the list, and the pages it leans on light up one layer at a time, back to page 1. The readout lists them in reading order, with links. Every arrow points from an earlier page to a later one, so reading straight through never skips a prerequisite. Shipping a Network, page 16, draws on 14 of the 15 pages before it: all but Learning from the Leaderboard.

05The lab's results

The series follows what the author's lab did with nine CodinGame games in September and October 2026, and it reports the results as recorded, failures included.

Where each game stood on October 30, 2026
GameStandingWhat got it there
Back Track King (Summer Challenge 2026)Contest: Gold. Afterwards, on the permanent ladder: Legend, near the top of the table at best (October 25)NetworkA self-play PPO network that started as a copy of the contest bot. The best live result wrapped a one-turn search around it.
Fantastic BitsLegendNetworkA self-play PPO network
Spring Challenge 2022Legend, promoted on October 30 from Gold, 8.03 above the bossNetworkA self-play PPO network, also trained against scripted bots that imitate styles common in Gold. It overtook the lab's hand-written bot, which had stalled high in Gold, below the boss.
Ultimate Tic-Tac-ToeLegend, from Gold, 4.48 above the bossSearchMonte Carlo tree search on bitboards, with a solver for proven results, tree reuse, and playouts that take immediate wins and avoid giving them away
Tron BattleLegend, from Gold, 3.07 above the bossSearchParanoid alpha-beta with a chamber-corrected Voronoi evaluation
The Great EscapeLegend, from Gold, 3.17 above the bossSearchParanoid alpha-beta on bitboards, with a fixed opening for two-player games
Mad Pod RacingLegend, from Gold, 6.48 above the bossRule-basedOne pod races while the other blocks the opponent's leader
Troll Farm (Spring Challenge 2026)Legend, from Gold, 2.49 above the bossRule-basedAn economy bot that keeps training new trolls while they still pay for themselves. The lab's network stopped after one or two.
Game of DronesGold, below the boss: not promotedSearchRollout search with an opponent model learned from logged games

Eight of the nine games reached Legend: five with search or rule-based strategy built from players' published write-ups, and three with self-play networks.[4] Each margin is the bot's leaderboard rating, CodinGame's skill score for a submission, minus the boss's at the same reading, and a bot is promoted once its rating reaches the boss's. Reaching Legend and ranking well inside it are different bars: the Mad Pod Racing bot, written for the Gold league's rules, finished its Legend ranking in the lower half of the table.

From the author's lab

Back Track King was the one live contest. The author's hand-written bot finished it in Gold.[5] Afterwards, a network that started as a copy of that bot trained by self-play for 917,630 games, about 11.7 hours on one RTX 3080 Ti. It then beat the original in 500 of 512 games on fresh maps and reached Legend on the permanent ladder. The run's best live rank, near the top of the Legend table, came from a later network with a one-turn search around it. Six submissions of that network without the search, identical code each time, finished within about 1.6 points of each other. Six other versions finished inside that band and two below it, and the top two bots stayed out of reach.

In Ultimate Tic-Tac-Toe the lab's trained network lost all 64 games it played against the lab's search bot. Spring Challenge 2022 went the other way. Several rounds of changes to the lab's search bot failed their live tests there, while a network retrained against the Gold league's styles beat that search bot 127 games to 1 locally and then took the game to Legend.[4]

Only Back Track King was a live contest. The lab played the other eight as permanent multiplayer puzzles, where every league is open all the time, so their ranks aren't contest results. During a live contest the field improves while you do, and the top leagues open only on set dates.[3] Every rank on these pages says which kind it is, and when it was recorded.

06How this series was made

The series stands on a real project and on the write-ups of players who published how their bots work.

The project is the author's lab, a private repository. It started from the author's own bot for Back Track King, frozen byte for byte after the contest, and grew a verified simulator, tools for measuring one bot against another, search bots and a self-play trainer, which were then used on eight more games.[4] Every result the pages quote from it sits in a box marked "From the author's lab", with the record file named in the page's sources. Failures get the same detail as wins, such as a 61% win rate that came only from breaking a mirror match (two copies of the original bot always draw).

The pages teach you to build every piece yourself. Their code is written for the pages, short excerpts of the lab's own code appear where they help, and no other person's code appears anywhere. Facts about the platform come from CodinGame's documentation, its staff's posts or its source code, and anything a player reported is credited to that player. The author used AI coding tools to study the material and to run the lab's experiments.

Credits

The lab's bots are built on ideas from players who wrote up how their own bots work. The lab read those write-ups as prose and wrote its own implementations; none of their code was used.[4] Each name below links to the player's write-up, and placements are as the player states them or as the contest leaderboard shows.

Back Track King, Summer Challenge 2026

Other bots trained by reinforcement learning

Search and hand-written bots

The search pages also draw on Jeff06 and pb4608, now pb4 (genetic algorithms, 1st and 3rd in Coders Strike Back), Hastings (aiming at the checkpoint minus four times the velocity), Psyho and Owl (beam search and a greedy search over seven moves in the same contest), Janzert and dhartmei (Tron chambers and endgames), jacek and TomAlard (Ultimate Tic-Tac-Toe search), Recar and Romka (The Great Escape), and Nanaeda (Spring Challenge 2022).

07Sources

Each tutorial researches its own topic from primary sources and lists them. The sources below support the claims on this page.

  1. CodinGame, 2026. llms.txt and the CodinGame agent skill documentation, retrieved October 30, 2026. Bot programming games run as time-limited contests and as permanent multiplayer puzzles; a bot reads its turn from standard input and answers on standard output.
  2. CodinGame Help Center, Languages Versions, retrieved October 30, 2026. "The code size for any game is limited to 100k characters."
  3. CodinGame, 2026. Leagues and promotion, CodinGame API documentation, retrieved October 30, 2026. The league ladder, bosses, boss battles in Wood, promotion by rating from Bronze up, new rules after a promotion, and top leagues that open on preset dates in public contests.
  4. Author's lab records, 2026 (private repository). Standings, promotions and submissions for all nine games in experiments/live-submissions/<game>/rankings.jsonl and submitted.jsonl (through October 30, 2026); the Back Track King final test in experiments/nn-final-20261014.json; games and hours per training iteration in experiments/runs/nn-main/metrics.jsonl; live ranks and the six identical submissions in experiments/live-submissions/summer-challenge-2026-back-track-king/evaluations-20261024.json; the climb of the other eight games, including Spring Challenge 2022's 127 to 1, in docs/postmortem-lessons.md; the Ultimate Tic-Tac-Toe network's 0–0–64 against the search bot in games/tictactoe/README.md; what was borrowed and from whom in docs/provenance.md. First-hand results from one lab.
  5. CodinGame, Summer Challenge 2026 (Back Track King) global leaderboard, retrieved October 30, 2026 through the endpoint the page itself calls. 1,595 ranked players; the author's final contest league (Gold) is from the lab's API record in docs/provenance.md.

Good places to start