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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
package casino
import (
"math"
"math/rand"
"strings"
"testing"
)
func newCrazyTimeTest() *crazyTimeTable {
return newCrazyTimeTable(1, TableConfig{ID: "crazy", Game: GameCrazyTime, MinBet: 1, MaxBet: 100000}, rand.New(rand.NewSource(99)))
}
func TestCrazyTimeRegistrationAndRTP(t *testing.T) {
cfg := TableConfig{ID: "crazy", Game: GameCrazyTime}
if err := cfg.Validate(); err != nil {
t.Fatal(err)
}
if cfg.Normalize().MaxPlayers != 1 {
t.Fatal("crazy time must be single-seat")
}
if cfg.HelpTopic() != "crazy time" {
t.Fatalf("help topic %q", cfg.HelpTopic())
}
if newTable(1, cfg, newTestRand()) == nil {
t.Fatal("registration failed")
}
for _, spot := range crazyTimeSpots() {
rtp := crazyTimeRTPTargetFor(spot.Label)
if math.Abs(rtp-crazyTimeRTPTarget) > 1e-9 {
t.Fatalf("%s RTP = %.12f, want %.12f", spot.Label, rtp, crazyTimeRTPTarget)
}
e := cfg.HouseEdge(spot.Label)
if len(e.Parts) != 1 || math.Abs(e.Parts[0].Loss-(1-crazyTimeRTPTarget)) > 1e-9 {
t.Fatalf("%s edge %+v", spot.Label, e)
}
dist := crazyTimeTopDists[spot.Label]
if dist.total <= 0 {
t.Fatalf("%s empty top dist", spot.Label)
}
for _, w := range dist.weights {
if w < 0 {
t.Fatalf("%s negative weight", spot.Label)
}
}
mean := 0.0
for i, w := range dist.weights {
mean += float64(dist.values[i]) * w
}
mean /= dist.total
if math.Abs(mean-crazyTimeTopTarget(spot.Label)) > 1e-9 {
t.Fatalf("%s top mean %.9f target %.9f", spot.Label, mean, crazyTimeTopTarget(spot.Label))
}
}
}
func TestCrazyTimeWheelCountsAndPositiveBonuses(t *testing.T) {
counts := map[string]int{}
for _, s := range crazyTimeWheel {
counts[s]++
}
if len(crazyTimeWheel) != crazyTimePockets {
t.Fatalf("wheel has %d pockets", len(crazyTimeWheel))
}
total := 0
for _, spot := range crazyTimeSpots() {
if counts[spot.Label] != spot.Count {
t.Fatalf("%s count %d want %d", spot.Label, counts[spot.Label], spot.Count)
}
total += spot.Count
}
if total != crazyTimePockets {
t.Fatalf("counts sum to %d", total)
}
// Every bonus distribution is strictly positive.
for _, v := range ctHuntValues {
if v < 1 {
t.Fatalf("cash hunt value %d is not positive", v)
}
}
for _, v := range ctPachinkoValues {
if v < 1 {
t.Fatalf("pachinko value %d is not positive", v)
}
}
for _, v := range ctCoinLowValues {
if v < 1 {
t.Fatalf("coin low value %d is not positive", v)
}
}
for _, v := range ctCoinHighValues {
if v < 1 {
t.Fatalf("coin high value %d is not positive", v)
}
}
for _, v := range ctBonusWheelValues {
if v < 1 {
t.Fatalf("crazy wheel value %d is not positive", v)
}
}
}
func TestCrazyTimeBetSpinSettle(t *testing.T) {
table := newCrazyTimeTest()
w := &recordingWallet{testWallet: testWallet{credits: 1000}}
table.join("a")
table.bet("a", "1", 10, w)
table.bet("a", "crazy time", 5, w)
if len(table.bets) != 2 || len(w.open) != 2 {
t.Fatalf("bets not committed: %+v open=%d", table.bets, len(w.open))
}
// Capture the fixed outcome before the wheel settles and resets it.
table.topSymbol, table.topMult = "2", 7
events := table.action("a", "spin")
if table.phase != ctSpinning || len(events) == 0 {
t.Fatal("spin did not start")
}
win := table.winSymbol
topSymbol, topMult := table.topSymbol, table.topMult
if win == "" {
t.Fatal("no winning symbol")
}
// Drive the wheel to completion.
for i := 0; i < 400 && table.phase == ctSpinning; i++ {
table.tick()
}
// A bonus may still be animating; drive it out too.
for i := 0; i < 1000 && table.phase == ctBonusing; i++ {
table.tick()
}
mult := 1
if topSymbol == win {
mult = topMult
}
want := 0
if win == "1" {
want += 10 * 2 * mult
}
if win == "CRAZY TIME" {
want += 5 * table.bonusValue * mult
}
if w.paid != want {
t.Fatalf("paid %d want %d (win=%s top=%s x%d)", w.paid, want, win, topSymbol, topMult)
}
if len(w.open) != 0 {
t.Fatalf("stakes left open: %d", len(w.open))
}
}
func TestCrazyTimeAllBonusesOnlyPayPositive(t *testing.T) {
for _, kind := range []string{ctBonusCoinFlip, ctBonusCashHunt, ctBonusPachinko, ctBonusWheel} {
for seed := int64(0); seed < 40; seed++ {
table := newCrazyTimeTable(1, TableConfig{ID: "c", Game: GameCrazyTime, MinBet: 1, MaxBet: 100000}, rand.New(rand.NewSource(seed+1)))
table.name = "a"
table.phase = ctBonusing
table.winSymbol = labelForBonus(kind)
table.topSymbol, table.topMult = "10", 1
switch kind {
case ctBonusCoinFlip:
table.buildCoinFlipLocked()
case ctBonusCashHunt:
table.buildCashHuntLocked()
case ctBonusPachinko:
table.buildPachinkoLocked()
case ctBonusWheel:
table.buildBonusWheelLocked()
}
if table.bonusValue < 1 {
t.Fatalf("%s produced %d", kind, table.bonusValue)
}
if len(table.prints) == 0 {
t.Fatalf("%s produced no frames", kind)
}
}
}
}
func labelForBonus(kind string) string {
for _, s := range crazyTimeSpots() {
if s.Bonus == kind {
return s.Label
}
}
return ""
}
func TestCrazyTimeUnbetRefunds(t *testing.T) {
table := newCrazyTimeTest()
w := &testWallet{credits: 100}
table.join("a")
table.bet("a", "5", 10, w)
if w.credits != 90 {
t.Fatalf("stake not debited: %d", w.credits)
}
table.action("a", "unbet")
if w.paid != 10 || len(w.open) != 0 {
t.Fatalf("unbet did not refund: paid=%d open=%d", w.paid, len(w.open))
}
}
func TestCrazyTimeAllBetAndRebet(t *testing.T) {
table := newCrazyTimeTest()
w := &testWallet{credits: 1000}
table.join("a")
events := table.bet("a", "all", 10, w)
if len(table.bets) != 4 {
t.Fatalf("ALL placed %d wagers, want 4", len(table.bets))
}
if w.credits != 960 || len(w.open) != 4 {
t.Fatalf("ALL debit: credits=%d open=%d", w.credits, len(w.open))
}
for _, e := range events {
if e.Menu != nil {
t.Fatalf("bet returned a menu (wallet would print): %+v", e)
}
}
// Settle on a losing number, then rebet every remembered minigame wager.
table.winSymbol = "10"
table.topSymbol, table.topMult = "1", 1
table.settleLocked()
if len(table.bets) != 0 {
t.Fatal("settlement did not clear the round")
}
before := w.credits
events = table.rebetAll("a", w)
if len(table.bets) != 4 {
t.Fatalf("rebet placed %d wagers, want 4", len(table.bets))
}
if w.credits != before-40 {
t.Fatalf("rebet debit: credits=%d want %d", w.credits, before-40)
}
for _, e := range events {
if e.Menu != nil {
t.Fatalf("rebet returned a menu: %+v", e)
}
}
}
func TestCrazyTimeResolveSpot(t *testing.T) {
cases := map[string]string{
"1": "1", "2": "2", "5": "5", "10": "10",
"co": "COIN FLIP", "coin flip": "COIN FLIP", "coinflip": "COIN FLIP",
"ca": "CASH HUNT", "cash hunt": "CASH HUNT",
"p": "PACHINKO", "pach": "PACHINKO",
"cr": "CRAZY TIME", "crazy time": "CRAZY TIME",
}
for in, want := range cases {
got, ok := crazyTimeResolveSpot(in)
if !ok || got != want {
t.Fatalf("%q -> %q,%v want %q", in, got, ok, want)
}
}
if _, ok := crazyTimeResolveSpot("c"); ok {
t.Fatal("ambiguous c should not resolve")
}
}
func TestCrazyTimeRulesText(t *testing.T) {
rules := crazyTimeRules(TableConfig{})
if !strings.Contains(rules, "98%") || strings.Contains(rules, "%%") {
t.Fatalf("rules text: %q", rules)
}
if !strings.Contains(rules, "CASH HUNT") || !strings.Contains(rules, "Top Slot") {
t.Fatalf("rules text missing content: %q", rules)
}
}
// TestCrazyTimeSettlementMath pins the payout arithmetic: a winning target
// pays stake * total-return-multiplier * Top Slot multiplier, and a losing
// target returns nothing.
func TestCrazyTimeSettlementMath(t *testing.T) {
cases := []struct {
spot, win, topSym string
bonus, topMult int
stake, want int
}{
{"1", "1", "1", 0, 5, 10, 10 * 2 * 5},
{"1", "10", "1", 0, 5, 10, 0},
{"CASH HUNT", "CASH HUNT", "CASH HUNT", 3, 4, 7, 7 * 3 * 4},
{"CASH HUNT", "CASH HUNT", "COIN FLIP", 500, 9, 2, 2 * 500},
{"CRAZY TIME", "CRAZY TIME", "CRAZY TIME", 64, 50, 1, 64 * 50},
}
for _, tc := range cases {
table := newCrazyTimeTable(1, TableConfig{ID: "c", Game: GameCrazyTime, MinBet: 1, MaxBet: 100000}, rand.New(rand.NewSource(3)))
w := &testWallet{credits: MaxCredits / 2}
table.name = "a"
table.wallet = w
wager, err := w.Wager(tc.stake)
if err != nil {
t.Fatal(err)
}
table.bets = []crazyTimeBet{{spot: tc.spot, wager: wager}}
table.winSymbol = tc.win
table.bonusValue = tc.bonus
table.topSymbol, table.topMult = tc.topSym, tc.topMult
before := w.paid
table.settleLocked()
if got := w.paid - before; got != tc.want {
t.Fatalf("%s win=%s bonus=%d top=%s x%d stake=%d paid %d want %d", tc.spot, tc.win, tc.bonus, tc.topSym, tc.topMult, tc.stake, got, tc.want)
}
}
}
func TestCrazyTimeSpinDelaysFirstMove(t *testing.T) {
table := newCrazyTimeTest()
w := &testWallet{credits: 1000}
table.join("a")
table.bet("a", "1", 10, w)
events := table.action("a", "spin")
if len(events) == 0 || events[0].Snapshot == nil {
t.Fatal("spin did not print the opening wheel")
}
// The spin command and the first engine tick share a cycle, so the opening
// position must survive that tick before the wheel advances.
if ev := table.tick(); len(ev) != 0 {
t.Fatalf("first tick advanced the wheel immediately: %+v", ev)
}
if ev := table.tick(); len(ev) == 0 {
t.Fatal("second tick did not advance the wheel")
}
}
|