Influence Maps
A single soldier can reason about one threat. A strategy game's AI, or a squad commander, needs to reason about the whole map: where is the front line? Which areas do we control? Where is it safe to send the medic? Where are the enemy weakest? An influence map answers all of these with one cheap data structure: a grid where every cell holds a number saying how strongly each side "controls" it.
Stamping influence
Each unit spreads influence around itself that fades with distance. A linear falloff is the easiest to read: a unit of strength s adds max(0, s - distance) to every cell. Do this for both sides, and the interesting maps fall out of simple arithmetic:
| Map | Formula | Answers |
|---|---|---|
| Net influence | friendly - enemy |
who controls a cell (sign) and how firmly (size) |
| Tension | friendly + enemy |
where both sides are strong: the front line, where fights happen |
| Vulnerability | tension - abs(net) |
contested cells: high tension, no clear owner |
using System;
const int W = 16, H = 8;
var red = new[] { (X: 2, Y: 2, S: 8.0), (X: 3, Y: 6, S: 5.0) };
var blue = new[] { (X: 12, Y: 3, S: 8.0), (X: 13, Y: 6, S: 6.0) };
double[,] redMap = Stamp(red), blueMap = Stamp(blue);
Console.WriteLine("Net influence (red - blue), R/B = units:");
for (int y = 0; y < H; y++)
{
var line = "";
for (int x = 0; x < W; x++)
{
string unit = Array.Exists(red, u => u.X == x && u.Y == y) ? "R" : Array.Exists(blue, u => u.X == x && u.Y == y) ? "B" : null;
int net = (int)Math.Round(redMap[y, x] - blueMap[y, x]);
line += unit != null ? quot; {unit}" : net == 0 ? " ." : quot;{net,4:+0;-0}";
}
Console.WriteLine(line);
}
// Queries the AI actually asks.
(int X, int Y) frontline = (0, 0), safest = (0, 0);
double bestVuln = double.MinValue, bestSafe = double.MinValue;
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++)
{
double net = redMap[y, x] - blueMap[y, x], tension = redMap[y, x] + blueMap[y, x];
double vuln = tension - Math.Abs(net);
if (vuln > bestVuln) { bestVuln = vuln; frontline = (x, y); }
if (net > bestSafe) { bestSafe = net; safest = (x, y); }
}
Console.WriteLine(quot;most contested cell: ({frontline.X},{frontline.Y}), vulnerability {bestVuln:F1}");
Console.WriteLine(quot;safest cell for red: ({safest.X},{safest.Y}), net {bestSafe:F1}");
int redCells = 0, blueCells = 0;
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++)
{
double net = redMap[y, x] - blueMap[y, x];
if (net >= 1) redCells++; else if (net <= -1) blueCells++;
}
Console.WriteLine(quot;cells controlled: red {redCells}, blue {blueCells}, contested {W * H - redCells - blueCells}");
static double[,] Stamp((int X, int Y, double S)[] units)
{
var map = new double[H, W];
foreach (var u in units)
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++)
{
double d = Math.Sqrt((x - u.X) * (x - u.X) + (y - u.Y) * (y - u.Y));
map[y, x] += Math.Max(0, u.S - d);
}
return map;
}Net influence (red - blue), R/B = units:
+5 +6 +6 +6 +5 +4 +2 . -1 -3 -4 -5 -5 -5 -4 -4
+6 +7 +7 +7 +6 +4 +2 . -2 -3 -5 -6 -7 -7 -6 -5
+6 +8 R +8 +7 +5 +2 . -2 -4 -7 -8 -9 -9 -8 -6
+7 +8 +9 +9 +8 +5 +3 . -2 -5 -8 -9 B -10 -9 -7
+7 +8 +9 +9 +8 +6 +3 . -3 -6 -8 -10 -11 -11 -10 -8
+6 +8 +9 +9 +8 +6 +3 . -3 -6 -8 -10 -11 -11 -10 -8
+6 +7 +8 R +8 +6 +3 . -3 -6 -7 -9 -10 B -9 -8
+4 +6 +7 +7 +6 +5 +3 . -3 -5 -6 -8 -9 -9 -8 -7
most contested cell: (7,2), vulnerability 5.8
safest cell for red: (2,2), net 8.9
cells controlled: red 56, blue 64, contested 8
Positive numbers are red territory, negative numbers blue, and the column of dots in the middle is the front line, where the two influences cancel. The red commander can now send reinforcements to the most contested cell, retreat a wounded unit toward the safest one (here, unsurprisingly, the cell of its strongest unit), and count territory for its strategic decisions, all from two arrays.
Influence beyond "where are the units"
The same grid trick works for anything that has a position and fades with distance:
- Danger maps: stamp the areas covered by enemy turrets, recent explosions or where allies died. Pathfinding then adds
danger × weightto the cost of each cell, so the A* path avoids kill zones without any special code. - Visibility maps: stamp the cells each enemy can see (from vision cones); a stealthy unit routes through the dark cells.
- Interest maps: loot, objectives, resources. An RTS uses them to choose where to expand; a scavenger animal uses one to choose where to go.
- History maps: add to a cell every time the player is seen there and let it decay slowly; guards then patrol where the player tends to be.
Tip: Don't recompute everything every frame. Units move slowly relative to the grid, so update the map a few times per second, or only re-stamp units that changed cell. Strategy games often run a coarse map (say 4 m cells) for the commander and keep fine-grained queries for individual soldiers.
Stamping vs. propagating
Stamping by straight-line distance ignores walls: influence leaks through a cliff into the next valley. The alternative is propagation: each update, every cell takes a blend of its own value and the decayed maximum of its neighbours, cell = lerp(cell, max(neighbour × decay), momentum). Walls simply don't take part, so influence flows around them like the hearing flood. It costs a pass over the grid per update but gives a map that respects the level layout and changes smoothly over time.
Test yourself
Which derived map highlights the front line, where both sides are strong?
- Net influence
- Tension (friendly + enemy)
- Only the friendly map
- The danger map
How can an influence map make A* avoid dangerous areas without changing the A* code?
- Remove dangerous cells from the grid
- Add the danger value (times a weight) to each cell's movement cost
- Run A* twice
- Use a different heuristic
What is the main advantage of propagating influence instead of stamping it by straight-line distance?
- It is cheaper
- Influence flows around walls instead of leaking through them
- It needs no grid
- It works without units