← All posts

Combat5 min read

The bot in Terminal Leave: rules, not a neural network

What the “AI” opponent in the demo battle is, and why “AI” in Terminal Leave means what it meant in the strategy games of the nineties.

The word “bot” or “AI” turns up in almost every post of this devlog. First, what it isn’t: it isn’t GPT, it isn’t a language model, and it isn’t a neural network of any kind. The “AI” in Terminal Leave is an ordinary program made of rules I wrote by hand. Nobody trained it, it doesn’t ask anyone anything, and it runs on the battle server next to the simulation.

Why it exists

The bot appeared in the first days of the project, before a battle could be seen on screen at all. There were four reasons, and all four still hold.

The first is development. Before there were graphics, battles existed only in tests, and in those tests two bots played each other from start to finish. That’s how I checked that a battle actually ends instead of hanging (there’s a separate post about it).

The second is the first battle with no signup. A person opens a link and plays straight away. A newcomer has no reason to wait for a live opponent to show up in the queue, so the first battle is always against the bot — and in that battle the bot carries simpler weapons.

The third is a battle when nobody is around. In a closed alpha the queue is often empty, and instead of waiting you can ask for a battle against the bot.

The fourth is a player who left. If someone quits a battle or loses connection, their soldiers don’t stand there like posts: the bot takes them over, but instead of fighting it leads them to the evacuation zone.

How it thinks

Every round the bot makes a plan for each of its soldiers — the same way a player does — and sends the server ordinary orders. The server checks them by the same rules as a human’s orders. The bot cannot change the state of the battle directly.

The bot sees only what its soldiers see. An enemy behind a wall or in the fog doesn’t exist for it. With no contact, the bot heads toward the side the enemy started from: that comes from the map, not from the other side’s plan. Its soldiers spread out over lanes of their own instead of filing down a single path.

Once an enemy is in sight, the bot picks a target: first whoever it can actually put down, then the most wounded, then the nearest. The fire mode depends on the weapon and the distance: a burst up close, an aimed shot at the edge of range, a single shot otherwise. A soldier queues up to three shots a round while there is time for them. If the magazine would run dry mid-volley, the rest of the round goes to reloading.

Where to stand, the bot decides by scoring the tiles nearby. Full cover adds more, half cover less, being exposed to each visible enemy takes away, and a line of fire on its own target adds. It also weighs a comfortable distance for its weapon, room from its squadmates and the length of the path. Cover is counted by the same function the simulation uses, so the bot can’t rely on protection that doesn’t exist in the battle. Before firing from cover a soldier drops to one knee. If he stands in the open, he first takes the few steps into cover and fires from there.

A frag grenade is thrown when at least two enemies are inside the blast and none of its own. A badly wounded soldier (under a third of his health) with an enemy close by falls back to the best cover he can reach — unless one more shot finishes his target. With nothing better to do, the bot puts a soldier on overwatch facing the threat.

None of this involves chance. The difference between soldiers of one squad comes from their ids, not from a random number generator, so the same position on the field always gives the same plan.

Why not a neural network

I do get asked this, so here is a straight answer: I’m not putting a language model in the bot’s place, and here’s why.

Cost. A request to a model means waiting, and money for every turn.

Clarity. When the bot does something stupid, I look at how the tiles scored and see which weight is to blame. A model has no answer to “why did it go there”.

Geometry. A battle is lines of fire, cover on the sides of tiles, ranges and time. A model describes such things in words; a program counts them — with the same functions the simulation uses.

“AI” in the game means what it meant in the strategy games of the nineties: an opponent driven by a program.

What it can’t do yet

  • Every bot behaves the same. There are no cautious or pushy ones yet.
  • It has no memory. Once an enemy leaves its sight, that enemy no longer exists for the bot, and it goes back to heading toward the enemy’s starting side.
  • The squad doesn’t act together. Its soldiers only stay out of each other’s way and don’t bunch up; there is no covering one another, no going round, no flanking.
  • It doesn’t throw smoke and doesn’t react to being suppressed.

Each of these is a next task. Today’s bot already takes cover and picks its targets, but beating it is no trouble.

The demo battle against the “AI” bot is open with no signup: play it.