package game import ( "fmt" "strings" "testing" "thehouseoficarus/internal/cardart" "thehouseoficarus/internal/casino" "thehouseoficarus/internal/color" ) // Pip art from data/cards.yaml is shared by every game. In the light card // style its dark box frame must still give way to the half-block edges that // meet the white body, or the top and bottom rows look like the dark style. func TestPokerLightStyleUsesHalfBlockEdgesForPipArt(t *testing.T) { store := cardart.Load("../../data/cards.yaml") cards := []casino.CardView{{Rank: "K", Suit: "spades"}} for _, size := range []int{7, 9} { lines := renderPokerCards(cards, nil, "none", true, size, "light", store) if len(lines) != size { t.Fatalf("size %d: got %d lines", size, len(lines)) } top, bottom := strings.TrimSpace(lines[0]), strings.TrimSpace(lines[size-1]) if top != strings.Repeat("▄", size) || bottom != strings.Repeat("▀", size) { t.Fatalf("size %d: light edges are not half blocks: top=%q bottom=%q", size, top, bottom) } } } func TestPokerPayTableBordersPaletteAndColumns(t *testing.T) { for _, cabinet := range []string{casino.CabinetClassic, casino.CabinetUXSingle, casino.CabinetUXMulti} { cfg := (casino.VideoPokerConfig{Cabinet: cabinet, Variant: "double_double_bonus"}).Normalize() snap := &casino.VideoPokerSnapshot{Config: cfg, Coins: 3, Hands: 3, Denomination: 10} panel := renderPokerPayTable(snap, "xterm256") for _, want := range []string{"┌", "┬", "┐", "│", "└", "┴", "┘", "....", "4000", "COINS PER HAND"} { if !strings.Contains(panel, want) { t.Fatalf("panel missing %q: %s", want, panel) } } for _, seq := range []string{fmt.Sprintf("38;5;%d", pokerYellow), fmt.Sprintf("48;5;%d", pokerBlue), fmt.Sprintf("48;5;%d", pokerRed)} { if !strings.Contains(panel, seq) { t.Fatalf("missing palette %s", seq) } } width := -1 for _, line := range strings.Split(stripANSI(panel), "\n") { if !strings.HasPrefix(line, "│") && !strings.HasPrefix(line, "┌") && !strings.HasPrefix(line, "├") && !strings.HasPrefix(line, "└") { continue } if width < 0 { width = color.VisibleLen(line) } if color.VisibleLen(line) != width { t.Fatalf("unaligned pay table: %q (%d != %d)", line, color.VisibleLen(line), width) } if strings.HasPrefix(line, "│") { cells := strings.Split(line, "│") want := 8 if cabinet != casino.CabinetClassic { want = 9 } if len(cells) != want { t.Fatalf("bad column count %d: %s", len(cells), line) } } } if cabinet != casino.CabinetClassic && strings.Count(stripANSI(panel), "NEXT X") != 1 { t.Fatal("missing/duplicate next award heading") } plain := renderPokerPayTable(snap, "none") if strings.Contains(plain, "\x1b") { t.Fatal("plain display contains escapes") } } } func TestPokerResultsBelowCardsAndHoldStyle(t *testing.T) { cards := []casino.CardView{{Rank: "A", Suit: "hearts"}, {Rank: "K", Suit: "hearts"}, {Rank: "Q", Suit: "hearts"}, {Rank: "J", Suit: "hearts"}, {Rank: "10", Suit: "hearts"}} cfg := (casino.VideoPokerConfig{Cabinet: casino.CabinetClassic}).Normalize() for _, hands := range []int{1, 3, 100} { for _, win := range []bool{false, true} { line := casino.PokerLine{Cards: cards, Category: "No win", Multiplier: 1} fg, text := 15, "No win" if win { line.Category = "Royal flush" line.Coins = 4000 fg = pokerYellow text = "Royal flush" } snap := &casino.VideoPokerSnapshot{Config: cfg, Hands: hands, Lines: []casino.PokerLine{line}, Multiplier: 1} out := renderVideoPoker(snap, "xterm256", true, 7, "", nil) styled := color.Render("xterm256", color.ColorSpec{Fg: fg, Bg: -1, Bold: true}, text) if !strings.Contains(out, styled) { t.Fatalf("missing result styling: %q", out) } plain := stripANSI(out) if strings.Contains(plain, "CLASSIC") { t.Fatalf("classic badge leaked into output: %s", plain) } result := strings.Index(plain, text) // The result starts its own line and follows the card/badge line. if result < 0 || result == 0 || plain[result-1] != '\n' { t.Fatalf("result not below cards: %s", plain) } if hands == 100 && !strings.Contains(plain, "♥") { t.Fatal("hundred-play missing compact Unicode suits") } } } held := [5]bool{true, false, true, false, true} art := strings.Join(renderPokerCards(cards, &held, "xterm256", true, 5, "", nil), "\n") for _, n := range []int{1, 3, 5} { if !strings.Contains(art, color.Render("xterm256", color.ColorSpec{Fg: pokerYellow, Bg: -1, Bold: true}, fmt.Sprintf("%d HELD", n))) { t.Fatal("HELD not bold yellow") } } } func TestPokerDrawShortcutLeavesDownAlone(t *testing.T) { g, sess, conn := casinoCrapsGame(t, "name: Poker\ncasino_tables:\n - id: vp\n game: video_poker\n") g.executeCommand(sess, "d", nil, "d") if !strings.Contains(string(conn.data), "You can't go that way.") { t.Fatalf("d did not route down outside poker: %s", conn.data) } g.executePlay(sess, []string{"vp"}, "play vp") g.executeBet(sess, nil, "bet") g.executeTableAction(sess, "deal") conn.data = nil g.executeCommand(sess, "d", nil, "d") if len(sess.Player.PendingWagers) != 0 || strings.Contains(string(conn.data), "You can't go that way.") { t.Fatal("seated d did not settle the hand") } }