wiwis.dev

How Warfront's nineteen bots think

· Warfront

View of the Warfront battlefield: the ruined village, the dirt roads, the craters and the forest

A match of Warfront has twenty soldiers: the player and nineteen computer-controlled ones. These bots work under a constraint many games don't impose on theirs: they follow exactly the same rules as the player. Same rifle, same damage, same vehicles, and above all, no cheating. A bot can't see through walls and doesn't know where enemies are unless it has seen them. Everything it knows, it has perceived. Here's how they work, step by step.

No two soldiers quite alike

When it's created, each bot gets a skill level drawn at random between 0.82 and 1.04. That number affects everything: its reaction time, how fast it turns its head, how accurate its aim is. A bot at 1.04 reacts about a fifth faster than a bot at 0.82. There's no difficulty setting: every match mixes more and less skilled soldiers, just like a real team.

Each bot is also assigned a lane, one of four strips of terrain that cross the map from east to west. This keeps a team's ten soldiers from marching single file down the same path: the front naturally spreads across the full width of the battlefield, from the forest to the farm.

Seeing: a gaze, not a map

A bot looks around three or four times per second, not every frame: a real soldier doesn't reassess everything constantly, and it saves computation. It can see up to 150 meters, in a field of a little over 140 degrees in front of it. Three exceptions let it notice an enemy outside that field: if the enemy is within 18 meters, has just hurt it, or was already being tracked.

Among potential enemies, it ranks the candidates by distance, favoring whoever just hit it and whoever it was already aiming at. Then, for the top three only, it checks whether it can actually see them: the game casts a ray from its eyes to the enemy's chest, then to their head. A wall, the terrain or foliage blocks that ray. If only the head is showing, it aims for the head. An enemy it hasn't seen for three seconds is forgotten.

Foliage gets special treatment: it blocks the bots' line of sight, but not bullets. A player hiding in a hedge is invisible, but no safer for it.

Reacting: time to process

When a bot spots a new enemy, it doesn't fire right away. It needs between 0.3 and 0.8 seconds to react, depending on its skill level and a bit of randomness. That's roughly the speed of a human reflex facing an unexpected target, and it's what gives a player who pops out first a fighting chance.

Aiming: an error that shrinks but never disappears

This is the heart of the system. The moment it spots its target, the bot starts with an aiming error that grows with the target's distance. That error then shrinks quickly: it's divided by nearly three roughly every half second. The longer it tracks a target, the more accurate it gets. That's what gives duels their rhythm: a bot's first bullets miss, the following ones much less so.

But the error never drops to zero. It has a floor that grows with distance: about 40 centimeters at 50 meters, and more than a meter at 100 meters. When the error reaches that floor, it's redrawn in a random direction. So the bot never locks perfectly onto its target: its crosshair wobbles slightly around it, like a real player's. Beyond 25 meters, it raises its rifle to aim, which tightens its spread exactly as it does for the player.

Shooting: one round at a time

A bot fires when three conditions are met: its reaction time has elapsed, its weapon is lined up with the point it's aiming at, and it isn't reloading. Between shots, it waits between a quarter and two thirds of a second. The rifle can fire faster, but a bot that emptied its magazine in one second would be both overpowered up close and ridiculous at range.

Before each shot, it has a small chance, about one in five, of aiming for the head instead of the chest. It reloads when its magazine is empty, but also as a precaution when it has fewer than six rounds left and no enemy in sight.

During a firefight, it keeps moving: every one to two seconds, it decides to strafe left, strafe right, or stay put. Beyond 40 meters, it stands still to aim properly. It moves toward a target that's too far away, beyond 55 meters, and backs off from an enemy that's too close, within 7 meters.

Moving: the front line

Bots have no fixed objective on the map. Instead, every second, the game computes a front line: the midpoint between the average positions of each team's living soldiers. When blue advances, the front advances with it. Each bot heads for a point a little past that front, on the enemy side, in its own lane. If it has seen an enemy in the last six seconds, it heads for where it spotted them instead.

To get there, it plans its path on a grid that splits the map into 2-meter cells: 128 by 80 cells. A cell is walkable if nothing blocks feet or head and the slope isn't too steep. The algorithm used, called A*, explores neighboring cells starting with the ones that look closest to the goal, until it finds a way through. The resulting path is then smoothed: when the straight line between two points is clear, the bot cuts across instead of zigzagging along the grid.

It recomputes this path every seven to thirteen seconds, since the front keeps moving. If it gets stuck, covering less than 60 centimeters in almost a second, it jumps and looks for another way. While walking, it doesn't necessarily look ahead: it keeps its eyes on the spot where it last saw an enemy. And it sprints, unless it has seen an enemy recently, in which case it advances cautiously.

Vehicles

When a bot respawns at its base, it has a six-in-ten chance of claiming a nearby free vehicle, and it picks the tank first. It drops its claim if it spots an enemy before getting there.

A stuck vehicle backs up for a second and a half, then tries again. After three failed attempts, the bot gets out and continues on foot.

Why not make them perfect

It would be easy to write a bot that hits every time: the program knows the exact position of every soldier. All the work goes the other way: taking that knowledge away and giving the bot believable flaws. A limited field of view, a reaction time, hesitant aim, a human firing rhythm. These limits are what make duels readable. When a bot misses, it misses for a reason the player can understand and exploit: it didn't see them coming, it had only just spotted them, or the distance was too great. The twelve tips for Warfront build on exactly these weaknesses.

Play WarfrontGame page

Read next