← Back to devlog

Teaching Soldiers to Fight: AI First Steps

This week the army finally started acting like one. Until now, soldiers were glorified turrets with legs — they attacked whatever was closest and happily pathed through hazards to do it.

The behavior tree

Every soldier now runs a small behavior tree, evaluated a few times per second:

  1. Survive — retreat to the nearest tower’s healing aura when below 25% HP
  2. Protect — intercept orcs targeting the hero or a building
  3. Fight — engage the highest-threat orc in range
  4. Regroup — return to the rally point when idle

The ordering matters: a soldier mid-fight will still peel off to body-block an orc charging your barracks.

Pathfinding on the build grid

Because players reshape the map with walls in real time, we re-run flow-field pathfinding whenever the grid changes. Flow fields turned out to be a great fit — one field serves hundreds of units, so big armies stay cheap.

Next up

Formations. Right now twenty soldiers form what can only be described as a “friendly mob”. We want lines, wedges, and tower garrisons — that’s the next sprint.