aboutsummaryrefslogtreecommitdiff
path: root/internal/game/crazy_time_test.go
blob: 2c078625f2fd8d778766c229df518932dd0514f8 (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
package game

import (
	"strings"
	"testing"

	"thehouseoficarus/internal/casino"
)

func crazyTimeRoom() string {
	return "name: Crazy Time Coliseum\ncasino_tables:\n  - id: crazy_time\n    game: crazy_time\n    min_bet: 1\n    max_bet: 1000\n"
}

func TestCrazyTimePlayAliasAndMenu(t *testing.T) {
	g, s, conn := casinoCrapsGame(t, crazyTimeRoom())
	s.Player.Options = map[string]any{"color": "none", "casino_hints": "on"}
	g.executePlay(s, []string{"crazy", "time"}, "play crazy time")
	table, ok := g.Casino.Participation(s.Player.Name)
	if !ok || table == nil || table.Config.Game != casino.GameCrazyTime {
		t.Fatal("Crazy Time alias did not seat the player")
	}
	text := stripANSI(string(conn.data))
	if !strings.Contains(text, "CRAZY TIME") {
		t.Fatalf("join output missing the game: %q", text)
	}
	if !strings.Contains(text, "bet N on BET") {
		t.Fatalf("join output missing the bet hint: %q", text)
	}
	if !strings.Contains(text, "98") {
		t.Fatalf("join output missing the RTP: %q", text)
	}
	conn.data = nil
	g.executeRules(s, nil, "rules")
	if help := stripANSI(string(conn.data)); !strings.Contains(help, "CRAZY TIME") || !strings.Contains(help, "TOP SLOT") {
		t.Fatalf("rules did not open the Crazy Time page: %q", help)
	}
}

func TestCrazyTimeListCommand(t *testing.T) {
	g, s, conn := casinoCrapsGame(t, crazyTimeRoom())
	s.Player.Options = map[string]any{"color": "none"}
	g.executePlay(s, []string{"crazy time"}, "play crazy time")
	conn.data = nil
	g.executeList(s, nil, "list")
	text := stripANSI(string(conn.data))
	for _, want := range []string{"COIN FLIP", "CASH HUNT", "PACHINKO", "CRAZY TIME", "ALL"} {
		if !strings.Contains(text, want) {
			t.Fatalf("list missing %s: %q", want, text)
		}
	}
}

func TestCrazyTimePlayAndSpin(t *testing.T) {
	g, s, conn := casinoCrapsGame(t, crazyTimeRoom())
	s.Player.Options = map[string]any{"color": "none", "casino_hints": "on"}
	g.executePlay(s, []string{"crazy time"}, "play crazy time")
	conn.data = nil
	g.executeBet(s, []string{"5", "on", "cash", "hunt"}, "bet 5 on cash hunt")
	if len(s.Player.PendingWagers) != 1 {
		t.Fatalf("bet not committed: %+v", s.Player.PendingWagers)
	}
	if !strings.Contains(stripANSI(string(conn.data)), "CASH HUNT") {
		t.Fatalf("bet confirmation missing the target: %q", conn.data)
	}
	// Spin and drive the whole round (main wheel plus any bonus) to a receipt.
	conn.data = nil
	g.executeTableAction(s, "spin")
	for i := 0; i < 2000 && len(s.Player.PendingWagers) > 0; i++ {
		g.CasinoTick()
	}
	if len(s.Player.PendingWagers) != 0 {
		t.Fatalf("round never settled: %+v", s.Player.PendingWagers)
	}
}

func TestCrazyTimeRendering(t *testing.T) {
	for _, mode := range []string{"none", "ansi", "xterm256"} {
		for _, unicode := range []bool{false, true} {
			wheel := &casino.CrazyTimeSnapshot{
				Phase:     "result",
				Pockets:   []string{"1", "2", "5", "10", "COIN FLIP", "CASH HUNT", "PACHINKO", "CRAZY TIME", "1", "2", "5"},
				TopSymbol: "CASH HUNT",
				TopMult:   5,
			}
			rendered := renderCrazyTime(wheel, mode, unicode, false, 0)
			if mode == "none" && strings.Contains(rendered, "\x1b") {
				t.Fatalf("plain wheel has ANSI escapes: %q", rendered)
			}
			plain := stripANSI(rendered)
			if !strings.Contains(plain, "CASH") || !strings.Contains(plain, "x5") {
				t.Fatalf("wheel missing symbol/top multiplier: %q", plain)
			}

			bonus := &casino.CrazyTimeSnapshot{
				Phase: "bonus",
				Bonus: &casino.CrazyTimeBonusView{
					Kind:         casino.CrazyTimeBonusPachinko,
					Phase:        "result",
					PachoPockets: []int{10, 20, -1, 5, 50, 100, 25, 15, 7, 10, 20, 5, 50, 100, 25, 15},
					PachoRow:     16,
					PachoLane:    4,
				},
			}
			rendered = renderCrazyTime(bonus, mode, unicode, false, 0)
			if plain := stripANSI(rendered); !strings.Contains(plain, "DBL") || !strings.Contains(plain, "100") {
				t.Fatalf("pachinko bonus missing prizes: %q", plain)
			}

			coin := &casino.CrazyTimeSnapshot{
				Phase: "bonus",
				Bonus: &casino.CrazyTimeBonusView{Kind: casino.CrazyTimeBonusCoinFlip, Phase: "result", CoinLow: 3, CoinHigh: 25, CoinSide: "blue", CoinValue: 25, CoinResult: true},
			}
			if plain := stripANSI(renderCrazyTime(coin, mode, unicode, false, 0)); !strings.Contains(plain, "25x") {
				t.Fatalf("coin flip bonus missing value: %q", plain)
			}

			hunt := &casino.CrazyTimeSnapshot{
				Phase: "bonus",
				Bonus: &casino.CrazyTimeBonusView{Kind: casino.CrazyTimeBonusCashHunt, Phase: "result", HuntFinal: []int{2, 5, 10, 25, 50, 100, 500, 15, 20, 2, 5, 10}, HuntPick: 3},
			}
			if plain := stripANSI(renderCrazyTime(hunt, mode, unicode, false, 0)); !strings.Contains(plain, "TILE 4") {
				t.Fatalf("cash hunt bonus missing the pick: %q", plain)
			}

			ct := &casino.CrazyTimeSnapshot{
				Phase: "bonus",
				Bonus: &casino.CrazyTimeBonusView{
					Kind:     casino.CrazyTimeBonusWheel,
					Phase:    "result",
					CTWheel:  []int{10, 15, 20, 25, 50, 100, -1, 10, 15, 20, 25, 50, 100, 10, 15},
					CTOffset: 0,
					CTPick:   1,
					CTResult: true,
					CTValue:  25,
				},
			}
			if plain := stripANSI(renderCrazyTime(ct, mode, unicode, false, 0)); !strings.Contains(plain, "POINTER") {
				t.Fatalf("crazy wheel bonus missing the result: %q", plain)
			}
		}
	}
}

func TestCrazyTimeBlockedVerbsDoNotLeak(t *testing.T) {
	g, s, _ := casinoCrapsGame(t, crazyTimeRoom())
	s.Player.Options = map[string]any{"color": "none"}
	g.executePlay(s, []string{"crazy time"}, "play crazy time")
	// "sp" must abbreviate to spin, not split (blackjack) or an unknown verb.
	got, ok := g.casinoAbbreviation(s, "sp")
	if !ok || got != "spin" {
		t.Fatalf("sp resolved to %q,%v; want spin", got, ok)
	}
}

func TestCrazyTimeBetOmitsBalanceAndResultShowsItOnce(t *testing.T) {
	g, s, conn := casinoCrapsGame(t, crazyTimeRoom())
	s.Player.Options = map[string]any{"color": "none", "casino_hints": "on"}
	g.executePlay(s, []string{"crazy time"}, "play crazy time")
	conn.data = nil
	g.executeBet(s, []string{"5", "on", "all"}, "bet 5 on all")
	out := stripANSI(string(conn.data))
	if strings.Contains(out, "Available") {
		t.Fatalf("bet printed the wallet: %q", out)
	}
	if !strings.Contains(out, "all four minigames") {
		t.Fatalf("ALL bet not confirmed: %q", out)
	}
	conn.data = nil
	g.executeTableAction(s, "spin")
	for i := 0; i < 3000 && len(s.Player.PendingWagers) > 0; i++ {
		g.CasinoTick()
	}
	if len(s.Player.PendingWagers) != 0 {
		t.Fatal("round never settled")
	}
	out = stripANSI(string(conn.data))
	if got := strings.Count(out, "Available "); got != 1 {
		t.Fatalf("result printed the wallet %d times, want 1: %q", got, out)
	}
}

func TestCrazyTimeTopSlotOnlyOnResult(t *testing.T) {
	pockets := []string{"1", "2", "5", "10", "COIN FLIP", "CASH HUNT", "PACHINKO", "CRAZY TIME", "1", "2", "5"}
	spin := &casino.CrazyTimeSnapshot{Phase: "spinning", Pockets: pockets, TopSymbol: "CASH HUNT", TopMult: 5}
	if plain := stripANSI(renderCrazyTime(spin, "none", false, false, 0)); strings.Contains(plain, "TOP SLOT") {
		t.Fatalf("spinning wheel printed TOP SLOT: %q", plain)
	}
	result := &casino.CrazyTimeSnapshot{Phase: "result", Pockets: pockets, TopSymbol: "CASH HUNT", TopMult: 5}
	plain := stripANSI(renderCrazyTime(result, "none", false, false, 0))
	if !strings.Contains(plain, "TOP SLOT") || !strings.Contains(plain, "x5") {
		t.Fatalf("result wheel omitted the Top Slot: %q", plain)
	}
}