aboutsummaryrefslogtreecommitdiff
path: root/internal/game/render_big_six.go
blob: 19579f0dfe10454b5b3a1f618bdfda16927ada28 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/casino"
	"thehouseoficarus/internal/color"
)

func bigSixInk(mode, label, text string, dim bool) string {
	fg := 2
	switch label {
	case "2":
		fg = 6
	case "5":
		fg = 4
	case "10":
		fg = 5
	case "20":
		fg = 3
	case "SWORD":
		fg = 15
	case "SHIELD":
		fg = 6
	case "DOUBLE":
		fg = 11
	}
	return color.Render(mode, color.ColorSpec{Fg: fg, Bg: -1, Bold: !dim, Dim: dim}, text)
}
func bigSixLabel(s string) string {
	if s == "SWORD" || s == "SHIELD" || s == "DOUBLE" {
		return s
	}
	return "$" + s
}

func bigSixPanel(spot casino.BigSixSpot, width int, mode string, unicode bool) []string {
	b := rouletteBorders(unicode)
	label := bigSixLabel(spot.Label)
	art := []string{"$             $", ".--------.", "|" + rouletteCenter(label, 8) + "|", "'--------'", "$             $"}
	if unicode {
		art = []string{"$             $", "╭────────╮", "│" + rouletteCenter(label, 8) + "│", "╰────────╯", "$             $"}
	}
	switch spot.Label {
	case "SWORD":
		// Two full blade rows below the tip; the guard sits just above the grip.
		art = []string{"/\\", "||", "||", "===++===", "()"}
		if unicode {
			art = []string{"▲", "║", "║", "╘══╬══╛", "╩"}
		}
	case "SHIELD":
		art = []string{".--------.", "|   /\\   |", "|   \\/   |", "\\        /", "'------'"}
		if unicode {
			// Keep a fixed-width canvas: centering each tapered row separately
			// would shift the corners apart and break the shield's outline.
			art = []string{"╭───────╮", "│   ◇   │", "╰╮     ╭╯", " ╰╮   ╭╯ ", "  ╰───╯  "}
		}
	}
	lines := []string{b.tl + strings.Repeat(b.h, width) + b.tr, b.v + rouletteCenter(label, width) + b.v}
	for _, a := range art {
		lines = append(lines, b.v+rouletteCenter(a, width)+b.v)
	}
	lines = append(lines, b.bl+strings.Repeat(b.h, width)+b.br)
	// The payout text is dim, but its box walls keep the same bold weight as
	// the rest of the panel; otherwise the row's verticals look thin.
	wall := bigSixInk(mode, spot.Label, b.v, false)
	oddsLine := wall + bigSixInk(mode, spot.Label, rouletteCenter(fmt.Sprintf("pays %d:1", spot.Pays), width), true) + wall
	lines = append(lines[:len(lines)-1], oddsLine, lines[len(lines)-1])
	for i := range lines {
		if i == len(lines)-2 {
			continue // oddsLine is already colored: bold walls, dim payout
		}
		lines[i] = bigSixInk(mode, spot.Label, lines[i], false)
	}
	return lines
}

// Self-contained scrollback art, always within 80 columns. The last two
// betting panels expand into the space formerly occupied by DOUBLE; DOUBLE
// is an automatic feature, advertised in a shallow full-width banner instead.
func renderBigSixSnapshot(s *casino.BigSixSnapshot, mode string, unicode bool) string {
	if len(s.Pockets) > 0 {
		return renderBigSixStrip(s, mode, unicode)
	}
	if s.Phase == "playing" {
		return "Big 6 wheel spinning | live stakes " + s.Multiplier + "x"
	}
	var out strings.Builder
	spots := casino.BigSixSpots()
	for _, row := range [][]casino.BigSixSpot{spots[:4], spots[4:7]} {
		var panels [][]string
		for _, spot := range row {
			width := 15
			if spot.Label == "SWORD" || spot.Label == "SHIELD" {
				width = 24
			}
			panels = append(panels, bigSixPanel(spot, width, mode, unicode))
		}
		for line := range panels[0] {
			out.WriteString("  ")
			for col, panel := range panels {
				if col > 0 {
					out.WriteByte(' ')
				}
				out.WriteString(panel[line])
			}
			out.WriteByte('\n')
		}
	}
	b := rouletteBorders(unicode)
	const bannerWidth = 69 // 71 columns including borders, like both betting rows.
	banner := []string{
		b.tl + strings.Repeat(b.h, bannerWidth) + b.tr,
		b.v + rouletteCenter("DOUBLE", bannerWidth) + b.v,
		b.v + rouletteCenter("Every live bet doubles and the wheel spins again", bannerWidth) + b.v,
		b.v + rouletteCenter("Double again. And again. No cap.", bannerWidth) + b.v,
		b.bl + strings.Repeat(b.h, bannerWidth) + b.br,
	}
	for _, line := range banner {
		out.WriteString("  " + bigSixInk(mode, "DOUBLE", line, false) + "\n")
	}
	fmt.Fprintf(&out, "  Bets: %s", betLimitsText(s.MinBet, s.MaxBet))
	return out.String()
}

func renderBigSixStrip(s *casino.BigSixSnapshot, mode string, unicode bool) string {
	result := s.Phase == "result"
	width := 6
	if result {
		width = 7
	}
	n := len(s.Pockets)
	center := n / 2
	pointer := 1 + center*(width+1) + width/2
	b := rouletteBorders(unicode)
	wall := "|"
	if unicode {
		wall = "│"
	}
	// Every rail and separator on the wheel uses the same dim-yellow border
	// ink; the per-pocket colors paint only the interiors.
	borderInk := func(text string) string { return bigSixInk(mode, "20", text, true) }
	var out strings.Builder
	tip := "\\/"
	if unicode {
		tip = "▼"
	}
	// No leading/trailing newline: WriteLine supplies the sole frame separator.
	out.WriteString(strings.Repeat(" ", pointer) + bigSixInk(mode, "DOUBLE", tip, false) + "\n")
	top := b.tl + strings.Repeat(strings.Repeat(b.h, width)+b.teeTop, n-1) + strings.Repeat(b.h, width) + b.tr
	bottom := b.bl + strings.Repeat(strings.Repeat(b.h, width)+b.teeBottom, n-1) + strings.Repeat(b.h, width) + b.br
	out.WriteString(borderInk(top) + "\n")
	rows := 3
	if result {
		rows = 4
	}
	for row := 0; row < rows; row++ {
		out.WriteString(borderInk(b.v))
		for i, pocket := range s.Pockets {
			label := bigSixLabel(pocket)
			var art []string
			if result {
				// The bill's side walls continue through the number row so the
				// outline stays complete once the wheel stops.
				art = []string{".-----.", "|  $  |", wall + rouletteCenter(label, 5) + wall, "'-----'"}
				if unicode {
					art = []string{"╭─────╮", "│  $  │", wall + rouletteCenter(label, 5) + wall, "╰─────╯"}
				}
				switch pocket {
				case "SWORD":
					art = []string{"/\\", "||", "--+--", label}
					if unicode {
						art = []string{"▲", "╘═╬═╛", "╩", label}
					}
				case "SHIELD":
					art = []string{"/---\\", "| + |", "\\___/", label}
					if unicode {
						art = []string{"╭─────╮", "╰╮ ◇ ╭╯", " ╰───╯ ", label}
					}
				case "DOUBLE":
					art = []string{"", "x 2", label, "RESPIN"}
					if unicode {
						art[1] = "× 2"
					}
				}
			} else {
				// Only the dollar symbols are drawn as banknotes; the logo and
				// DOUBLE spaces show their name without the bill walls.
				art = []string{".----.", wall + rouletteCenter(label, 4) + wall, "'----'"}
				if unicode {
					art = []string{"╭────╮", wall + rouletteCenter(label, 4) + wall, "╰────╯"}
				}
				switch pocket {
				case "SWORD", "SHIELD", "DOUBLE":
					art = []string{"", label, ""}
				}
			}
			out.WriteString(bigSixInk(mode, pocket, rouletteCenter(art[row], width), result && i != center))
			out.WriteString(borderInk(b.v))
		}
		out.WriteByte('\n')
	}
	out.WriteString(borderInk(bottom))
	if result {
		out.WriteString("\n" + strings.Repeat(" ", pointer-3) + bigSixInk(mode, s.Pockets[center], "WINNER", false))
	}
	return out.String()
}