Fix bugs around AI opponents.
This commit is contained in:
@@ -1290,11 +1290,14 @@ func (g *Game) runBattle() *BattleResult {
|
||||
}
|
||||
}
|
||||
|
||||
// A single side still holding a pet in play wins; anything else
|
||||
// (everyone out, or a stalemate with pets on both sides) is a draw.
|
||||
// A single side that can still field a pet wins; anything else (everyone
|
||||
// out, or a stalemate with pets on both sides) is a draw. We test canField,
|
||||
// not unit, because the loop can break the instant one side runs out while
|
||||
// the other's current pet has just fainted — that side still has pets left
|
||||
// in its stack (it simply wasn't refilled) and is the rightful winner.
|
||||
winner := -1
|
||||
for seat, s := range sides {
|
||||
if s.unit != nil {
|
||||
if s.canField() {
|
||||
if winner >= 0 {
|
||||
winner = -1 // stalemate / >2-player safety
|
||||
break
|
||||
|
||||
@@ -156,6 +156,23 @@ func TestManateeSelfRockFatalStillAddsApples(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A player whose only in-play pet faints to its own play effect (Manatee's
|
||||
// self-rock) still wins if it has pets left in its deck and the opponent has
|
||||
// none. The battle loop breaks the instant the opponent runs out — before the
|
||||
// survivor's next pet is revealed — so the winner must be decided by who can
|
||||
// still field a pet, not by who happens to have one in play at that instant.
|
||||
func TestSelfFaintWithReserveStillWins(t *testing.T) {
|
||||
g, _, _ := testGame(t)
|
||||
g.RollDie = func() int { return 2 } // 2 rocks = 4 damage, fatal to the 3-power Manatee
|
||||
res := forceBattle(t, g,
|
||||
[]Card{g.goldenPet(t, "Manatee"), g.pet("Reserve", 5)},
|
||||
[]Card{g.newApple()}, // opponent has only food — no pet, ever
|
||||
)
|
||||
if res.WinnerSeat != 0 {
|
||||
t.Fatalf("seat 0 should win with a reserve pet vs an all-food deck, got winner %d", res.WinnerSeat)
|
||||
}
|
||||
}
|
||||
|
||||
// Poison Dart Frog, once set aside, throws rocks each time a Bee is played.
|
||||
func TestPoisonDartFrogBeeRocks(t *testing.T) {
|
||||
g, _, _ := testGame(t)
|
||||
|
||||
Reference in New Issue
Block a user