games: no mercy on the felt, and the bill that went to the wrong window

The engine has been able to play No Mercy since aca523e. Now a browser can.

The switch is a switch, not a fourth table: the tier is still the table size,
because that is what you are paid for, and the deck is the other dial. Six faces
the normal box does not print, sized by the card's own vars and never by the box
they sit in. The stack says what the bill is on the felt, in the turn line and on
the button, and under it the deck is dead — you cannot draw your way out of a
bill somebody has run up and pointed at you.

The wild draws glow. That started as decoration and turned out to be doing work:
No Mercy prints a coloured +4 right beside the wild one, and in a hand of twenty
the glow is what tells them apart.

A buried seat is not an empty one, which is the whole trap here — a seat killed
at twenty-five holds no cards, and neither does a seat that just went out and
won. The view asks the engine which it is instead of counting to zero, so the
winner is never the corpse.

Two bugs, both found in a browser and neither findable anywhere else:

The felt's stack bill was writing into the chip bar. It was [data-pending], and
so is the bar's "your chips are still coming" readout — and the bar lives inside
the table's own root and comes first in the document. A stack quietly overwrote
the escrow message and never appeared on the felt at all. A table's attributes
are not a private namespace.

And hold'em, re-driven on the 20M-hand policy (six hands, got up 61 ahead of a
100 buy-in, money conserved to the chip — Phase 4 closed), let you click a button
that did nothing: Deal, Leave and Top up stayed alive through the whole deal
animation, where send() drops the click on purpose. The lock is on the buttons
now, not only in the variable.

Claude-Session: https://claude.ai/code/session_013M5nD7PgUboJXoDcYHzpuJ
This commit is contained in:
prosolis
2026-07-14 11:10:07 -07:00
parent aca523e511
commit 8db8845feb
11 changed files with 638 additions and 81 deletions

View File

@@ -145,3 +145,71 @@ func TestUnoWildWithNoColourIsRefused(t *testing.T) {
t.Logf("colour in play after the bots: %s", v.Uno.Color)
}
}
// A seat the mercy rule has buried holds no cards. So does a seat that has just
// gone out and won. The view has to tell them apart, because everything it says
// afterwards hangs off it: who won, whose fan of cards to rub out, and whether the
// player is looking at a payout or a grave.
//
// This is the whole reason the view asks the engine (Live) instead of inferring it
// from a count of zero.
func TestABuriedSeatIsNotTheWinner(t *testing.T) {
g, _, err := uno.New(100, mustTier(t, "nm-full"), 0.05, 7, 9)
if err != nil {
t.Fatal(err)
}
// Bury seat 2, the way the engine does: no cards, and out.
g.Hands[2] = nil
g.Out[2] = true
v := viewUno(g)
if !v.Seats[2].Out {
t.Error("a buried seat must say so; the felt draws it as a grave")
}
if v.Seats[2].Uno {
t.Error("a buried seat is not one card away from going out")
}
if v.Winner == 2 {
t.Fatal("the buried seat was reported as the winner — an empty hand is not a win")
}
if v.Winner != -1 {
t.Errorf("nobody has gone out yet, so there is no winner: got %d", v.Winner)
}
// And the other ending only this deck has: you win by outliving the table, with
// a hand still in front of you.
g.Phase, g.Outcome, g.Payout = uno.PhaseDone, uno.OutcomeWon, g.Pays()
if v := viewUno(g); v.Winner != uno.You {
t.Errorf("you outlived the table; winner = %d, want you (%d)", v.Winner, uno.You)
}
}
// The bill a stack has run up is the only thing on the table while it stands, so it
// has to reach the browser. It is a No Mercy field on a struct the normal game
// shares, which is exactly the kind of field that quietly never gets copied across.
func TestTheStackBillCrossesTheWire(t *testing.T) {
g, _, err := uno.New(100, mustTier(t, "nm-duel"), 0.05, 3, 4)
if err != nil {
t.Fatal(err)
}
g.Pending = 6
g.Phase = uno.PhaseStack
v := viewUno(g)
if v.Pending != 6 {
t.Errorf("the felt was told the bill is %d, want 6", v.Pending)
}
if v.Phase != string(uno.PhaseStack) {
t.Errorf("phase = %q, want %q", v.Phase, uno.PhaseStack)
}
}
func mustTier(t *testing.T, slug string) uno.Tier {
t.Helper()
tier, err := uno.TierBySlug(slug)
if err != nil {
t.Fatalf("no tier %q: %v", slug, err)
}
return tier
}