feat: Integrate AI primitives into AI orchestration layer#1172
Conversation
Wire up sophisticated AI primitive systems into the AI orchestration layer: - AICoordinator: Initialize shared InfluenceMap and PositionalAnalysis, add per-player ScoutingMemory, WorkerDistribution, RetreatCoordination, and FormationControl instances - AIScoutingManager: Use ScoutingMemory for enemy intel tracking with confidence decay, strategy inference, and unit type detection - AITacticsManager: Use InfluenceMap for threat analysis, RetreatCoordination for coordinated retreats with rally points, FormationControl for army positioning with concave/box/spread formations - AIEconomyManager: Use WorkerDistribution for optimal worker saturation tracking and transfer recommendations across multiple bases - AIBuildOrderExecutor: Use PositionalAnalysis for strategic defensive building placement near choke points and pre-analyzed expansion locations This eliminates code duplication between src/engine/ai (primitives) and src/engine/systems/ai (orchestration) by properly integrating the primitives' sophisticated algorithms. https://claude.ai/code/session_01DNptntMLovVJiitzsVeDgY
1fcbcaf to
c4a1d46
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1fcbcaf942
ℹ️ 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".
| // Check group retreat status | ||
| const retreatStatus = retreatCoordinator.getGroupStatus(this.world, ai.playerId); | ||
| if (retreatStatus.isRetreating) { | ||
| // Issue retreat commands to retreating units |
There was a problem hiding this comment.
Trigger retreat orders without requiring group retreat
This branch only issues retreat MOVE commands when retreatStatus.isRetreating is true, but getGroupStatus only sets that flag when group retreat is active (retreat ratio/avg health threshold). As a result, individual low‑health units that receive retreat orders during retreatCoordinator.update(...) never get commanded to retreat unless a full group retreat is triggered, so they keep fighting and the new retreat coordination doesn’t engage in small skirmishes (e.g., 1–2 units drop below the health threshold while the rest of the army is healthy).
Useful? React with 👍 / 👎.
| for (const transfer of transfers) { | ||
| // The transfer already specifies which worker to move | ||
| const workerId = transfer.workerId; | ||
| const workerIndex = idleWorkers.findIndex(w => w.entityId === workerId); | ||
| if (workerIndex === -1) continue; |
There was a problem hiding this comment.
Execute transfers even when workers aren’t idle
WorkerDistribution can select workers that are still gathering when rebalancing oversaturated bases, but this code only executes a transfer if the worker is in idleWorkers and silently skips otherwise. In typical play, oversaturated workers are actively gathering, so transfers are never executed and the distribution system can’t actually rebalance bases. Consider issuing the transfer command regardless of idle state or ensuring WorkerDistribution only returns idle workers.
Useful? React with 👍 / 👎.
| const command: GameCommand = { | ||
| tick: currentTick, | ||
| playerId: ai.playerId, |
There was a problem hiding this comment.
Avoid overriding formation MOVE with same‑tick ATTACK
This ATTACK command is issued on the same tick as the earlier formation MOVE orders in executeAttackingPhase. Because commands are dispatched immediately and later orders override earlier ones, the attack order will cancel the formation moves, so units never actually form up before engaging (especially on the first attack cooldown tick). To make formations take effect, the attack order needs to be delayed or queued after units reach formation positions.
Useful? React with 👍 / 👎.
Wire up sophisticated AI primitive systems into the AI orchestration layer:
This eliminates code duplication between src/engine/ai (primitives) and src/engine/systems/ai (orchestration) by properly integrating the primitives' sophisticated algorithms.
https://claude.ai/code/session_01DNptntMLovVJiitzsVeDgY