Make the AI a little smarter.

This commit is contained in:
Greyson Parrelli
2026-07-24 16:20:45 -04:00
parent e25a85e394
commit 0a1e2f9bee
4 changed files with 93 additions and 4 deletions
+21
View File
@@ -160,6 +160,11 @@ type BattleResult struct {
Events []BattleEvent `json:"events"`
WinnerSeat int `json:"winnerSeat"` // -1 = draw
Trophies int `json:"trophies"` // awarded to the winner
// Survivors is each seat's remaining force at battle end: pets still in
// play plus any never reached in the stack. The loser is 0. It measures how
// decisive the result was — the margin the AI uses to prefer a lineup that
// fights harder, even in a battle it can't win.
Survivors []int `json:"survivors,omitempty"`
}
// setAsideRocks is a fainted pet's pending rock payout.
@@ -1312,5 +1317,21 @@ func (g *Game) runBattle() *BattleResult {
res.Trophies = 2
}
}
// Record each side's leftover force: a live pet in play plus any pets never
// reached in the stack. The loser lands on 0.
res.Survivors = make([]int, n)
for seat, s := range sides {
cnt := 0
if s.unit != nil && s.unit.Alive() {
cnt++
}
for _, c := range s.stack {
if c.IsPet() {
cnt++
}
}
res.Survivors[seat] = cnt
}
return res
}
+5
View File
@@ -171,6 +171,11 @@ func TestSelfFaintWithReserveStillWins(t *testing.T) {
if res.WinnerSeat != 0 {
t.Fatalf("seat 0 should win with a reserve pet vs an all-food deck, got winner %d", res.WinnerSeat)
}
// The survivor margin reflects the leftover force: seat 0's unrevealed
// Reserve still counts, seat 1 has nothing.
if got := res.Survivors; len(got) != 2 || got[0] < 1 || got[1] != 0 {
t.Fatalf("survivors should be [>=1, 0], got %v", got)
}
}
// Poison Dart Frog, once set aside, throws rocks each time a Bee is played.