A Game You Play With Code: Why I Build a Screeps Bot

Part 1 of the series Building a Screeps AI.

I wanted to learn JavaScript. What I ended up with is an empire of more than 500 small robots that runs day and night without me, trades on a market, builds its own cities and occasionally goes to war.

This is the first part of a series about that journey. It is less about clever algorithms (those come later) and more about the question every side project has to answer at some point: why on earth am I doing this?

What is Screeps?

Imagine a real-time strategy game in which you never click a unit. Instead you write code, upload it, and the game server runs it for you — every single game tick, around the clock, against other players who do exactly the same.

That is Screeps. A few core ideas are enough to follow the rest of the series (the official documentation has the full picture):

Diagram: one tick in Screeps. The server hands your code the state of the world, your code decides within the CPU budget, then the server applies all decisions at once and the next tick starts.
One tick: the world waits, your code decides, the server acts, and the cycle repeats every few seconds.
  • The world is a huge grid of rooms. Each room is a 50 × 50 tile map with energy sources, sometimes a mineral, and a controller you can claim.
  • Creeps are your units. You design their bodies from parts (work, carry, move, attack, heal …), spawn them, and they die of old age after roughly 1500 ticks. Nothing lives forever — everything has to be replaced.
  • A tick is one game step. Each tick the server calls your code once. Whatever your code decides in that moment is what happens.
  • CPU is the real currency. Every player gets a fixed CPU budget per tick. Smart code does more with less; sloppy code hits the limit and simply stops thinking for a while.
  • The controller level (RCL) of a room unlocks buildings, and your global control level (GCL) decides how many rooms you may own at all.

Quick glossary

  • Tick: one game step; your code runs once per tick.
  • Creep: a unit you design, spawn and program.
  • Room: a 50 × 50 tile map; the world is a grid of them.
  • Spawn: the building that produces creeps.
  • Controller / RCL: the heart of an owned room; its level unlocks buildings.
  • GCL: your global control level; it limits how many rooms you can own.
  • CPU budget: the computing time you get per tick.
  • Bucket: unused CPU that is saved up for busy ticks.
  • Shard: one of several separate copies of the world map.

The twist is that you are never really “playing”. You are designing a system that plays. If it fails at 3 a.m., it fails alone.

Where this bot comes from

Bar chart of commits per month from 2018 to 2026 on a log scale: a single commit in 2018, a burst in autumn 2021, a few commits during the quiet years, and a much larger burst from spring 2026 peaking at over 300 commits per month.
Commits per month to the bot, 2018–2026 (log scale). Source: git history, as of November 2026.

2018: one room and a lot of flags

I found Screeps in 2018, at a time when I knew very little JavaScript. My first attempts could barely build up a single room. Most of what happened was steered by hand: I placed coloured flags in the game, and the code reacted to them — “build here”, “attack there”, “claim this room”.

It worked, sort of. But it was a remote control, not an AI. The bot did what I told it; the moment I stopped watching, it stopped improving.

2021: the restart

In 2021 I came back with more experience from my day job as a developer, and I saw Screeps as the perfect place to try out things I could not easily try at work. TypeScript replaced plain JavaScript early on.

What kept me going was simple: the deeper I went, the more complex and interesting it became. Every solved problem revealed two new “construction sites”. Energy logistics led to remote mining, remote mining led to neighbours who did not like that, neighbours led to defence, defence led to CPU problems. The autumn of 2021 was the most intense phase of that first restart — November alone saw more than fifty commits.

The quiet years

Then life happened. A professional change and a personal reorientation, and between 2022 and 2025 again a lot going on at work and at home. The bot kept running in the background with only occasional touches. Screeps is forgiving in that way: a decent bot survives a long time on autopilot. It just doesn’t get any smarter.

2026: a proper engineering setup

The real comeback in 2026 had a lot to do with AI. With it I could finally set up what a project like this deserves: an automatic build pipeline, full CI/CD, linting, and an extensive test suite — almost entirely generated, and the code quality went up massively. For the first time the bot became something I could change confidently without breaking a live world that never pauses.

Since then the history looks very different: hundreds of commits per month, more than a thousand unit tests, a private test server as a laboratory, and features I would never have dared to ship before.

What the bot is supposed to do

Today the bot runs on the persistent main world with more than twenty rooms and over five hundred creeps. Its job, roughly from the bottom up:

  1. Keep every room economically stable — energy must flow, spawns must stay full, nothing may starve.
  2. Grow — raise new rooms quickly, mine neighbouring rooms, expand into new territory.
  3. Defend — towers, ramparts, defenders, and knowing when to avoid a room entirely.
  4. Scale — trade on the market, run labs and boosts, plan buildings, remember what it has learned.

Architecturally that maps onto four layers: a thin tick shell, an empire-level orchestrator, room systems, and unit behaviour. Part 2 of this series walks through a single tick from start to finish.

Diagram of four stacked layers: tick shell, empire orchestrator, room systems and unit behaviour, each with a few keywords.
The bot in four layers, from the game loop down to a single creep.

The rules I gave myself

Over the years a few principles turned out to matter more than any single feature:

  • Autonomy first. The bot should claim, build, defend, trade and even fight without me. The 2018 flag remote control is the opposite of what I want today.
  • Never fix the game by hand. If the bot is stuck because it believes something wrong about the world, I don’t correct its memory or plant a flag. I fix the code so it detects the situation itself. Manual fixes hide the bug.
  • Measure before optimising. CPU is the scarcest resource; every new feature has to pay for itself, and the only way to know is to measure.
  • Test first, document everything. Every change gets a test; every session gets written down. A live world forgives slow code, but not a broken economy.

The moments that keep me hooked

People sometimes ask what the highlight was. Honestly: all of them.

  • My first room — watching the first spawn produce the first creep that actually did what I wrote.
  • My first lost room — painful, and the best teacher this game has.
  • The first autonomous expansion — the bot picked a room, sent a claimer and started building, without me.
  • The first lab jobs — chemistry running in the background, boosts appearing in a terminal.
  • The first market sales — my code trading with other players’ code, while I was asleep.
  • Every reset — whether I got wiped out or gave up all my rooms myself. Each restart is a clean slate, and each one showed me which parts of the bot were really robust and which only worked because the world happened to be kind.

Where I want to go

My goal is a bot that can react to anything new that comes along — new neighbours, new threats, new game mechanics — without me stepping in. That means optimising again and again, so there is always CPU left for the next feature.

The next big step is to go beyond a single shard: a bot that is present on all shards of the world, purely through its own automatic expansion.

What you can expect from this series

Roughly in the order the bot grew up:

  • How a tick is structured, and why the order of things matters.
  • The task system that turns “something should be done” into “this creep does it”.
  • Room planning, bunkers and extension crosses.
  • Creep roles, body design and the energy logistics that keep everything alive.
  • Remote mining, expansion, towers, ramparts and the minimum-cut trick for walls.
  • Markets, terminals, labs and boosts — and the industrial features that weren’t worth it.
  • CPU: profiling, a near-death spiral, and a bot that learned to throttle itself.
  • The private server as a lab, and then warfare: scouting, squads, formations, sieges and strongholds.
  • A season server, a loss, and peace.
  • The “cycle room”: turning surplus energy into control level by claiming, maxing and releasing a room over and over.
  • And finally: what I learned.

Next time: what actually happens inside a single tick?

Polaroid Workshop, by Marco / JG35

Another workshop?!

Yes, indeed. And totally worth it. It was in Vienna again, though on a different location. It was held by Marco (again) / JG35. We used the new developed films from The-Impossible-Project, again. It was awesome, again.

Little changes? Well, first and foremost, this time this article is written in english. (You should have noticed by now) Also, we sized down from 8×10″ to our old, beloved and known SX-70 and Polaroid 600* series. And well prepared we started into the workshop.

films from the-impossible-project
films from the-impossible-project

I have to admit that Macro has a gift to communicate his knowledge and you feel that he has fun in what he is doing. From the first moment you get well dragged along and fall in line with his enthusiasm.

just chillin
just chillin

 

getting situated
getting situated

smalltalk about different polaroids
smalltalk about different polaroids

 

eager to start
eager to start

For all who reached this article, I will not go into depth about polaroid cameras as you will most likely already know more about them than I do. Furthermore, I think Marco got it all covered.

So, what is left before we can go into the process of lift-offs and do cool stuff?

Oh, right, actually taking some pictures!

first contact
first contact

It's always in the details
It’s always in the details

After some time we were through with all the films and evaluated the outcome.

the shots
the shots

Finally we were itching to test the methods shown by Marco.

As hard as it looked some months ago with the 8×10″ film. I have to admit that it actually is not that hard. Given that we had someone to show us the process first and keep a steady eye on use during our experiments.

cut the film open
cut the film open

cut off borders
cut off borders

 

rinse the film before lift-off
rinse the film before lift-off

 

be careful
be careful

float the image onto the paper
float the image onto the paper

 

Looks easy, is easy … after you have done it a couple of times! It is doable and for sure it is a heck of fun! Try it, grab your Polaroid, get some film, cut it open and rinse it in warm water, then float it onto paper/glas/wood/… really … anything, you name it, you try it!

Thanks to

Marco for making this happen and guiding us through,

Brick-5 for a wonderful location for this workshop and for our exhibition,

The-Impossible-Project for reinvented the polaroid films and supplying us with them,

and well, us, the JG35 for making this workshop.

 

More photos us having fun and from the final results are shown here:

UK – Tag 11 – Der verregnete Tag

Heute war ein enttäuschender Tag.

Bereits am Morgen hat der Regen eingesetzt. Also beschloss ich einen ruhe Tag einzulegen und lediglich ein paar Kamera-Geschäfte abzuklappern. Jedoch, egal wo ich hin kam. Es waren fast keine brauchbaren Kameras zu finden. Und wenn dann Eine dabei war, die mir gefallen hätte, waren die Preise eine Frechheit. London ist definitiv keine Stadt um sich mit einer analogen SLR auszurüsten. Damit hatte ich zu aller letzt gerechnet. Dies dürfte wohl der Todesstoss für meine analoge Fotografie in England gewesen sein. Gerade darauf hätte ich mich so gefreut.

Starbucks
Starbucks

Nachmittag dann nur noch gemütlich Kaffee trinken und Buch lesen.

Auch ist es glaub ich an der Zeit, etwas über mein Hotel hier zu schreiben. Weiter empfehlen kann ich es nicht. Eigentlich ein schönes Hotel. Jedoch stark unterteilt in Klassen. Ist man erste Klasse, passt alles. Als Tourist jedoch hat man verloren. Ein eigener Lift, beim Eingang für die erste Klasse. Etwas weiter hinten und versteckt die Lifte für Touristen. Das Frühstück ist eigentlich normaler (schlechterer) Standard. Was jedoch ungut auffällt, ist das man jedoch vorher bei der ersten Klasse vorbei gehen muss und sieht wie hier das “bessere” Personal, persönlich jeden Tisch betreut und es Frühstück a lá Card gibt. Im Touristen Bereich, stehen für die 6 fache Anzahl an Gästen nur 2-3 Kellner zur Verfügung. Selbst diese bewegen sich nur im äußersten Notfall um eventuell Kaffee oder Brot aufzufüllen im offenen Buffet. Das Zimmer selbst ist vergessen worden. Defektes Fenster, defekter Duschvorhang, defekte Duschkopfhalterung, gebrochene Bett-Unterkonstruktion. Aber super Ausblick aus dem Zimmer. Nachdem ich jedoch sowieso nicht so oft im Hotel bin, reicht es.

der Ausblick
der Ausblick