diff options
Diffstat (limited to 'internal/casino')
| -rw-r--r-- | internal/casino/baccarat.go | 2 | ||||
| -rw-r--r-- | internal/casino/big_six.go | 530 | ||||
| -rw-r--r-- | internal/casino/big_six_test.go | 293 | ||||
| -rw-r--r-- | internal/casino/blackjack.go | 6 | ||||
| -rw-r--r-- | internal/casino/core.go | 3 | ||||
| -rw-r--r-- | internal/casino/craps_ux.go | 2 | ||||
| -rw-r--r-- | internal/casino/registry.go | 14 | ||||
| -rw-r--r-- | internal/casino/table_hints.go | 2 | ||||
| -rw-r--r-- | internal/casino/table_ux_test.go | 2 | ||||
| -rw-r--r-- | internal/casino/types.go | 1 |
10 files changed, 848 insertions, 7 deletions
diff --git a/internal/casino/baccarat.go b/internal/casino/baccarat.go index f1ba951..d385834 100644 --- a/internal/casino/baccarat.go +++ b/internal/casino/baccarat.go @@ -113,7 +113,7 @@ func (t *baccaratTable) menuEvent(name string) Event { } commands := []MenuCommand{} if p != nil && p.hasLastBet() { - commands = append(commands, MenuCommand{Command: "bet", Desc: "Repeat your last bets"}) + commands = append(commands, MenuCommand{Command: "bet / rebet", Desc: "Repeat your last bets"}) } if p != nil && len(p.sides) > 0 { commands = append(commands, MenuCommand{Command: "unbet", Desc: "Take back your side bets"}) diff --git a/internal/casino/big_six.go b/internal/casino/big_six.go new file mode 100644 index 0000000..6d16bbc --- /dev/null +++ b/internal/casino/big_six.go @@ -0,0 +1,530 @@ +package casino + +import ( + "fmt" + "math/big" + "math/rand" + "strings" +) + +// BigSixSpot describes a physical symbol and its profit odds. The dollar +// labels follow Draft Kings; counts and odds are adjusted for this house. +// Reference: https://wizardofodds.com/games/big-six/ (Draft Kings Rules). +type BigSixSpot struct { + Label string + Count, Pays int +} + +func BigSixSpots() []BigSixSpot { + return []BigSixSpot{ + {"1", 24, 1}, {"2", 12, 3}, {"5", 6, 7}, {"10", 4, 11}, {"20", 2, 23}, + {"SWORD", 1, 47}, {"SHIELD", 1, 47}, {"DOUBLE", 1, 0}, + } +} + +// Each ordinary symbol has count*(profit+1)=48. With N=51 and D=1, +// E = 48/51 + (2/51)*E = 48/49 = 97.95918367%, for EVERY target. +// DOUBLE is not a bet: it doubles all live stakes and spins again. No rounding. +func bigSixHouseEdge(_ TableConfig, bet string) HouseEdge { + if bigSixPayout(bet) > 0 { + return edge(1.0 / 49) + } + return unknownEdge("unrecognized Big 6 target") +} +func bigSixTarget(s string) string { + return strings.TrimPrefix(strings.ToUpper(strings.TrimSpace(s)), "$") +} +func bigSixPayout(s string) int { + for _, spot := range BigSixSpots() { + if spot.Label == bigSixTarget(s) && spot.Pays > 0 { + return spot.Pays + 1 + } + } + return 0 +} +func bigSixRules(TableConfig) string { + return "Big 6: bet on $1, $2, $5, $10, $20, SWORD or SHIELD. Profit odds: 1, 3, 7, 11, 23, 47, 47 to 1. DOUBLE doubles every live bet and respins without a cap. RTP 48/49 (97.959%). Alone, place any number of bets then spin; multiplayer betting lasts 25 ticks, even with no bets." +} + +// A fixed, interleaved physical wheel, never shuffled during a round. +var bigSixWheel = func() []string { + var wheel []string + for _, spot := range BigSixSpots() { + for i := 0; i < spot.Count; i++ { + wheel = append(wheel, spot.Label) + } + } + rand.New(rand.NewSource(601)).Shuffle(len(wheel), func(i, j int) { wheel[i], wheel[j] = wheel[j], wheel[i] }) + return wheel +}() + +type bigSixBet struct { + spot string + wager Wager +} +type bigSixPlayer struct { + Participant + bets []bigSixBet + lastSpot string + lastBet int +} + +func (p *bigSixPlayer) participantPtr() *Participant { return &p.Participant } + +type bigSixFrame struct{ delay, move int } +type bigSixTable struct { + tableCore[*bigSixPlayer] + rng *rand.Rand + frames []bigSixFrame + frame, wait, position, winningIndex int + // Arbitrary precision keeps DOUBLE chains uncapped and prevents wraparound. + multiplier big.Int + lastResult *BigSixSnapshot +} +type BigSixSnapshot struct { + Players []string + Phase string + Pockets []string + Multiplier string + BettingTicks int + MinBet, MaxBet int +} + +func (*BigSixSnapshot) snapshot() {} +func newBigSixTable(room int, cfg TableConfig, rng *rand.Rand) *bigSixTable { + t := &bigSixTable{tableCore: newTableCore[*bigSixPlayer](&tableBase{RoomID: room, Config: cfg.Normalize()}), rng: rng} + t.multiplier.SetInt64(1) + return t +} +func (t *bigSixTable) active() int { + n := 0 + for _, p := range t.players.ordered() { + if p.Connected && !p.SittingOut { + n++ + } + } + return n +} +func (t *bigSixTable) openRound() []Event { + if t.phase == phaseWaiting && t.active() > 1 { + t.phase = phaseBetting + t.window.open(25) + return []Event{t.event("Big 6 betting is open for 25 ticks.", true)} + } + return nil +} +func (t *bigSixTable) view() *BigSixSnapshot { + s := &BigSixSnapshot{Phase: string(t.phase), Multiplier: t.multiplier.String(), BettingTicks: t.window.timer.remaining(), MinBet: t.Config.MinBet, MaxBet: t.Config.MaxBet} + for _, p := range t.players.ordered() { + s.Players = append(s.Players, p.Name) + } + return s +} +func (t *bigSixTable) strip(result bool) *BigSixSnapshot { + s := t.view() + count := 11 + if result { + s.Phase = "result" + count = 9 + } + for i := 0; i < count; i++ { + s.Pockets = append(s.Pockets, bigSixWheel[(t.position+i-count/2+len(bigSixWheel))%len(bigSixWheel)]) + } + return s +} +func (t *bigSixTable) board(_ string) Snapshot { + t.mu.Lock() + defer t.mu.Unlock() + return t.view() +} +func (t *bigSixTable) wagerRows() []WagerRow { + if t.phase == phasePlaying { + return nil + } + var rows []WagerRow + for _, s := range BigSixSpots() { + if s.Pays > 0 { + rows = append(rows, WagerRow{Bet: s.Label, Payout: fmt.Sprintf("%d:1", s.Pays), Win: "Wheel stops on " + s.Label}) + } + } + return rows +} +func (t *bigSixTable) wagers(_ string) []WagerRow { + t.mu.Lock() + defer t.mu.Unlock() + return t.wagerRows() +} +func (t *bigSixTable) commands(name string) []MenuCommand { + var c []MenuCommand + if p := t.players.get(name); p != nil && t.phase != phasePlaying { + c = append(c, MenuCommand{Command: "bet N on BET", Desc: "Add a wager"}) + if p.lastBet > 0 { + c = append(c, MenuCommand{Command: "bet / rebet", Desc: "Repeat your last wager"}) + } + if p.HasBet { + c = append(c, MenuCommand{Command: "unbet", Desc: "Take back all wagers"}) + } + if t.phase == phaseWaiting { + c = append(c, MenuCommand{Command: "spin", Desc: "Start the wheel"}) + } + } + c = append(c, MenuCommand{Command: "table", Desc: "Show the felt"}, MenuCommand{Command: "stop", Desc: "Leave after your bets settle"}) + return withTableHints(c, t.wagerRows()) +} +func (t *bigSixTable) hints(name string) []MenuCommand { + t.mu.Lock() + defer t.mu.Unlock() + return t.commands(name) +} +func (t *bigSixTable) menu(name string, board bool) Event { + e := t.betMenuEvent(name, t.commands(name)) + if board { + e.Snapshot = t.view() + } + return e +} +func (t *bigSixTable) join(name string) []Event { + t.mu.Lock() + defer t.mu.Unlock() + if t.players.has(name) { + return []Event{t.menu(name, true)} + } + if t.players.count() >= t.Config.MaxPlayers { + return []Event{t.private(name, "The Big 6 table is full.")} + } + e := t.addSeatLocked(name, &bigSixPlayer{Participant: Participant{Name: name, Connected: true}}) + events := append([]Event{e}, t.openRound()...) + return append(events, t.menu(name, true)) +} +func (t *bigSixTable) leave(name string) []Event { + t.mu.Lock() + defer t.mu.Unlock() + p := t.players.get(name) + if p == nil { + return nil + } + if p.HasBet { + return []Event{t.private(name, "Your Big 6 wagers are committed until the round ends.")} + } + t.removeSeatLocked(name) + if t.players.count() == 0 { + t.reset() + } + return t.closeIfEmptyLocked([]Event{t.playerAction(name, name+" stands up.", "You stand up.")}) +} +func (t *bigSixTable) bet(name, spot string, amount int, w Wallet) []Event { + t.mu.Lock() + defer t.mu.Unlock() + p := t.players.get(name) + if p == nil { + return []Event{t.private(name, "You aren't playing Big 6.")} + } + if t.phase == phasePlaying { + return []Event{t.private(name, "No more bets! The wheel is spinning.")} + } + if spot == "" { + spot = p.lastSpot + } + spot = bigSixTarget(spot) + if bigSixPayout(spot) == 0 { + return []Event{t.private(name, "Bet on 1, 2, 5, 10, 20, SWORD or SHIELD. DOUBLE is automatic, not a bet.")} + } + if amount < t.Config.MinBet || amount > t.Config.MaxBet { + return []Event{t.private(name, "Big 6 bets must be "+betRangeText(t.Config.MinBet, t.Config.MaxBet)+".")} + } + // Keep the original aggregate representable for shared menus and refunds. + if amount > int(^uint(0)>>1)-p.Wager.Total { + return []Event{t.private(name, "Your total stake is too large.")} + } + wager, err := w.Wager(amount) + if err != nil { + return []Event{t.private(name, walletErrorMessage(err))} + } + p.bets = append(p.bets, bigSixBet{spot, wager}) + p.HasBet = true + p.Wallet = w + p.Wager.Total += amount + p.lastSpot, p.lastBet, p.SittingOut = spot, amount, false + events := []Event{t.playerAction(name, fmt.Sprintf("%s bets %d on %s.", name, amount, spot), fmt.Sprintf("You bet %d on %s.", amount, spot))} + return append(events, t.openRound()...) +} + +// Motion is planned backwards from an independently sampled uniform outcome. +// Cosmetic randomness never consumes the table outcome RNG. Steps never grow +// and waits never shrink, so the wheel only ever slows. +// +// The final approach ticks one space at a time. The wheel caps its wait so +// it never crawls, but each click has a 50% chance of one more, so it can +// tease forever. Half the time the very last click does not advance at all: +// it re-prints the winning space. Only that last click may take a long pause. +func bigSixAnimation() []bigSixFrame { + var frames []bigSixFrame + // Opening blur: 3-6 prints of 4-8 spaces each, easing down. (Two steps + // shorter than before so the wheel reaches its final approach sooner.) + step := 4 + rand.Intn(5) // 4..8 + for n := 3 + rand.Intn(4); n > 0; n-- { + frames = append(frames, bigSixFrame{1, step}) + if step > 4 && rand.Intn(2) == 0 { + step-- + } + } + // The wheel eases down: longer waits, shorter hops. + step = min(step, 2+rand.Intn(3)) // 2..4 + for n := 1 + rand.Intn(2); n > 0; n-- { + frames = append(frames, bigSixFrame{2, step}) + } + step = min(step, 1+rand.Intn(2)) // 1..2 + frames = append(frames, bigSixFrame{3, step}) + // Final approach: single-space clicks. The wait is capped at maxApproachWait + // so the wheel keeps moving; after at least three clicks it may stop, but + // each further click has a 50% chance to continue. + const maxApproachWait = 4 + for clicks := 1; ; clicks++ { + frames = append(frames, bigSixFrame{maxApproachWait, 1}) + if clicks >= 3 && rand.Intn(2) == 0 { + break + } + } + // Half the time the wheel makes one final stationary click, printing the + // winning space again instead of ticking over to the next one. + if rand.Intn(2) == 0 { + frames = append(frames, bigSixFrame{maxApproachWait, 0}) + } + // Occasionally a long suspense pause before the final click. + if rand.Intn(3) == 0 { + frames[len(frames)-1].delay = 8 + rand.Intn(5) + } + return frames +} +func (t *bigSixTable) startSpin() Event { + t.phase = phasePlaying + t.window.close() + t.winningIndex = t.rng.Intn(len(bigSixWheel)) + t.frames = bigSixAnimation() + t.frame = 0 + distance := 0 + for _, f := range t.frames { + distance += f.move + } + t.position = (t.winningIndex - distance%len(bigSixWheel) + len(bigSixWheel)) % len(bigSixWheel) + t.wait = t.frames[0].delay + return t.event("No more bets! The brass Big 6 wheel begins to turn...", true) +} +func (t *bigSixTable) tick() []Event { + t.mu.Lock() + defer t.mu.Unlock() + if t.phase == phaseWaiting { + return t.openRound() + } + if t.phase == phaseBetting { + t.window.timer.tick() + if t.window.timer.expired() { + return []Event{t.startSpin()} + } + return nil + } + t.wait-- + if t.wait > 0 { + return nil + } + t.position = (t.position + t.frames[t.frame].move) % len(bigSixWheel) + t.frame++ + if t.frame == len(t.frames) { + return t.settle() + } + t.wait = t.frames[t.frame].delay + e := t.event("", true) + e.Snapshot = t.strip(false) + return []Event{e} +} +func (t *bigSixTable) settle() []Event { + spot := bigSixWheel[t.winningIndex] + t.position = t.winningIndex + e := t.event("The pointer stops on {casino_emphasis}"+spot+"{/}!", true) + e.Snapshot = t.strip(true) + t.lastResult = e.Snapshot.(*BigSixSnapshot) + events := []Event{e} + if spot == "DOUBLE" { + t.multiplier.Lsh(&t.multiplier, 1) + events = append(events, t.event("DOUBLE! Every live bet doubles; the same bets ride again. Stake multiplier: "+t.multiplier.String()+"x.", true)) + return append(events, t.startSpin()) + } + for _, p := range t.players.ordered() { + if !p.HasBet { + continue + } + total := new(big.Int) + var ids []string + var lines []SettlementLine + representable := true + for _, b := range p.bets { + ids = append(ids, b.wager.ID) + returned := new(big.Int) + result := "loss" + if b.spot == spot { + returned.Mul(big.NewInt(int64(b.wager.Total)), &t.multiplier) + returned.Mul(returned, big.NewInt(int64(bigSixPayout(spot)))) + result = "win" + } + total.Add(total, returned) + if !returned.IsInt64() || returned.Cmp(big.NewInt(int64(int(^uint(0)>>1)))) > 0 { + representable = false + } + odds := new(big.Int).Mul(&t.multiplier, big.NewInt(int64(bigSixPayout(b.spot)))) + odds.Sub(odds, big.NewInt(1)) + lines = append(lines, SettlementLine{Label: b.spot, Odds: odds.String() + ":1", Stake: b.wager.Total, Returned: int(returned.Int64()), Result: result}) + } + if !total.IsInt64() || total.Cmp(big.NewInt(int64(int(^uint(0)>>1)))) > 0 { + representable = false + } + // One atomic save pays ALL bets and consumes exactly their ledger handles. + // Unrepresentable payouts stay pending for recovery, never wrap or clamp. + failed := !representable + if !failed { + failed = p.Wallet.PayCredits(int(total.Int64()), ids...) != nil + } + ev := t.playerAction(p.Name, p.Name+" settles their Big 6 wagers.", "") + if failed { + ev.PrivateMessage = payoutFailedMessage() + ev.Message = p.Name + "'s settlement is pending recovery." + } else { + ev.PrivateMessage = settlementText(lines) + ev.Settlement = lines + if t.multiplier.Cmp(big.NewInt(1)) > 0 { + ev.SettlementNote = "DOUBLE stake multiplier: " + t.multiplier.String() + "x; odds and net are relative to your original stake." + } + ev.Color = settlementTag(lines) + } + // The next-spin menu already shows the balance for seats that remain. + // Only a departing or disconnected seat needs it here, otherwise the + // wallet would print twice after a result. + ev.ShowBalance = !failed && (p.LeaveAfter || p.SitOutAfter || !p.Connected) + events = append(events, ev) + } + t.reset() + events = append(events, t.finishControlsLocked()...) + events = append(events, t.openRound()...) + for _, p := range t.players.ordered() { + if p.Connected && !p.SittingOut { + events = append(events, t.menu(p.Name, false)) + } + } + return events +} +func (t *bigSixTable) reset() { + t.phase = phaseWaiting + t.window.close() + t.frames = nil + t.multiplier.SetInt64(1) + for _, p := range t.players.ordered() { + p.bets = nil + p.HasBet = false + p.Wager = Wager{} + } +} +func (t *bigSixTable) action(name, action string) []Event { + t.mu.Lock() + defer t.mu.Unlock() + p := t.players.get(name) + if p == nil { + return []Event{t.private(name, "You aren't playing Big 6.")} + } + if action == "unbet" { + if t.phase == phasePlaying { + return []Event{t.private(name, "You cannot unbet after the wheel starts, including DOUBLE respins.")} + } + if !p.HasBet { + return []Event{t.private(name, "Nothing to take back.")} + } + var ids []string + for _, b := range p.bets { + ids = append(ids, b.wager.ID) + } + if err := p.Wallet.PayCredits(p.Wager.Total, ids...); err != nil { + return []Event{t.private(name, payoutFailedMessage())} + } + total := p.Wager.Total + p.bets = nil + p.HasBet = false + p.Wager = Wager{} + return []Event{t.private(name, fmt.Sprintf("You take back %d credits.", total))} + } + if action == "spin" { + if t.phase == phasePlaying { + return []Event{t.private(name, "The wheel is already spinning.")} + } + if t.phase == phaseBetting { + return []Event{t.private(name, fmt.Sprintf("The shared betting round has %d ticks remaining.", t.window.timer.remaining()))} + } + if !p.HasBet { + return []Event{t.private(name, "Place your bets before spinning.")} + } + return []Event{t.startSpin()} + } + if events, ok := t.controlLocked(name, action); ok { + return events + } + return []Event{t.private(name, "Place bets, then spin. Use rules for Big 6 help.")} +} +func (t *bigSixTable) rebet(name string) (string, int) { + t.mu.Lock() + defer t.mu.Unlock() + if p := t.players.get(name); p != nil && p.lastBet > 0 { + return p.lastSpot, p.lastBet + } + return "", t.Config.MinBet +} +func (t *bigSixTable) status(name string) []Event { + t.mu.Lock() + defer t.mu.Unlock() + events := []Event{t.menu(name, true)} + if t.phase != phasePlaying && t.lastResult != nil { + e := t.private(name, "Last stop:") + e.Snapshot = t.lastResult + events = append(events, e) + } + return events +} +func (t *bigSixTable) markDisconnected(name string) []Event { + t.mu.Lock() + defer t.mu.Unlock() + p := t.players.get(name) + if p == nil { + return nil + } + // Once animation reveals positions, refunds would permit selective losses. + // Match the casino's disconnect-forfeit convention for exposed games. + var events []Event + if p.Wallet != nil { + var err error + if p.HasBet && t.phase == phasePlaying { + var ids []string + for _, b := range p.bets { + ids = append(ids, b.wager.ID) + } + err = p.Wallet.PayCredits(0, ids...) + } else { + _, _, err = p.Wallet.RefundOutstanding() + } + if err != nil { + events = append(events, t.private(name, payoutFailedMessage())) + } + } + t.removeSeatLocked(name) + if t.players.count() == 0 { + t.reset() + } + return t.closeIfEmptyLocked(append(events, t.event(name+" stands up.", true))) +} +func (t *bigSixTable) refundAll() []Event { + t.mu.Lock() + defer t.mu.Unlock() + events := t.refundAllLocked() + t.reset() + return events +} +func (t *bigSixTable) busy(_ string) bool { + t.mu.Lock() + defer t.mu.Unlock() + return t.phase == phasePlaying +} diff --git a/internal/casino/big_six_test.go b/internal/casino/big_six_test.go new file mode 100644 index 0000000..cccad77 --- /dev/null +++ b/internal/casino/big_six_test.go @@ -0,0 +1,293 @@ +package casino + +import ( + "math" + "math/big" + "math/rand" + "strings" + "testing" +) + +func newBigSixTest() *bigSixTable { + return newBigSixTable(1, TableConfig{ID: "wheel", Game: GameBigSix}, rand.New(rand.NewSource(123))) +} +func forceBigSix(t *bigSixTable, spot string) []Event { + for i, s := range bigSixWheel { + if s == spot { + t.winningIndex = i + return t.settle() + } + } + panic("unknown test symbol") +} +func TestBigSixRTPAndRegistry(t *testing.T) { + cfg := TableConfig{ID: "wheel", Game: GameBigSix} + if err := cfg.Validate(); err != nil { + t.Fatal(err) + } + if cfg.Normalize().BettingTicks != 25 || cfg.HelpTopic() != "big6" || newTable(1, cfg, newTestRand()) == nil { + t.Fatal("registration") + } + counts := map[string]int{} + for _, s := range bigSixWheel { + counts[s]++ + } + if len(bigSixWheel) != 51 || counts["DOUBLE"] != 1 { + t.Fatal(counts) + } + for _, s := range BigSixSpots() { + if counts[s.Label] != s.Count { + t.Fatal(s) + } + if s.Pays == 0 { + continue + } + rtp := float64(s.Count*(s.Pays+1)) / float64(len(bigSixWheel)-2*counts["DOUBLE"]) + if rtp < .978 || rtp > .985 || math.Abs(rtp-48.0/49) > 1e-12 { + t.Fatal(s, rtp) + } + if e := cfg.HouseEdge(s.Label); len(e.Parts) != 1 || math.Abs(e.Parts[0].Loss-(1-rtp)) > 1e-12 { + t.Fatal(e) + } + } + if len(cfg.HouseEdge("DOUBLE").Parts) != 0 { + t.Fatal("DOUBLE is not a target") + } +} +func TestBigSixMultipleBetsAndDouble(t *testing.T) { + table := newBigSixTest() + table.join("a") + w := &recordingWallet{testWallet: testWallet{credits: 100}} + table.bet("a", "$1", 10, w) + table.bet("a", "sword", 2, w) + table.bet("a", "1", 3, w) + if table.phase != phaseWaiting || len(w.open) != 3 { + t.Fatal("bet started spin or lost wager") + } + table.action("a", "spin") + if table.phase != phasePlaying { + t.Fatal("spin") + } + forceBigSix(table, "DOUBLE") + forceBigSix(table, "DOUBLE") + if table.multiplier.String() != "4" || w.paid != 0 || len(w.open) != 3 { + t.Fatal("DOUBLE must ride all bets without cashing out") + } + table.bet("a", "2", 1, w) + table.action("a", "unbet") + if len(w.open) != 3 || len(table.players.get("a").bets) != 3 { + t.Fatal("bet/unbet accepted during respin") + } + events := forceBigSix(table, "1") + if w.paid != 104 || len(w.open) != 0 || len(w.payStakes) != 3 { + t.Fatal("wrong payout/ledger", w) + } + for _, e := range events { + if len(e.Settlement) > 0 { + if len(e.Settlement) != 3 || e.Settlement[0].Stake != 10 || e.Settlement[0].Returned != 80 || e.Settlement[0].Odds != "7:1" { + t.Fatal(e.Settlement) + } + } + } + if table.multiplier.String() != "1" || table.phase != phaseWaiting { + t.Fatal("not reset") + } +} +func TestBigSixUncappedDoubleAndSafeOverflow(t *testing.T) { + table := newBigSixTest() + table.join("a") + w := &testWallet{credits: 10} + table.bet("a", "1", 1, w) + table.action("a", "spin") + for i := 0; i < 130; i++ { + forceBigSix(table, "DOUBLE") + } + if table.multiplier.Cmp(new(big.Int).Lsh(big.NewInt(1), 130)) != 0 { + t.Fatal("DOUBLE capped or wrapped") + } + events := forceBigSix(table, "1") + if w.paid != 0 || len(w.open) != 1 { + t.Fatal("overflow must not pay or consume pending stake") + } + for _, e := range events { + if len(e.Settlement) > 0 { + t.Fatal("announced unbanked payout") + } + } + table.refundAll() + if len(w.open) != 0 { + t.Fatal("recovery did not refund") + } +} +func TestBigSixMultiplayerClockWithoutBets(t *testing.T) { + table := newBigSixTest() + table.join("a") + table.join("b") + if table.phase != phaseBetting || table.window.timer.remaining() != 25 { + t.Fatal("join must open betting") + } + table.action("a", "spin") + for i := 0; i < 24; i++ { + table.tick() + if table.phase != phaseBetting { + t.Fatal("early spin", i) + } + } + table.tick() + if table.phase != phasePlaying { + t.Fatal("empty round did not spin") + } + forceBigSix(table, "2") + if table.phase != phaseBetting || table.window.timer.remaining() != 25 { + t.Fatal("next window") + } +} +func TestBigSixAnimationGeometryAndTiming(t *testing.T) { + sawLong, sawVariation := false, false + length := 0 + for round := 0; round < 250; round++ { + table := newBigSixTest() + table.startSpin() + frames := append([]bigSixFrame(nil), table.frames...) + if length != 0 && length != len(frames) { + sawVariation = true + } + length = len(frames) + fast := 0 + prevStep, prevDelay := 10, 1 + for i, f := range frames { + if f.delay == 1 { + fast++ + } + if f.delay >= 8 { + sawLong = true + } + if f.move > prevStep || f.delay < prevDelay { + t.Fatalf("not slowing: %+v", frames) + } + if f.delay == 1 && (f.move < 4 || f.move > 8) || f.delay == 2 && (f.move < 2 || f.move > 4) || f.delay == 3 && (f.move < 1 || f.move > 2) { + t.Fatal(frames) + } + // Only the very last click may take a long pause; everything else + // is capped so the wheel never crawls. + if i < len(frames)-1 && f.delay > 4 { + t.Fatalf("wait uncapped before the last click: %+v", frames) + } + prevStep, prevDelay = f.move, f.delay + } + if fast < 3 || fast > 6 { + t.Fatal("fast count", fast) + } + // The final approach is all single-space clicks, with an optional + // stationary click at the very end. + approach := 0 + for i := len(frames) - 1; i >= 0 && frames[i].move <= 1; i-- { + approach++ + } + if approach < 3 { + t.Fatalf("wheel must click one space at least 3 times at rest: %+v", frames) + } + if frames[len(frames)-1].move > 1 { + t.Fatalf("final click must stay or advance one space: %+v", frames) + } + winner := table.winningIndex + position := table.position + for i, f := range frames { + for wait := 1; wait < f.delay; wait++ { + if e := table.tick(); len(e) != 0 { + t.Fatal("early frame") + } + } + events := table.tick() + position = (position + f.move) % len(bigSixWheel) + var s *BigSixSnapshot + for _, e := range events { + if v, ok := e.Snapshot.(*BigSixSnapshot); ok { + s = v + break + } + } + if s == nil { + t.Fatal("missing frame") + } + count := 11 + if i == len(frames)-1 { + count = 9 + if position != winner { + t.Fatal("outcome teleport") + } + } + if len(s.Pockets) != count { + t.Fatal("strip width", s) + } + for j, p := range s.Pockets { + if p != bigSixWheel[(position+j-count/2+51)%51] { + t.Fatal("invented neighbor") + } + } + } + } + if !sawLong || !sawVariation { + t.Fatal("no suspense variation") + } +} +func TestBigSixUnbetAndDisconnect(t *testing.T) { + for _, spinning := range []bool{false, true} { + table := newBigSixTest() + table.join("a") + w := &testWallet{credits: 100} + table.bet("a", "1", 10, w) + table.bet("a", "2", 20, w) + if spinning { + table.action("a", "spin") + forceBigSix(table, "DOUBLE") + } else { + table.action("a", "unbet") + if w.paid != 30 || len(w.open) != 0 || table.players.get("a").HasBet { + t.Fatal("unbet") + } + table.bet("a", "1", 10, w) + } + table.markDisconnected("a") + if len(w.open) != 0 || table.players.count() != 0 || table.phase != phaseWaiting { + t.Fatal("disconnect cleanup") + } + if spinning && w.paid != 0 { + t.Fatal("selective refund exploit") + } + } +} +func TestBigSixSettlementFailureAndDeparture(t *testing.T) { + table := newBigSixTest() + table.join("a") + w := &failingPayoutWallet{testWallet: testWallet{credits: 100}} + table.bet("a", "1", 10, w) + table.action("a", "spin") + events := forceBigSix(table, "1") + if len(w.open) != 1 { + t.Fatal("failed payout consumed stake") + } + found := false + for _, e := range events { + if strings.Contains(e.Message, "pending recovery") { + found = true + } + if len(e.Settlement) > 0 { + t.Fatal("fake receipt") + } + } + if !found { + t.Fatal("missing error") + } + table.refundAll() + table.bet("a", "1", 1, &testWallet{credits: 10}) + table.action("a", "leave_after") + table.action("a", "spin") + events = forceBigSix(table, "2") + if table.players.count() != 0 { + t.Fatal("queued departure") + } + if s, ok := events[0].Snapshot.(*BigSixSnapshot); !ok || len(s.Players) != 1 || s.Players[0] != "a" { + t.Fatal("departing player lost result visibility") + } +} diff --git a/internal/casino/blackjack.go b/internal/casino/blackjack.go index 5656129..b5beb1e 100644 --- a/internal/casino/blackjack.go +++ b/internal/casino/blackjack.go @@ -112,12 +112,12 @@ func (t *blackjackTable) menuEvent(name string) Event { if t.phase == blackjackPlaying || t.phase == blackjackInsurance { return t.private(name, "Round in progress. You’ll join the next hand; table shows the current action.") } - amount, desc := t.Config.MinBet, "Table minimum" + amount, desc, betCmd := t.Config.MinBet, "Table minimum", "bet" if p := t.players.get(name); p != nil && p.lastBet > 0 { - amount, desc = p.lastBet, "Repeat wager" + amount, desc, betCmd = p.lastBet, "Repeat wager", "bet / rebet" } e := t.betMenuEvent(name, []MenuCommand{ - {Command: "bet", Desc: fmt.Sprintf("%s: %d credits (also: rebet)", desc, amount)}, + {Command: betCmd, Desc: fmt.Sprintf("%s: %d credits", desc, amount)}, {Command: "bet N", Desc: "Change wager; min/max accepted"}, {Command: "stop", Desc: "Leave; during a round, leave afterward"}, {Command: "table", Desc: "Check the table"}, diff --git a/internal/casino/core.go b/internal/casino/core.go index f51dde3..3956750 100644 --- a/internal/casino/core.go +++ b/internal/casino/core.go @@ -187,6 +187,9 @@ func settleStakeOutcome(w Wallet, payout int, stakeIDs []string, payoutErr error // gameTitle renders a configured game name as a message heading. func gameTitle(game GameName) string { + if game == GameBigSix { + return "Big 6" + } name := string(game) if name == "" { return "Table" diff --git a/internal/casino/craps_ux.go b/internal/casino/craps_ux.go index e64feb3..9538e7c 100644 --- a/internal/casino/craps_ux.go +++ b/internal/casino/craps_ux.go @@ -16,7 +16,7 @@ func (t *crapsTable) commands(name string) []MenuCommand { // Pass is the only target, so the bare bet is a rebet. if p.lastBet > 0 { commands = append(commands, - MenuCommand{Command: "bet", Desc: fmt.Sprintf("Rebet %d on pass (also: rebet)", p.lastBet)}, + MenuCommand{Command: "bet / rebet", Desc: fmt.Sprintf("Rebet %d on pass", p.lastBet)}, MenuCommand{Command: "bet N", Desc: "New amount on pass; the dice roll 3 ticks after a bet"}) } else { commands = append(commands, MenuCommand{Command: "bet N", Desc: "Wager on pass; the dice roll 3 ticks after a bet"}) diff --git a/internal/casino/registry.go b/internal/casino/registry.go index a27a9dd..4366bc6 100644 --- a/internal/casino/registry.go +++ b/internal/casino/registry.go @@ -84,6 +84,20 @@ func init() { ruleText: func(c TableConfig) string { return c.CrapsRulesText() }, helpTopic: func(c TableConfig) string { return c.Craps.helpTopic() }, }, + GameBigSix: { + houseEdge: bigSixHouseEdge, + validate: func(c TableConfig) error { + if c.BettingTicks != 0 && c.BettingTicks != 25 { + return fmt.Errorf("Big 6 betting_ticks must be 25") + } + return nil + }, + normalize: func(c TableConfig) TableConfig { c.BettingTicks = 25; return c }, + hasRuleBlock: func(TableConfig) bool { return false }, + new: func(room int, c TableConfig, rng *rand.Rand) tableGame { return newBigSixTable(room, c, rng) }, + ruleText: bigSixRules, + helpTopic: func(TableConfig) string { return "big6" }, + }, GameRoulette: { houseEdge: rouletteHouseEdge, validate: func(c TableConfig) error { diff --git a/internal/casino/table_hints.go b/internal/casino/table_hints.go index eafb05e..5b1d86e 100644 --- a/internal/casino/table_hints.go +++ b/internal/casino/table_hints.go @@ -75,7 +75,7 @@ func baccaratHintCommands(t *baccaratTable, name string) []MenuCommand { } commands := []MenuCommand{} if p != nil && p.hasLastBet() { - commands = append(commands, MenuCommand{Command: "bet", Desc: "Repeat your last bets"}) + commands = append(commands, MenuCommand{Command: "bet / rebet", Desc: "Repeat your last bets"}) } if p != nil && len(p.sides) > 0 { commands = append(commands, MenuCommand{Command: "unbet", Desc: "Take back your side bets"}) diff --git a/internal/casino/table_ux_test.go b/internal/casino/table_ux_test.go index f81d537..9589deb 100644 --- a/internal/casino/table_ux_test.go +++ b/internal/casino/table_ux_test.go @@ -223,7 +223,7 @@ func TestRebetMenusAndMidRoundJoin(t *testing.T) { } bac.bet("alice", "banker", 25, &testWallet{credits: 100}) menu := bac.menuEvent("alice").Menu - if !menu.Repeat || menu.Commands[0].Command != "bet" || !strings.Contains(menu.Commands[0].Desc, "Repeat") { + if !menu.Repeat || menu.Commands[0].Command != "bet / rebet" || !strings.Contains(menu.Commands[0].Desc, "Repeat") { t.Fatalf("missing rebet details: %+v", menu) } } diff --git a/internal/casino/types.go b/internal/casino/types.go index 570d0ac..8986dc1 100644 --- a/internal/casino/types.go +++ b/internal/casino/types.go @@ -20,6 +20,7 @@ const ( GameBlackjack GameName = "blackjack" GameBaccarat GameName = "baccarat" GameRoulette GameName = "roulette" + GameBigSix GameName = "big6" GameCraps GameName = "craps" ) |
