SWARM

A counter-drone defense trainer where the enemy swarm taught itself to attack, trained on an AMD Radeon GPU.


Inspiration

Cheap attack drones have become one of the biggest threats to bases and critical infrastructure. Yet the people who plan air defenses usually practice against scripted enemies that do the same thing every time.

So we asked: what if the enemy in the training sim had to figure out how to beat you? A red team that probes your defense, finds the radar shadow behind the ridge or the gap between two sensors, and makes you pay for it, the way a real one would.

What it does

SWARM is a 3D training simulation with three phases:

  1. Defend. Spend a fixed budget on radars (line-of-sight detection, blocked by terrain), jammers (scramble drone navigation) and interceptor pads. Hover with the radar tool to see exactly what it would cover from that spot.
  2. Attack. Choose an enemy: a classic Scripted A* planner, or a swarm trained with reinforcement learning at three difficulties (Recruit, Regular, Veteran). SWARM simulates 64 attacks against your defense and replays a representative one on a sand-table map.
  3. Review. An after-action report shows your breach rate across all 64 attacks, the corridors the drones used, an automatic blind-spot diagnosis with a suggested fix, the A* planner's view of your defense, and how you compare to an AI-optimized layout.

What sets it apart from other defense simulations:

  • Tactics the swarm found. We never programmed tactics. The swarm was only rewarded for getting through. SWARM mines every attack and names what emerged: wait-and-dash runs, valley runs, radar-shadow corridors, saturation, pincers, decoys, multi-axis probing. You can draw each one on the map or watch an example. Against the same defense, A* takes the radar-shadow route; the learned swarm holds position and then dashes.
  • See inside its head. During a replay, a "What it's thinking" panel shows the selected drone's live move probabilities and the network's own forecast of whether it will get through. Press N and you get the full neural network: the drone's actual inputs, all 7 hidden layers firing, the 10 outputs, the neurons that pushed for or against its move, and an attention map projected onto the terrain. The server re-runs the exact battle from its seed, so every number shown is what the network actually computed.
  • Watch it learn. Replay your defense against five snapshots from the swarm's own training run, from random flight to Veteran, and watch the breach rate climb.
  • Two theaters. A north-axis mode, and a 360° mode where the base sits mid-map and drones can come from any edge.

Who it helps: air-defense planners and trainees, and anyone teaching how sensor coverage, terrain and layered defense interact. It works as an automated red team: you find your defense's weaknesses before someone else does.

How we built it

Where Algorithm
Interceptors All-pairs Dijkstra next-hop tables per map, so 4,096 parallel battles route every interceptor with one GPU tensor lookup. Targets are picked by threat evaluation (closest to the base, weighed against flight distance) and aimed with lead pursuit
Scripted enemy Threat-aware A*: distance plus penalties for radar, jammer and interceptor zones, replanning when jamming knocks a drone off course
Learned swarm's senses The same threat-aware cost field, solved for every cell of every battle at once by parallel Bellman-Ford relaxation on the GPU
Learned swarm's reward Progress along the plain shortest-path distance to the base

A unit test checks that A* and the Dijkstra tables produce identical routes.

The simulation (redcell/env.py) is written entirely as PyTorch tensor operations: movement, line-of-sight detection, jamming drift, interceptor assignment and pursuit, kill rolls. The same code runs 4,096 battles on the GPU for training and one battle on a CPU for the live simulation, so training and what you see on screen can never disagree.

The swarm is one neural network shared by all six drones, trained with PPO. Each drone sees an 11×11 local view (terrain, radar coverage, jammers, interceptors, other drones, the threat field), a 16×16 map summary and a few status values. It can move in 8 directions, hover, or "follow the pathfinder". It started from completely random flight.

An arms race: every 10 training updates, a genetic search over defense layouts finds the defenses that just barely beat the current swarm, and the swarm trains against those. The same search produces the "AI-optimized" defense shown in the report.

AMD hardware: we trained on an AMD Radeon Pro W7900D with ROCm. Each theater trained from scratch in about 17 minutes: 252 million drone decisions at roughly 250K per second.

Stack: Python, PyTorch (ROCm), FastAPI, Three.js, procedural Web Audio for sound, and Playwright for end-to-end UI tests. The UI follows military documents rather than a generic dashboard: an operation order, an after-action report, MIL-STD-2525-style unit symbols and date-time groups. The simulation runs fully offline.

Results

Measured on held-out strong defenses: layouts the A* attacker mostly fails against, never used in training or for picking checkpoints. 24 battles each.

Scripted A* Learned Veteran
North theater (205 defenses) 21.4% breach 29.2% (+36%)
360° theater (252 defenses) 25.0% breach 61.7% (2.5×)

How it beats A*: it spends 4% of its flight detected vs. 11%, waits for openings (taking 70 steps to break through vs. 30), spreads its attacks over nearly twice as many cells, and follows the pathfinder on only 43% of its moves, improvising the rest.

When we upgraded the interceptors with threat-based targeting and lead pursuit, A* lost ground. We retrained the swarm against the new interceptors and it gained: the learned enemy adapts to a smarter defense, and the fixed pathfinder can't.

Challenges we ran into

  • The swarm that refused to attack. Our first Veteran posted the best numbers, but against the strongest defenses it never attacked at all: it loitered outside radar range until time ran out. Two causes: timing out cost the same as being shot down, and the blue-team search threw away every defense the swarm couldn't beat, including the ones where it hid. Then the AI-layout search found that habit and exploited it. We made timing out 3× as costly, kept the stall-inducing defenses in training, and now reject any checkpoint that stalls on more than 10% of drones. That cost us a few points of headline breach rate, and we report the honest number.
  • ROCm performance. Small convolutions were 30–60× slower than the equivalent matrix multiplies, and fp32 matmuls were about 40× slower than bf16. Switching to a bf16 MLP made training 13× faster.
  • An arms race that stalled. The blue team first kept only unbeatable defenses, which give no learning signal. The fix was to keep the frontier: defenses the swarm beats about 20% of the time.
  • Reward hacking. A penalty for being detected made the swarm hide and time out instead of attacking, so we removed it.
  • A comparison bug. CPU and GPU random generators with the same seed produce different defenses, so our first A*-vs-swarm comparison wasn't apples to apples. We now evaluate both on identical layouts.
  • The cloud box. No internet and roughly 17 KB/s upload meant shipping slim tarballs. Running two GPU jobs at once crashed the driver, so jobs ran one at a time.

Accomplishments that we're proud of

  • A learned enemy that beats a classic pathfinder on defenses it has never seen, trained from scratch in minutes.
  • Tactics nobody programmed, detected and named automatically.
  • A neural network view that shows the real computation behind each move, not an illustration.
  • Being honest about the numbers: held-out benchmarks, a stall rate on every simulation, and a lower score we chose over a better-looking broken one.
  • A polished, end-to-end simulation that runs offline, with unit tests and an automated UI test across both theaters.

What we learned

  • RL agents will exploit any gap in the reward, and an arms race will find the exploit before you do.
  • Writing the simulation as batched tensor operations turns the simulation itself into a training environment for free.
  • Profile on the hardware you actually train on: what's fast on one GPU stack can be 60× slower on another.
  • Pathfinding and learning complement each other. Give the agent a pathfinding field as a sense and it starts at A* level, then learns what A* can't: timing, spreading out and dodging.

What's next

  • Let the player's own defenses feed the blue-team pool, so the swarm keeps adapting to how people actually defend.
  • Heterogeneous swarms (decoys, fast scouts, heavy strikers) and moving or pop-up air defenses.
  • Real elevation data (DEM tiles) so planners can train on terrain they actually defend.
Share this project:

Updates

Submission history