fix(ai): respect TeamIndex for ally/enemy distinction

AiTurnContext.OpponentIds was everyone-except-self, so in team games the
AI would attack its own allies and score them as enemy material. The game
model already has TeamIndex on PlayerState and GameState.GetEnemyIds() /
AreAllies() helpers — the AI just never used them.

- AiTurnContext: use state.GetEnemyIds() so OpponentIds excludes allies
  (fixes attack targeting, threat detection, positional advance)
- MaterialScore: use state.AreAllies() so allied units/ArchSpirit score
  positively instead of as enemy material
- PositionalScore: skip allied players when collecting enemy positions

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-04-14 20:32:03 -04:00
co-authored by Claude Happy
parent ad031a8e30
commit a814d2bdb9
2 changed files with 5 additions and 6 deletions
+1 -3
View File
@@ -14,9 +14,7 @@ public sealed class AiTurnContext
State = state;
AiAccountId = aiAccountId;
AiPlayer = state.Players[aiAccountId];
OpponentIds = state.Players.Keys
.Where(k => k != aiAccountId && !state.Players[k].IsEliminated)
.ToList();
OpponentIds = state.GetEnemyIds(aiAccountId).ToList();
Rules = state.Rules;
}
@@ -52,8 +52,9 @@ internal static class ScoringFunctions
{
if (player.IsEliminated) continue;
bool isOwn = playerId == aiAccountId;
float sign = isOwn ? 1f : -1f;
// Allies (same TeamIndex) score positively; enemies score negatively.
bool isAlly = state.AreAllies(playerId, aiAccountId);
float sign = isAlly ? 1f : -1f;
foreach (var fc in player.Field.OfType<FieldCard>())
{
@@ -214,7 +215,7 @@ internal static class ScoringFunctions
var enemyUnitPositions = new List<Coord>();
foreach (var (id, p) in state.Players)
{
if (id == aiAccountId || p.IsEliminated) continue;
if (p.IsEliminated || state.AreAllies(id, aiAccountId)) continue;
if (p.ArchSpirit?.Position.HasValue == true)
enemyArchPositions.Add(p.ArchSpirit.Position.Value);
foreach (var fc in p.Field.OfType<FieldCard>())