From e3df26ae07d7c958033d5d398eef505388907a9c Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 13 Apr 2026 17:58:25 -0400 Subject: [PATCH] fix(ai): use real ST return formula in SacrificeOpportunityScore Previously assumed each sacrifice always yields +1 ST regardless of the unit's costs or the player's running ST total. Now calls SacrificeSystem.GetSacrificeValue / GetSTReturn exactly as the engine does, and respects FixedSacrificeReturn overrides. The projected ST total is accumulated unit-by-unit so the diminishing-return curve is correctly applied. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../src/SOR.Ai/Heuristics/ScoringFunctions.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Server/src/SOR.Ai/Heuristics/ScoringFunctions.cs b/Server/src/SOR.Ai/Heuristics/ScoringFunctions.cs index b22d20d..8498eda 100644 --- a/Server/src/SOR.Ai/Heuristics/ScoringFunctions.cs +++ b/Server/src/SOR.Ai/Heuristics/ScoringFunctions.cs @@ -314,8 +314,24 @@ internal static class ScoringFunctions if (sacrificeableCount == 0) return 0f; + // Compute actual ST return for each sacrificeable unit. + // ST earned per sacrifice depends on the card's SpiritSacValue AND the running ST total, + // so we accumulate in order (cheapest → most generous return first is irrelevant here; + // we just sum what each unit actually yields given the ST state at the time it's sacrificed). + int runningSt = aiPlayer.CurrentSt; + foreach (var fc in aiPlayer.Field.OfType()) + { + if (fc.IsLeader || !fc.CanBeSacrificed || fc.Position is null) continue; + if (!fc.Position.Value.IsOrthogonallyAdjacentTo(archSpirit.Position.Value)) continue; + + int stGained = fc.FixedSacrificeReturn + ?? SOR.Game.Combat.SacrificeSystem.GetSTReturn( + runningSt, + SOR.Game.Combat.SacrificeSystem.GetSacrificeValue(fc.StCost, fc.SpCost)); + runningSt += stGained; + } + int projectedSt = runningSt; float score = 0f; - int projectedSt = aiPlayer.CurrentSt + sacrificeableCount; foreach (var card in aiPlayer.Hand) {