package casino import "testing" // The "list" view doubles as the availability sheet: during the insurance // window it names the insurance stake and the decline, and during a turn it // names the wagers the current hand could still add (double/split/surrender). func TestBlackjackWagerListFollowsTheHand(t *testing.T) { table := newBlackjackTable(1, TableConfig{ID: "blackjack", Game: GameBlackjack}, newTestRand()) w := &testWallet{credits: 100} table.players.add("alice", &blackjackPlayer{ Participant: Participant{Name: "alice", HasBet: true, Connected: true, Wallet: w, Wager: Wager{Total: 10}}, hands: []*blackjackHand{{bet: 10, cards: []card{{rank: "10"}, {rank: "8"}}}}, }) table.dealer.cards = []card{{rank: "K"}, {rank: "A"}} table.phase = blackjackInsurance rows := table.wagers("alice") if len(rows) != 2 || rows[0].Bet != "insurance" || rows[1].Bet != "decline" { t.Fatalf("insurance rows=%+v", rows) } if rows[0].Payout != "2:1" || rows[0].Win != "Covers dealer blackjack; the stake costs 5" { t.Fatalf("insurance wording=%+v", rows[0]) } // A turn with a splittable pair and surrender available lists both // wagers; a hit/stand-only hand lists none. table.phase = blackjackPlaying table.activePlayer = 0 table.activeHand = 0 table.players.get("alice").hands = []*blackjackHand{{bet: 10, cards: []card{{rank: "8"}, {rank: "8"}}}} table.dealer.cards = []card{{rank: "K"}, {rank: "7"}} surrender := true table.Rules.Surrender = &surrender if rows := table.wagers("alice"); len(rows) == 0 { t.Fatal("turn rows missing") } table.Rules.Surrender = nil table.players.get("alice").hands = []*blackjackHand{{bet: 10, cards: []card{{rank: "K"}, {rank: "6"}}}} rows = table.wagers("alice") if len(rows) != 3 || rows[0].Bet != "hit" || rows[2].Bet != "double" { t.Fatalf("plain hand rows=%+v", rows) } } // The betting phase has exactly one wager: no rows, and no "list" hint. func TestBlackjackBettingPhaseHidesList(t *testing.T) { table := newBlackjackTable(1, TableConfig{ID: "blackjack", Game: GameBlackjack, BettingTicks: 10}, newTestRand()) table.join("a") hints := table.hints("a") for _, c := range hints { if c.Command == "list" { t.Fatal("list advertised with a single wager", hints) } if c.Command != "rules" { continue } } foundRules := false for _, c := range hints { if c.Command == "rules" { foundRules = true } } if !foundRules { t.Fatal("rules hint missing", hints) } } // Craps variants that take one target (pass only) never advertise "list". func TestCrapsSingleBetVariantsHideList(t *testing.T) { for _, v := range []string{"simplified", "high_point", "die_rich"} { tb := variantFixture(v) tb.join("a") for _, c := range tb.hints("a") { if c.Command == "list" { t.Fatal(v, "list advertised for a single-bet variant") } if c.Command == "rules" { break } } } } // Multi-bet variants advertise the "list" hint at every phase. func TestCrapsMultiBetVariantsAdvertiseList(t *testing.T) { for _, v := range []string{"bank", "crapless", "new_york", "diceless"} { tb := variantFixture(v) tb.join("a") found := false for _, c := range tb.hints("a") { if c.Command == "list" { found = true } } if !found { t.Fatal(v, "list hint missing", tb.hints("a")) } } }