diff options
Diffstat (limited to 'internal/game')
| -rw-r--r-- | internal/game/casino.go | 18 | ||||
| -rw-r--r-- | internal/game/casino_ux.go | 2 | ||||
| -rw-r--r-- | internal/game/cmd_registry.go | 16 | ||||
| -rw-r--r-- | internal/game/game.go | 4 | ||||
| -rw-r--r-- | internal/game/look_casino.go | 4 | ||||
| -rw-r--r-- | internal/game/look_target.go | 2 | ||||
| -rw-r--r-- | internal/game/pachinko_test.go | 309 | ||||
| -rw-r--r-- | internal/game/render_pachinko.go | 404 | ||||
| -rw-r--r-- | internal/game/roulette_animation_test.go | 2 |
9 files changed, 750 insertions, 11 deletions
diff --git a/internal/game/casino.go b/internal/game/casino.go index a0cc675..fa78c2a 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -354,9 +354,11 @@ func (g *Game) executeTableAction(sess *net.Session, action string) { g.emitCasinoEvents(g.Casino.Action(table.RoomID, table.Config.ID, p.Name, action)) } -// Keep the automatic post-command prompt out of a seated player's spin -// animation. Settlement menus resume prompting once the table leaves playing. -func (g *Game) rouletteSpinning(sess *net.Session) bool { +// casinoAnimationBusy reports whether a seated player's game is mid-animation: +// a spinning roulette wheel or Big 6 wheel, or a falling Plinko or Pachinko +// ball. The automatic prompt stays out of that output and resumes when the +// table settles. +func (g *Game) casinoAnimationBusy(sess *net.Session) bool { if g.Casino == nil || sess == nil || sess.Player == nil { return false } @@ -364,8 +366,8 @@ func (g *Game) rouletteSpinning(sess *net.Session) bool { if !playing || table == nil { return false } - if table.Config.Game == casino.GameBigSix { - return table.Busy(sess.Player.Name) + if table.Busy(sess.Player.Name) { + return true } if table.Config.Game != casino.GameRoulette { return false @@ -515,12 +517,13 @@ func (g *Game) casinoBoardReminder(sess *net.Session, category string, menu *cas _, isCraps := snapshot.(*casino.CrapsSnapshot) _, isPoker := snapshot.(*casino.VideoPokerSnapshot) _, isPlinko := snapshot.(*casino.PlinkoSnapshot) + _, isPachinko := snapshot.(*casino.PachinkoSnapshot) _, isCashHunt := snapshot.(*casino.CashHuntSnapshot) _, isPaiGow := snapshot.(*casino.PaiGowSnapshot) b, isBigSix := snapshot.(*casino.BigSixSnapshot) isBigSix = isBigSix && b.Phase != "playing" && b.Phase != "result" s, isRoulette := snapshot.(*casino.RouletteSnapshot) - if !isCashHunt && !isPlinko && !isPoker && !isCraps && !isPaiGow && !isBigSix && (!isRoulette || s.Phase == "playing" || s.Phase == "result") { + if !isCashHunt && !isPlinko && !isPachinko && !isPoker && !isCraps && !isPaiGow && !isBigSix && (!isRoulette || s.Phase == "playing" || s.Phase == "result") { return "", false } if isRoulette && sess.Player.OptionString("casino_display") == "compact" && (menu.Repeat || !menu.ShowBalance) { @@ -617,6 +620,9 @@ func (g *Game) renderCasinoSnapshot(sess *net.Session, snapshot casino.Snapshot) return renderCashHunt(s, mode, unicode, rtp) case *casino.PlinkoSnapshot: return renderPlinko(s, mode, unicode) + case *casino.PachinkoSnapshot: + precision, showOdds := g.casinoEdgePrecision(sess) + return renderPachinko(s, mode, unicode, showOdds, precision) case *casino.PaiGowSnapshot: return renderPaiGow(s, mode, unicode, size, sess.Player.OptionString("card_style"), g.CardArt) case *casino.VideoPokerSnapshot: diff --git a/internal/game/casino_ux.go b/internal/game/casino_ux.go index 88562cd..7eb10dd 100644 --- a/internal/game/casino_ux.go +++ b/internal/game/casino_ux.go @@ -68,6 +68,8 @@ func casinoTableAliases(cfg casino.TableConfig) []string { switch cfg.Game { case casino.GameCashHunt: names = append(names, "cash hunt", "cashhunt", "cash-hunt") + case casino.GamePachinko: + names = append(names, "pachinko") case casino.GameBigSix: names = append(names, "big-six", "big_six", "big six", "big 6") case casino.GameBlackjack: diff --git a/internal/game/cmd_registry.go b/internal/game/cmd_registry.go index 2defb9e..ef17925 100644 --- a/internal/game/cmd_registry.go +++ b/internal/game/cmd_registry.go @@ -252,6 +252,8 @@ func (g *Game) casinoOwnedInput(sess *net.Session, cmd string) bool { switch table.Config.Game { case casino.GameCashHunt: return isAllDigits(cmd) || cmd == "settle" + case casino.GamePachinko: + return isAllDigits(cmd) case casino.GamePaiGow: return isAllDigits(cmd) || cmd == "set" || cmd == "house" || cmd == "autoset" || cmd == "settle" } @@ -291,6 +293,7 @@ var casinoCommonVerbs = []string{"watch", "game", "table", "list", "stop", "rule var casinoVerbsByGame = map[casino.GameName][]string{ casino.GameCashHunt: {"bet", "rebet", "difficulty", "paytable", "pick", "settle"}, casino.GamePlinko: {"bet", "rebet", "difficulty", "balls", "paytable"}, + casino.GamePachinko: {"bet", "rebet", "table", "drop"}, casino.GameBlackjack: {"bet", "rebet", "unbet", "hit", "stand", "double", "split", "insurance", "surrender", "decline"}, casino.GameBaccarat: {"bet", "rebet", "unbet"}, casino.GameRoulette: {"bet", "rebet", "unbet"}, @@ -417,6 +420,19 @@ func (g *Game) executeCommand(sess *net.Session, cmd string, args []string, rawI } } + // Pachinko owns bare slot numbers and "drop N" while seated; a "drop" + // with any other argument still drops an item from the world. + if p != nil && g.Casino != nil { + if t, playing := g.Casino.Participation(p.Name); playing && t != nil && t.Config.Game == casino.GamePachinko { + numeric := cmd != "" && cmd[0] >= '0' && cmd[0] <= '9' + dropSlot := cmd == "drop" && len(args) == 1 && isAllDigits(args[0]) + if numeric || dropSlot { + g.executeTableAction(sess, strings.Join(append([]string{cmd}, args...), " ")) + return + } + } + } + // Pai Gow owns these inputs only while seated; leave normal commands alone. if p != nil && g.Casino != nil { if t, playing := g.Casino.Participation(p.Name); playing && t != nil && t.Config.Game == casino.GamePaiGow { diff --git a/internal/game/game.go b/internal/game/game.go index 448dcce..6780250 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -586,13 +586,13 @@ func playerDataFileName(relPath string) (name, kind string, ok bool) { } func (g *Game) writePrompt(sess *net.Session) { - if !g.rouletteSpinning(sess) { + if !g.casinoAnimationBusy(sess) { sess.WritePrompt(g.promptStr(sess)) } } func (g *Game) reprompt(sess *net.Session) { - if !g.rouletteSpinning(sess) { + if !g.casinoAnimationBusy(sess) { sess.Reprompt(g.promptStr(sess)) } } diff --git a/internal/game/look_casino.go b/internal/game/look_casino.go index eb0b5f9..e349386 100644 --- a/internal/game/look_casino.go +++ b/internal/game/look_casino.go @@ -83,7 +83,7 @@ func (g *Game) renderCasinoTableDetails(sess *net.Session, cfg casino.TableConfi fmt.Sprintf(" Seated %s", seated), } switch cfg.Game { - case casino.GameRoulette, casino.GameBigSix, casino.GamePlinko, casino.GameCashHunt: + case casino.GameRoulette, casino.GameBigSix, casino.GamePlinko, casino.GamePachinko, casino.GameCashHunt: // Look, like sitting down and the table command, shows the live // wheel: tracker, racetrack, and betting layout. if rendered := strings.TrimRight(g.renderCasinoSnapshot(sess, table.Board(sess.Player.Name)), "\n"); rendered != "" { @@ -107,6 +107,8 @@ func casinoTableSummary(cfg casino.TableConfig) string { return "100 squares; three difficulties; 98% RTP; prizes up to 50000x" case casino.GamePlinko: return fmt.Sprintf("16 rows; four risks; 1-10 balls; near %.4g%% target RTP", cfg.Plinko.Normalize().RTP) + case casino.GamePachinko: + return "8 slots; 20 reflected rows; populated fractional board" case casino.GameBlackjack: b := cfg.Blackjack.Normalize() dealer := "dealer stands on soft 17" diff --git a/internal/game/look_target.go b/internal/game/look_target.go index 0ddd8f4..97d7ecb 100644 --- a/internal/game/look_target.go +++ b/internal/game/look_target.go @@ -50,7 +50,7 @@ func (g *Game) doLookTarget(sess *net.Session, input string) { // Felt tables resolve through one data-driven loop; the video-poker cabinet // has its own cabinet-id/pay-table handling. - for _, game := range []casino.GameName{casino.GameCashHunt, casino.GamePlinko, casino.GameBigSix, casino.GameBlackjack, casino.GameBaccarat, casino.GameRoulette, casino.GameCraps, casino.GamePaiGow} { + for _, game := range []casino.GameName{casino.GameCashHunt, casino.GamePlinko, casino.GamePachinko, casino.GameBigSix, casino.GameBlackjack, casino.GameBaccarat, casino.GameRoulette, casino.GameCraps, casino.GamePaiGow} { if g.lookCasinoTable(sess, lower, game) { return } diff --git a/internal/game/pachinko_test.go b/internal/game/pachinko_test.go new file mode 100644 index 0000000..fbf3b35 --- /dev/null +++ b/internal/game/pachinko_test.go @@ -0,0 +1,309 @@ +package game + +import ( + "strings" + "testing" + "unicode/utf8" + + "thehouseoficarus/internal/casino" + "thehouseoficarus/internal/color" +) + +func pachinkoTestSnapshot(phase string) *casino.PachinkoSnapshot { + s := &casino.PachinkoSnapshot{ + Phase: phase, + RTP: 100.00, + Uniform: 83.67, + Row: pachinkoRows, + Lane: 4, + Landing: -1, + Doubling: 0, + } + values := []casino.PachinkoPocket{ + {Value: 0}, {Value: 2}, {Value: 10}, {Value: 2}, {Value: 100}, + {Double: true}, {Value: 2}, {Value: 10}, + } + copy(s.Pockets[:], values) + if phase == "result" { + s.Landing = 4 + } + return s +} + +func TestPachinkoRenderBoard(t *testing.T) { + for _, mode := range []string{"none", "ansi", "xterm256"} { + for _, unicode := range []bool{false, true} { + s := pachinkoTestSnapshot("choosing") + out := renderPachinko(s, mode, unicode, false, 0) + lines := strings.Split(out, "\n") + if len(lines) != pachinkoRows+3 { + t.Fatalf("%d lines, want %d", len(lines), pachinkoRows+3) + } + for _, line := range lines { + if got := utf8.RuneCountInString(stripANSI(line)); got != pachinkoWidth { + t.Fatalf("line width %d, want %d (%q)", got, pachinkoWidth, stripANSI(line)) + } + } + if mode == "none" { + if strings.Contains(out, "\x1b") { + t.Fatal("plain board has ANSI escapes") + } + if !strings.Contains(stripANSI(out), "DBL") || !strings.Contains(stripANSI(out), "100x") { + t.Fatalf("plain board missing prizes: %q", stripANSI(out)) + } + } else { + for bg := 0; bg < 256; bg++ { + if strings.Contains(out, color.BgCode(mode, bg)) { + t.Fatalf("%s board must not paint a background", mode) + } + } + } + } + } +} + +func TestPachinkoHeaderSitsBetweenPegs(t *testing.T) { + s := pachinkoTestSnapshot("choosing") + lines := strings.Split(stripANSI(renderPachinko(s, "none", false, false, 0)), "\n") + header, firstPegs := []rune(lines[0]), []rune(lines[1]) + for lane := 0; lane < pachinkoLanes; lane++ { + x := pachinkoLaneX(lane) + if header[x] != rune('1'+lane) { + t.Fatalf("header %d not at x=%d: %q", lane+1, x, string(header)) + } + // The number must sit in a gap of the first peg row, not on a pin or + // the wall. + if firstPegs[x] != ' ' { + t.Fatalf("slot %d header overlaps a pin or wall: %q", lane+1, string(firstPegs)) + } + near := false + for _, dx := range []int{-pachinkoPitch / 2, pachinkoPitch / 2} { + if at := x + dx; at >= 0 && at < len(firstPegs) && firstPegs[at] == '.' { + near = true + } + } + if !near { + t.Fatalf("slot %d header not between pins: %q", lane+1, string(firstPegs)) + } + } +} + +func TestPachinkoRenderDroppingIsOneLine(t *testing.T) { + s := pachinkoTestSnapshot("dropping") + for row := 0; row <= pachinkoRows; row++ { + for lane := 0; lane < pachinkoLanes; lane++ { + s.Row, s.Lane = row, lane + out := renderPachinko(s, "none", true, false, 0) + if strings.Contains(out, "\n") { + t.Fatalf("row %d lane %d printed more than one line", row, lane) + } + if got := utf8.RuneCountInString(stripANSI(out)); got != pachinkoWidth { + t.Fatalf("row %d lane %d width %d, want %d", row, lane, got, pachinkoWidth) + } + // The ball sits exactly on its staggered lane column. + plain := []rune(stripANSI(out)) + if plain[pachinkoDropX(row, lane)] != 'โ' { + t.Fatalf("row %d lane %d ball misplaced: %q", row, lane, string(plain)) + } + } + } +} + +func TestPachinkoRenderResultMarksLanding(t *testing.T) { + s := pachinkoTestSnapshot("result") + s.Landing = 4 + out := stripANSI(renderPachinko(s, "none", true, false, 0)) + lines := strings.Split(out, "\n") + // The settled view is only the prize row: the drop already drew the ball + // path, so the result must not reprint the board or its number header. + if len(lines) != 1 { + t.Fatalf("result should be one prize row, got %d lines: %q", len(lines), out) + } + if got := utf8.RuneCountInString(lines[0]); got != pachinkoWidth { + t.Fatalf("result width %d, want %d", got, pachinkoWidth) + } + if !strings.Contains(lines[len(lines)-1], "[100x]") { + t.Fatalf("landed jackpot not bracketed: %q", lines[len(lines)-1]) + } + if strings.Count(lines[len(lines)-1], "[") != 1 { + t.Fatalf("only the landed pocket may be bracketed: %q", lines[len(lines)-1]) + } +} + +func TestPachinkoRenderDoubledLabels(t *testing.T) { + s := pachinkoTestSnapshot("choosing") + s.Doubling = 2 + out := stripANSI(renderPachinko(s, "none", true, false, 0)) + // 0, 2, 10, 2, 100, DBL, 2, 10, 0 doubled twice: 0, 8, 40, 8, 400, DBL, 8, 40, 0. + for _, want := range []string{"8x", "40x", "400x", "DBL"} { + if !strings.Contains(out, want) { + t.Fatalf("doubled board missing %q: %q", want, out) + } + } +} + +func TestPachinkoIdleShowsIntroOnly(t *testing.T) { + s := &casino.PachinkoSnapshot{Phase: "idle", RTP: 100.00, Uniform: 83.67, Odds: casino.PachinkoOdds()} + out := stripANSI(renderPachinko(s, "none", true, false, 0)) + if !strings.Contains(out, "You stand atop a giant peg board") { + t.Fatalf("idle view missing the intro: %q", out) + } + // Sitting down must not dump the blank board or pay table. + if strings.Contains(out, "Pachinko pay table") || strings.Contains(out, "?") || strings.Contains(out, "Prize") { + t.Fatalf("idle view leaked the reference table: %q", out) + } +} + +func TestPachinkoPaytableRender(t *testing.T) { + s := &casino.PachinkoSnapshot{Phase: "paytable", RTP: 100.00, Uniform: 83.67} + s.Odds = casino.PachinkoOdds() + out := stripANSI(renderPachinko(s, "none", true, true, 2)) + for _, want := range []string{"100.00%", "83.67%", "0.1-1.5x", "1.7x", "2x", "5x", "10x", "100x", "DOUBLE"} { + if !strings.Contains(out, want) { + t.Fatalf("paytable missing %q: %q", want, out) + } + } + if !strings.Contains(out, "Prize") || !strings.Contains(out, "Chance") || !strings.Contains(out, "Odds") { + t.Fatalf("paytable missing its columns: %q", out) + } +} + +func TestPachinkoPaytableHidesOdds(t *testing.T) { + s := &casino.PachinkoSnapshot{Phase: "paytable", RTP: 100.00, Uniform: 83.67, Odds: casino.PachinkoOdds()} + out := stripANSI(renderPachinko(s, "none", true, false, 2)) + if !strings.Contains(out, "Pachinko pay table") || !strings.Contains(out, "DOUBLE") { + t.Fatalf("reference view missing the table: %q", out) + } + // Without a House Edge instrument the exact percentages stay hidden. + for _, leak := range []string{"100.00%", "83.67%", "28.18%", "5.00%"} { + if strings.Contains(out, leak) { + t.Fatalf("paytable leaked odds %q without an instrument: %q", leak, out) + } + } +} + +func TestPachinkoPaytablePrecision(t *testing.T) { + s := &casino.PachinkoSnapshot{Phase: "paytable", RTP: 100.00, Uniform: 80.09, Odds: casino.PachinkoOdds()} + out := stripANSI(renderPachinko(s, "none", true, true, 0)) + if !strings.Contains(out, "4%") || strings.Contains(out, "3.73%") { + t.Fatalf("whole-percent instrument should round: %q", out) + } + out = stripANSI(renderPachinko(s, "none", true, true, 2)) + if !strings.Contains(out, "3.73%") { + t.Fatalf("hundredth-percent instrument should not round: %q", out) + } +} + +func TestPachinkoCommandsAndReceipt(t *testing.T) { + g, s, conn := casinoCrapsGame(t, "name: Pins\ncasino_tables:\n - id: pachinko\n game: pachinko\n") + s.Player.Options = map[string]any{"color": "none", "casino_hints": "off"} + g.executePlay(s, []string{"pachinko"}, "play pachinko") + table, ok := g.Casino.Participation(s.Player.Name) + if !ok || table == nil || table.Config.Game != casino.GamePachinko { + t.Fatal("pachinko was not seated") + } + conn.data = nil + g.executeBet(s, []string{"1"}, "bet 1") + if text := stripANSI(string(conn.data)); !strings.Contains(text, "Choose a top slot") || !strings.Contains(text, "0.1x") { + t.Fatalf("bet did not reveal a board: %s", text) + } + if table.Busy(s.Player.Name) { + t.Fatal("choosing a slot must not suppress the input prompt") + } + // A bare slot number must reach the game rather than being rejected. + conn.data = nil + g.handleGameCommand(s, "4") + if strings.Contains(string(conn.data), "Unknown command") { + t.Fatalf("bare slot rejected: %s", conn.data) + } + if !table.Busy(s.Player.Name) { + t.Fatal("drop did not start") + } + // Settle, re-dropping through any chained DOUBLEs. + for i := 0; i < 2000; i++ { + switch table.State() { + case "waiting": + i = 5000 + case "choosing a slot": + g.executeTableAction(s, "4") + case "dropping": + g.emitCasinoEvents(g.Casino.Tick()) + } + } + if table.State() != "waiting" || len(s.Player.PendingWagers) != 0 { + t.Fatalf("round did not settle: state %q pending %d", table.State(), len(s.Player.PendingWagers)) + } + if text := stripANSI(string(conn.data)); !strings.Contains(text, "Returned:") || !strings.Contains(text, "Staked") { + t.Fatalf("settlement receipt missing: %s", text) + } + conn.data = nil + g.doLookTarget(s, "pachinko") + if text := stripANSI(string(conn.data)); !strings.Contains(text, "giant peg board") { + t.Fatalf("look missing the reference board: %s", text) + } + conn.data = nil + g.executeRules(s, nil, "rules") + if text := stripANSI(string(conn.data)); !strings.Contains(text, "PACHINKO") { + t.Fatalf("rules did not open the pachinko help page: %s", text) + } +} + +func TestPachinkoRejectsPickingSlotBeforeBoard(t *testing.T) { + g, s, conn := casinoCrapsGame(t, "name: Pins\ncasino_tables:\n - id: pachinko\n game: pachinko\n") + s.Player.Options = map[string]any{"color": "none", "casino_hints": "off"} + g.executePlay(s, []string{"pachinko"}, "play pachinko") + conn.data = nil + g.executeBet(s, []string{"1", "on", "5"}, "bet 1 on 5") + table, _ := g.Casino.Participation(s.Player.Name) + if table.State() != "waiting" { + t.Fatalf("bet on SLOT should be rejected before the board exists: %q", table.State()) + } + if len(s.Player.PendingWagers) != 0 { + t.Fatal("rejected bet must not commit a stake") + } + if !strings.Contains(stripANSI(string(conn.data)), "board is revealed before you choose") { + t.Fatalf("missing rejection: %s", conn.data) + } +} + +func TestPachinkoDropSuppressesPrompt(t *testing.T) { + g, s, conn := casinoCrapsGame(t, "name: Pins\ncasino_tables:\n - id: pachinko\n game: pachinko\n") + s.Player.Options = map[string]any{"color": "none", "casino_hints": "off"} + g.executePlay(s, []string{"pachinko"}, "play pachinko") + g.executeBet(s, []string{"1"}, "bet 1") + conn.data = nil + g.handleGameCommand(s, "4") + if !g.casinoAnimationBusy(s) { + t.Fatal("drop did not mark the table busy") + } + before := len(conn.data) + g.writePrompt(s) // the command queue's post-command prompt + if len(conn.data) != before { + t.Fatalf("prompt interrupted the drop: %q", conn.data) + } +} + +func TestPachinkoDropVerbKeepsItemDrop(t *testing.T) { + // "drop sword" must stay a world command, not a casino slot. + g, s, conn := casinoCrapsGame(t, "name: Pins\ncasino_tables:\n - id: pachinko\n game: pachinko\n") + s.Player.Options = map[string]any{"color": "none", "casino_hints": "off"} + g.executePlay(s, []string{"pachinko"}, "play pachinko") + g.executeBet(s, []string{"1"}, "bet 1") + conn.data = nil + g.executeCommand(s, "drop", []string{"sword"}, "drop sword") + if strings.Contains(string(conn.data), "Choose a top slot") { + t.Fatalf("drop with a non-slot argument leaked into the casino: %s", conn.data) + } +} + +func TestPachinkoHelpAndAliases(t *testing.T) { + for _, name := range []string{"pachinko", "pachinko machine"} { + g, s, _ := casinoCrapsGame(t, "name: Pins\ncasino_tables:\n - id: pachinko\n game: pachinko\n") + args := strings.Fields(name) + g.executePlay(s, args, "play "+name) + table, ok := g.Casino.Participation(s.Player.Name) + if !ok || table == nil || table.Config.Game != casino.GamePachinko { + t.Fatalf("alias %q did not seat the player", name) + } + } +} diff --git a/internal/game/render_pachinko.go b/internal/game/render_pachinko.go new file mode 100644 index 0000000..e973f04 --- /dev/null +++ b/internal/game/render_pachinko.go @@ -0,0 +1,404 @@ +package game + +import ( + "fmt" + "math" + "strconv" + "strings" + + "thehouseoficarus/internal/casino" + "thehouseoficarus/internal/color" + "thehouseoficarus/internal/ui" +) + +// The rectangle is drawn on a fixed pitch: eight lanes at x = 3+6k, pegs on +// the boundaries at x = 6+6k, and walls at both ends. Every scanline has the +// same width, so a drop prints one row per tick and the ball's path reads as a +// diagonal column of frames. The right wall sits one half-lane past the last +// lane, mirroring the left wall, so the outer slots have the same clearance on +// both sides. +const ( + pachinkoLanes = 8 + pachinkoRows = 20 + pachinkoPitch = 6 + pachinkoWidth = pachinkoLanes*pachinkoPitch + 1 + pachinkoBallX = 3 + pachinkoPegGap = 6 +) + +// pachinkoLaneX is the fixed column of a lane on an even scanline; the prize +// row and the top labels use it so a settled ball lines up with its pocket. +func pachinkoLaneX(lane int) int { return pachinkoBallX + pachinkoPitch*lane } + +// pachinkoDropX staggers the ball's column on odd rows so a ball that holds its +// lane visibly weaves between the pins instead of sliding down a static grid. +func pachinkoDropX(row, lane int) int { + if row%2 == 0 { + return pachinkoLaneX(lane) + } + return pachinkoPitch * (lane + 1) +} + +// pachinkoGradientRGB gives the board a warm jewel ramp: deep violet walls, +// through blue and teal, to a golden-red right edge. +func pachinkoGradientRGB(x int) [3]int { + stops := [5][3]int{{150, 80, 255}, {60, 170, 255}, {40, 230, 190}, {255, 210, 60}, {255, 90, 70}} + distance := float64(x) / float64(pachinkoWidth-1) + segment := min(3, int(distance*4)) + blend := distance*4 - float64(segment) + var rgb [3]int + for i := range rgb { + rgb[i] = int(math.Round(float64(stops[segment][i])*(1-blend) + float64(stops[segment+1][i])*blend)) + } + return rgb +} + +func pachinkoColorAt(x int, scale float64) int { + rgb := pachinkoGradientRGB(x) + return color.NearestXterm256( + max(0, min(255, int(float64(rgb[0])*scale))), + max(0, min(255, int(float64(rgb[1])*scale))), + max(0, min(255, int(float64(rgb[2])*scale)))) +} + +func pachinkoPegColor(x int) int { return pachinkoColorAt(x, 0.45) } +func pachinkoWallColor(x int) int { return pachinkoColorAt(x, 0.85) } +func pachinkoHeaderColor(x int) int { return pachinkoColorAt(x, 1.0) } + +// pachinkoPocketColor maps a prize to a readable color; doubling shifts an +// already-valuable pocket hotter. +func pachinkoPocketColor(p casino.PachinkoPocket, doubling int) int { + switch { + case p.Double: + if doubling > 0 { + return 201 // bright magenta + } + return 198 // magenta + case p.Value >= 100: + return 51 // neon cyan + case p.Value >= 10: + if doubling > 0 { + return 226 + } + return 220 // gold + case p.Value >= 5: + return 208 // orange + case p.Value >= 2: + return 46 // green + case p.Value >= 1: + return 49 // teal: break-even and small fractions + case p.Value > 0: + return 245 // dim fraction + default: + return 240 // dim slate for 0x + } +} + +func pachinkoPocketBold(p casino.PachinkoPocket, doubling int) bool { + return !p.Double && (p.Value >= 2 || doubling > 0) +} + +type pachinkoCell struct { + glyph rune + fg int + bold bool +} + +type pachinkoLine [pachinkoWidth]pachinkoCell + +func newPachinkoLine() pachinkoLine { + var line pachinkoLine + for x := range line { + line[x] = pachinkoCell{glyph: ' ', fg: -1} + } + return line +} + +func (line *pachinkoLine) put(x int, glyph rune, fg int) { + if x >= 0 && x < len(line) { + line[x] = pachinkoCell{glyph: glyph, fg: fg} + } +} + +func (line *pachinkoLine) putBold(x int, glyph rune, fg int) { + if x >= 0 && x < len(line) { + line[x] = pachinkoCell{glyph: glyph, fg: fg, bold: true} + } +} + +// centeredStart returns the first cell of a text of length n centered in the +// 6-wide lane k cell. +func pachinkoCenteredStart(lane, n int) int { + if n > pachinkoPitch { + n = pachinkoPitch + } + return pachinkoPitch*lane + (pachinkoPitch-n+1)/2 +} + +func (line pachinkoLine) render(mode string) string { + var b strings.Builder + for x := 0; x < len(line); { + cell := line[x] + end := x + 1 + for end < len(line) && line[end].fg == cell.fg && line[end].bold == cell.bold { + end++ + } + var text strings.Builder + for _, c := range line[x:end] { + text.WriteRune(c.glyph) + } + b.WriteString(color.Render(mode, color.ColorSpec{Fg: cell.fg, Bg: -1, Bold: cell.bold}, text.String())) + x = end + } + return b.String() +} + +func pachinkoGlyphs(unicode bool) (ball, peg rune) { + if unicode { + return 'โ', 'ยท' + } + return 'o', '.' +} + +// pachinkoScanline draws one staggered peg row, optionally with the ball in a +// lane. +func pachinkoScanline(row, ballLane int, mode string, unicode bool) string { + ball, peg := pachinkoGlyphs(unicode) + line := newPachinkoLine() + line.put(0, '|', pachinkoWallColor(0)) + line.put(pachinkoWidth-1, '|', pachinkoWallColor(pachinkoWidth-1)) + if row%2 == 0 { + for k := 0; k < pachinkoLanes-1; k++ { + x := pachinkoPegGap + pachinkoPitch*k + line.put(x, peg, pachinkoPegColor(x)) + } + } else { + for k := 0; k < pachinkoLanes; k++ { + x := pachinkoBallX + pachinkoPitch*k + line.put(x, peg, pachinkoPegColor(x)) + } + } + if ballLane >= 0 && ballLane < pachinkoLanes { + line.putBold(pachinkoDropX(row, ballLane), ball, 231) + } + return line.render(mode) +} + +// pachinkoPocketLabel is the text shown for a landed value after doublings. +func pachinkoPocketLabel(p casino.PachinkoPocket, doubling int) string { + if p.Double { + return "DBL" + } + value := p.Value + for i := 0; i < doubling && i < 62; i++ { + value *= 2 + if value > casino.MaxCredits { + return "MAX" + } + } + if value > casino.MaxCredits { + return "MAX" + } + return strconv.FormatFloat(value, 'f', -1, 64) + "x" +} + +// pachinkoPocketRow prints the prize row, marking the landed pocket. +func pachinkoPocketRow(s *casino.PachinkoSnapshot, mode string) string { + var b strings.Builder + for lane := 0; lane < pachinkoLanes; lane++ { + pocket := s.Pockets[lane] + label := pachinkoPocketLabel(pocket, s.Doubling) + landed := s.Landing == lane && (s.Phase == "result" || s.Phase == "dropping") + text := label + if landed && len([]rune("["+label+"]")) <= pachinkoPitch { + text = "[" + label + "]" + } + fg := pachinkoPocketColor(pocket, s.Doubling) + bold := pachinkoPocketBold(pocket, s.Doubling) + if landed { + bold = true + switch { + case pocket.Double: + fg = 201 + case pocket.Value >= 100: + fg = 51 + default: + fg = 226 + } + } + runes := []rune(text) + if len(runes) > pachinkoPitch { + runes = runes[:pachinkoPitch] + } + lead := pachinkoCenteredStart(lane, len(runes)) - pachinkoPitch*lane + if lead < 0 { + lead = 0 + } + trail := pachinkoPitch - lead - len(runes) + if trail < 0 { + trail = 0 + } + b.WriteString(strings.Repeat(" ", lead)) + b.WriteString(color.Render(mode, color.ColorSpec{Fg: fg, Bg: -1, Bold: bold}, string(runes))) + b.WriteString(strings.Repeat(" ", trail)) + } + // The cells span pachinkoLanes*pachinkoPitch; pad to the board width. + b.WriteString(strings.Repeat(" ", pachinkoWidth-pachinkoLanes*pachinkoPitch)) + return b.String() +} + +// renderPachinkoBoard draws the whole rectangle: the numbered top slots, the +// peg rows, and the prize row. The labels sit in the gaps of the first peg row +// (not on its pins) so they read as slots to drop the ball into. The first +// drawn row is the even entry row, whose pins bracket each slot number. +func renderPachinkoBoard(s *casino.PachinkoSnapshot, mode string, unicode bool) string { + lines := make([]string, 0, pachinkoRows+3) + header := newPachinkoLine() + for lane := 0; lane < pachinkoLanes; lane++ { + x := pachinkoLaneX(lane) + header.put(x, rune('1'+lane), pachinkoHeaderColor(x)) + } + lines = append(lines, header.render(mode)) + for row := 0; row <= pachinkoRows; row++ { + lines = append(lines, pachinkoScanline(row, -1, mode, unicode)) + } + lines = append(lines, pachinkoPocketRow(s, mode)) + return strings.Join(lines, "\n") +} + +// pachinkoBlankPocketRow prints a prize row of question marks for the +// reference view, where no board has been dealt yet. +func pachinkoBlankPocketRow(mode string) string { + var b strings.Builder + for lane := 0; lane < pachinkoLanes; lane++ { + x := pachinkoLaneX(lane) + fg := pachinkoColorAt(x, 0.6) + lead := pachinkoCenteredStart(lane, 1) - pachinkoPitch*lane + if lead < 0 { + lead = 0 + } + trail := pachinkoPitch - lead - 1 + if trail < 0 { + trail = 0 + } + b.WriteString(strings.Repeat(" ", lead)) + b.WriteString(color.Render(mode, color.ColorSpec{Fg: fg, Bg: -1, Bold: true}, "?")) + b.WriteString(strings.Repeat(" ", trail)) + } + b.WriteString(strings.Repeat(" ", pachinkoWidth-pachinkoLanes*pachinkoPitch)) + return b.String() +} + +// renderPachinkoBlankBoard draws the numbered top slots, the peg rows, and a +// row of question marks in place of the pockets. +func renderPachinkoBlankBoard(mode string, unicode bool) string { + lines := make([]string, 0, pachinkoRows+3) + header := newPachinkoLine() + for lane := 0; lane < pachinkoLanes; lane++ { + x := pachinkoLaneX(lane) + header.put(x, rune('1'+lane), pachinkoHeaderColor(x)) + } + lines = append(lines, header.render(mode)) + for row := 0; row <= pachinkoRows; row++ { + lines = append(lines, pachinkoScanline(row, -1, mode, unicode)) + } + lines = append(lines, pachinkoBlankPocketRow(mode)) + return strings.Join(lines, "\n") +} + +// pachinkoOddsColor maps a prize tier to the color its label uses in the table. +func pachinkoOddsColor(label string) int { + switch label { + case "1.7x": + return 49 + case "2x": + return 46 + case "5x": + return 208 + case "10x": + return 220 + case "DOUBLE": + return 198 + case "100x": + return 51 + default: + return 240 + } +} + +// renderPachinkoOddsTable lays the board composition out as a bordered table. +// The chance column carries the exact percentages, so it is blanked unless the +// player carries a House Edge instrument. +func renderPachinkoOddsTable(odds []casino.PachinkoPrizeOdds, mode string, unicode, showOdds bool, precision int) string { + rows := make([][]string, 0, len(odds)) + for _, odd := range odds { + chance := "?" + if showOdds { + if odd.Chance > 0 { + chance = strconv.FormatFloat(100*odd.Chance, 'f', precision, 64) + "%" + } else { + chance = "โ" + } + } + label := color.Render(mode, color.ColorSpec{Fg: pachinkoOddsColor(odd.Label), Bg: -1, Bold: odd.Label == "DOUBLE" || odd.Label == "100x"}, odd.Label) + rows = append(rows, []string{label, chance, odd.Odds}) + } + table := ui.Table{ + Title: "Pachinko pay table", + Columns: []string{"Prize", "Chance", "Odds"}, + Rows: rows, + } + return strings.Join(table.Render(unicode, 0), "\n") +} + +// pachinkoIntro is the framing text every player sees, whether they are just +// sitting down or reading the table reference. It is never gated by items. +func pachinkoIntro(mode string) string { + return color.Render(mode, color.ColorSpec{Fg: 253, Bg: -1}, "You stand atop a giant peg board with 8 slots and 20 rows. Win multipliers are randomized as soon as you place a bet.") +} + +// renderPachinkoReference is the table command's view: the framing text, a +// blank board, and the pay table. The RTP footer appears only with a House Edge +// instrument, matching the gated chance column. +func renderPachinkoReference(s *casino.PachinkoSnapshot, mode string, unicode, showOdds bool, precision int) string { + parts := []string{ + pachinkoIntro(mode), + "", + renderPachinkoBlankBoard(mode, unicode), + "", + renderPachinkoOddsTable(s.Odds, mode, unicode, showOdds, precision), + } + if showOdds { + format := func(v float64) string { return strconv.FormatFloat(v, 'f', precision, 64) + "%" } + parts = append(parts, "", fmt.Sprintf("Best slot: %s RTP Random slot: %s RTP", format(s.RTP), format(s.Uniform))) + } + return strings.Join(parts, "\n") +} + +// renderPachinko renders the game view: two scanlines per tick while the ball +// falls, the full board while choosing, the prize row once it settles, and the +// blank board plus pay table for the table command. showOdds controls whether +// the exact percentages appear; precision is the House Edge instrument's +// rounding (0 or 2 decimal places). +func renderPachinko(s *casino.PachinkoSnapshot, mode string, unicode, showOdds bool, precision int) string { + if s == nil { + return "" + } + switch s.Phase { + case "paytable": + return renderPachinkoReference(s, mode, unicode, showOdds, precision) + case "idle": + // Sitting down shows the framing text and the menu, but not the blank + // board or pay table; those wait for the table command. + return pachinkoIntro(mode) + case "dropping": + return pachinkoScanline(s.Row, s.Lane, mode, unicode) + case "result": + // The ball path is already on screen; the settled view is just the + // prize row so the multipliers land as the last line, with no repeated + // board or number header. + return pachinkoPocketRow(s, mode) + default: + return renderPachinkoBoard(s, mode, unicode) + } +} diff --git a/internal/game/roulette_animation_test.go b/internal/game/roulette_animation_test.go index d7f5626..910e781 100644 --- a/internal/game/roulette_animation_test.go +++ b/internal/game/roulette_animation_test.go @@ -47,7 +47,7 @@ func TestRouletteSpinOutputHasNoPromptOrBlankLines(t *testing.T) { } g.CasinoTick() result := strings.ReplaceAll(string(conn.data), "\r\n", "\n") - if !strings.HasPrefix(result, "\nThe ball lands in") || g.rouletteSpinning(sess) { + if !strings.HasPrefix(result, "\nThe ball lands in") || g.casinoAnimationBusy(sess) { t.Fatalf("result did not start on a blank line or end animation: %q", result) } // A resolved spin shows the result and the next-spin menu, but not the |
