Realtime Commander AI

Results

in this project, I explored the challenging topic of Commander/Strategist AI—an AI system that makes decisions based on goals and missions with real-time evaluations. The AI uses heat maps to guide its choices, simulating how a commander might assess a battlefield. Each commander is designed with unique characteristics, allowing for different playstyles: one may be highly aggressive, another balanced, while another might specialize in defensive strategies.

Github Page:
Documentation about how the system works can be found at this github page.

Insperations

The following games inspired this system’s design:

  • Star Wars: Empire at War – AI that intelligently chooses when to attack, defend, or retreat based on fleet strength and positioning
  • Supreme Commander – Emphasizes long-term strategic planning and economy-driven decisions
  • Total War franchise – Tactical AI that considers morale, unit matchups, and terrain
  • Command & Conquer – Known for aggressive, fast-paced AI with multiple attack patterns

Creating the system Architecture

From my research, I found that goal-based systems are a common approach to tackling this problem. The concept is straightforward: define a goal, then build a mission around it. A mission consists of assigned units and evaluation values that track its progress. If a mission is performing well, it continues. But if it begins to fail—or completely fails—it can either be abandoned, converted into a different mission, or even replaced with a new one aimed at recovering the failed attempt. As the saying goes, “plans change”—and so do missions.

I followed this design, where commanders oversee and manage their missions. Behind the scenes, however, the process is simplified: each mission is represented by a numerical evaluation. If that value drops too low for the commander’s tolerance, they must decide whether to abandon the mission, attempt to save it, or convert it into something new.

Stats map

The AI uses a StatsGrid to decide where to move and what areas to avoid. This grid highlights regions of advantage, enemy strength, and potential opportunities for better positioning. While the StatsGrid is currently separate from the partitioning grid (which isn’t ideal, as combining them would reduce memory use and overhead), this approach is sufficient for a small project. The AI also considers morale, alongside total attack power, as an indicator of whether its army—or the player’s—is gaining or losing confidence.