Skip to content

fix: Add throttling to AI defense phase to prevent units from moving …#1160

Merged
braedonsaunders merged 1 commit into
mainfrom
claude/fix-ai-defense-strategy-Z2Sbc
Jan 30, 2026
Merged

fix: Add throttling to AI defense phase to prevent units from moving …#1160
braedonsaunders merged 1 commit into
mainfrom
claude/fix-ai-defense-strategy-Z2Sbc

Conversation

@braedonsaunders

Copy link
Copy Markdown
Owner

…instead of attacking

The AI defense phase was issuing ATTACK commands to ALL army units on every single tick. This constant re-commanding caused units to continuously reset their attack state, resulting in:

  1. Units moving around the enemy but never actually attacking
  2. Multiple AI armies converging to the same location and sitting idle

Changes:

  • Add DEFENSE_COMMAND_INTERVAL (20 ticks/1 sec) to throttle defense commands
  • Only re-command idle units, not units already engaged in combat
  • Increase threat search radius from 50 to 80 units for better detection
  • Include workers with attack damage in threat detection (worker rush defense)

This matches the existing attack phase logic which properly throttles commands and only re-commands idle assault units.

https://claude.ai/code/session_017TvSHA6ZyEaBu3iPh6p5AH

…instead of attacking

The AI defense phase was issuing ATTACK commands to ALL army units on every
single tick. This constant re-commanding caused units to continuously reset
their attack state, resulting in:
1. Units moving around the enemy but never actually attacking
2. Multiple AI armies converging to the same location and sitting idle

Changes:
- Add DEFENSE_COMMAND_INTERVAL (20 ticks/1 sec) to throttle defense commands
- Only re-command idle units, not units already engaged in combat
- Increase threat search radius from 50 to 80 units for better detection
- Include workers with attack damage in threat detection (worker rush defense)

This matches the existing attack phase logic which properly throttles commands
and only re-commands idle assault units.

https://claude.ai/code/session_017TvSHA6ZyEaBu3iPh6p5AH
@braedonsaunders braedonsaunders merged commit 92d903c into main Jan 30, 2026
4 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd1f8c1fe9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +515 to +519
// Unit needs commanding if:
// 1. It's idle (not doing anything)
// 2. It's completely stopped (no target, no destination)
const isIdle = unit.state === 'idle' && unit.targetEntityId === null;
const isStuck = unit.state === 'idle' && !unit.isInAssaultMode;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recall non-idle units during defense

Because getIdleDefendingUnits only selects units in unit.state === 'idle', the defending phase will issue no commands if the army is already moving/attacking (e.g., marching to an assault or chasing elsewhere) when the AI switches to defending. In that scenario idleDefenders is empty, so the AI stays in defense while the army keeps its old orders and the base can be left undefended. Consider also including non‑engaged moving units (or issuing an initial full defense command on state change) so defense actually retasks the army.

Useful? React with 👍 / 👎.

@braedonsaunders braedonsaunders deleted the claude/fix-ai-defense-strategy-Z2Sbc branch January 31, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants