aboutsummaryrefslogtreecommitdiff
path: root/internal/game/video_poker_render_test.go
blob: 8195e216ff1019bfa459b99e8595159df1f6b860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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 = "WIN: Royal flush — 4000 coins"
			}
			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")
	}
}