Implement priority token.

This commit is contained in:
Greyson Parrelli
2026-07-23 00:45:25 -04:00
parent 1c457c602a
commit b8775432b4
6 changed files with 280 additions and 39 deletions
+76
View File
@@ -20,6 +20,10 @@ func testGame(t *testing.T) (*Game, *Player, *Player) {
if g.Phase != PhaseShop {
t.Fatalf("expected shop phase after both players join, got %s", g.Phase)
}
// Pin the (otherwise random) priority token to seat 0 so tests are
// deterministic: seat 0 shops first and wins battle simultaneity races.
g.PrioritySeat = p1.Seat
g.Turn = p1.Seat
return g, p1, p2
}
@@ -620,3 +624,75 @@ func TestTemporariesExpireAfterBattle(t *testing.T) {
t.Fatalf("pets should survive the round: %+v", p1.Deck)
}
}
// TestPriorityTokenInitialAssignment checks the token starts on a real seat
// and that seat opens the shop.
func TestPriorityTokenInitialAssignment(t *testing.T) {
g := New()
if _, err := g.AddPlayer("Alice"); err != nil {
t.Fatal(err)
}
if _, err := g.AddPlayer("Bob"); err != nil {
t.Fatal(err)
}
if g.PrioritySeat < 0 || g.PrioritySeat >= len(g.Players) {
t.Fatalf("priority token should start on a real seat, got %d", g.PrioritySeat)
}
if g.Turn != g.PrioritySeat {
t.Fatalf("priority holder should open the shop: turn=%d priority=%d", g.Turn, g.PrioritySeat)
}
}
// TestPriorityWinsRockRace: two pets that both throw rocks on play would each
// kill the other, so whoever has priority throws first and survives. Flipping
// the token flips the winner, proving the token — not seat order — decides.
func TestPriorityWinsRockRace(t *testing.T) {
for _, priority := range []int{0, 1} {
g, _, _ := testGame(t)
g.RollDie = func() int { return 2 } // 3 dice = 6, lethal to a 2-power pet
g.PrioritySeat = priority
res := forceBattle(t, g,
[]Card{g.realPet(t, "Dolphin")},
[]Card{g.realPet(t, "Dolphin")})
if res.WinnerSeat != priority {
t.Fatalf("priority seat %d should win the rock race, winner=%d", priority, res.WinnerSeat)
}
}
}
// TestPriorityTokenTransfer: a winner who holds the token hands it to the
// loser; a loser who holds it keeps it; a draw leaves it put.
func TestPriorityTokenTransfer(t *testing.T) {
// Winner holds it -> passes to the loser.
g, _, _ := testGame(t)
g.PrioritySeat = 0
forceBattle(t, g, []Card{g.pet("Champ", 9)}, []Card{g.pet("Chump", 1)})
if g.Battle.WinnerSeat != 0 {
t.Fatalf("seat 0 should win, got %d", g.Battle.WinnerSeat)
}
if g.PrioritySeat != 1 {
t.Fatalf("winner should hand the token to the loser, priority=%d", g.PrioritySeat)
}
// Loser holds it -> keeps it.
g, _, _ = testGame(t)
g.PrioritySeat = 1
forceBattle(t, g, []Card{g.pet("Champ", 9)}, []Card{g.pet("Chump", 1)})
if g.Battle.WinnerSeat != 0 {
t.Fatalf("seat 0 should win, got %d", g.Battle.WinnerSeat)
}
if g.PrioritySeat != 1 {
t.Fatalf("a losing token holder should keep it, priority=%d", g.PrioritySeat)
}
// Draw -> token stays put. Equal-power pets trade lethal blows at once.
g, _, _ = testGame(t)
g.PrioritySeat = 0
forceBattle(t, g, []Card{g.pet("A", 3)}, []Card{g.pet("B", 3)})
if g.Battle.WinnerSeat != -1 {
t.Fatalf("mutual KO should draw, got %d", g.Battle.WinnerSeat)
}
if g.PrioritySeat != 0 {
t.Fatalf("a draw should leave the token put, priority=%d", g.PrioritySeat)
}
}