diff options
| author | historia <[not public]> | 2026-10-03 07:11:58 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-03 07:11:58 -0400 |
| commit | 0fb83bdf433b9b48240f4ac7a5d4c912f6b808cc (patch) | |
| tree | ac0af51cc2513b1ddd8a280f360af820d1f097af /internal/game | |
| parent | 6232d41e5639f9c38e47b2bb65266e343ca26e8f (diff) | |
| download | thehouseoficarus-0fb83bdf433b9b48240f4ac7a5d4c912f6b808cc.tar.gz | |
feat: added big 6 wheel to the casino
Diffstat (limited to 'internal/game')
| -rw-r--r-- | internal/game/big_six_test.go | 222 | ||||
| -rw-r--r-- | internal/game/blackjack_rules.go | 4 | ||||
| -rw-r--r-- | internal/game/casino.go | 35 | ||||
| -rw-r--r-- | internal/game/casino_ux.go | 8 | ||||
| -rw-r--r-- | internal/game/casino_ux_test.go | 51 | ||||
| -rw-r--r-- | internal/game/cmd_registry.go | 99 | ||||
| -rw-r--r-- | internal/game/core_login_char.go | 4 | ||||
| -rw-r--r-- | internal/game/game.go | 16 | ||||
| -rw-r--r-- | internal/game/hardening_shutdown_save_error_test.go | 49 | ||||
| -rw-r--r-- | internal/game/look_casino.go | 2 | ||||
| -rw-r--r-- | internal/game/look_target.go | 2 | ||||
| -rw-r--r-- | internal/game/render_big_six.go | 209 |
12 files changed, 665 insertions, 36 deletions
diff --git a/internal/game/big_six_test.go b/internal/game/big_six_test.go new file mode 100644 index 0000000..6a83cdf --- /dev/null +++ b/internal/game/big_six_test.go @@ -0,0 +1,222 @@ +package game + +import ( + "strings" + "testing" + + "thehouseoficarus/internal/casino" + "thehouseoficarus/internal/color" +) + +func TestBigSixRendering(t *testing.T) { + for _, mode := range []string{"none", "ansi16", "xterm256"} { + for _, unicode := range []bool{false, true} { + s := &casino.BigSixSnapshot{Phase: "betting", Multiplier: "1", BettingTicks: 25, MinBet: 1, MaxBet: 10000} + board := renderBigSixSnapshot(s, mode, unicode) + if mode != "none" && !strings.Contains(board, "\x1b[2m") { + t.Fatal("payouts must be dim") + } + if mode == "none" && strings.Contains(board, "\x1b") { + t.Fatal("ANSI leaked into plain display") + } + for _, text := range []string{"$1", "$2", "$5", "$10", "$20", "SWORD", "SHIELD", "DOUBLE", "pays 47:1", "Bets:"} { + if !strings.Contains(board, text) { + t.Fatalf("missing %q: %s", text, board) + } + } + for _, gone := range []string{"B I G", "RTP", "Place any number", "Odds are profit", "double & respin"} { + if strings.Contains(board, gone) { + t.Fatalf("stale felt text %q: %s", gone, board) + } + } + if unicode && !strings.ContainsAny(board, "─│┌╭") { + t.Fatalf("Unicode felt is still ASCII: %s", board) + } + if !unicode && strings.ContainsAny(board, "─│┌╭") { + t.Fatalf("ASCII felt leaked Unicode: %s", board) + } + for _, phase := range []string{"playing", "result"} { + s.Phase = phase + s.Pockets = []string{"1", "2", "5", "10", "DOUBLE", "20", "SWORD", "SHIELD", "1"} + if phase == "playing" { + s.Pockets = append(s.Pockets, "1", "2") + } + text := renderBigSixSnapshot(s, mode, unicode) + if strings.Count(text, "\n") < 5 { + t.Fatal("not a multi-line wheel", text) + } + wall := "|" + if unicode { + wall = "│" + } + // The bill outline must continue through the number row. + bill := wall + " $1 " + if phase == "result" { + bill = wall + " $1 " + wall + } else { + bill = wall + " $1 " + wall + } + if !strings.Contains(text, bill) { + t.Fatalf("number row is missing the bill walls (%q): %s", bill, text) + } + // Every rail and separator uses the same dim-yellow border ink. + if mode != "none" { + yellow := color.Render(mode, color.ColorSpec{Fg: 3, Bg: -1, Dim: true}, wall) + if !strings.Contains(text, yellow) { + t.Fatalf("wheel separators are not the yellow border color: %s", text) + } + } + for _, line := range strings.Split(text, "\n") { + if color.VisibleLen(line) > 80 { + t.Fatalf("frame too wide (%d): %s", color.VisibleLen(line), line) + } + } + pointer := "\\/" + if unicode { + pointer = "▼" + } + if !strings.Contains(text, pointer) { + t.Fatal("no pointer") + } + if strings.ContainsAny(text, "◆") { + t.Fatalf("second pointer glyph still present: %s", text) + } + if strings.Contains(text, "* * *") || strings.Contains(text, "[ STOP ]") { + t.Fatalf("stale wheel result art: %s", text) + } + if phase == "result" { + lines := strings.Split(strings.TrimRight(text, " \n"), "\n") + if !strings.Contains(lines[len(lines)-1], "WINNER") { + t.Fatalf("WINNER must print below the entire wheel: %s", text) + } + } + } + for _, line := range strings.Split(board, "\n") { + if color.VisibleLen(line) > 80 { + t.Fatalf("felt too wide (%d): %s", color.VisibleLen(line), line) + } + if strings.Contains(line, "pays 23:1") && mode != "none" { + // The box walls stay bold; only the payout text is dim. + if !strings.Contains(line, "\x1b[1m") || !strings.Contains(line, "\x1b[2m") { + t.Fatalf("pays row walls/text have the wrong weight: %q", line) + } + } + } + } + } +} + +func TestBigSixUnicodeArtwork(t *testing.T) { + // Check the rendered cells, not just the source art: independent row + // centering must not misalign the blade or disconnect shield corners. + for _, tt := range []struct { + label string + want []string + }{ + {"SWORD", []string{ + "│ ▲ │", + "│ ║ │", + "│ ║ │", + "│ ╘══╬══╛ │", + "│ ╩ │", + }}, + {"SHIELD", []string{ + "│ ╭───────╮ │", + "│ │ ◇ │ │", + "│ ╰╮ ╭╯ │", + "│ ╰╮ ╭╯ │", + "│ ╰───╯ │", + }}, + } { + t.Run(tt.label, func(t *testing.T) { + panel := bigSixPanel(casino.BigSixSpot{Label: tt.label, Pays: 47}, 24, "none", true) + if got, want := strings.Join(panel[2:7], "\n"), strings.Join(tt.want, "\n"); got != want { + t.Fatalf("table artwork:\n%s\nwant:\n%s", got, want) + } + }) + } + + s := &casino.BigSixSnapshot{Phase: "result", Pockets: []string{"SWORD", "SHIELD"}} + lines := strings.Split(renderBigSixSnapshot(s, "none", true), "\n") + want := strings.Join([]string{ + "│ ▲ │╭─────╮│", + "│ ╘═╬═╛ │╰╮ ◇ ╭╯│", + "│ ╩ │ ╰───╯ │", + "│ SWORD │SHIELD │", + }, "\n") + if got := strings.Join(lines[2:6], "\n"); got != want { + t.Fatalf("wheel artwork:\n%s\nwant:\n%s", got, want) + } +} + +func TestBigSixSpinAbbreviation(t *testing.T) { + // "sp" is the blackjack split shorthand. Split is not a Big 6 command, so + // the abbreviation must instead match the only relevant verb: spin. + g, sess, _ := houseEdgeGame(t, "name: Wheel\ncasino_tables:\n - id: big6\n game: big6\n") + g.queue = NewCommandQueue() + g.executePlay(sess, []string{"big6"}, "play big6") + g.executeBet(sess, []string{"2", "on", "1"}, "bet 2 on 1") + if got, ok := g.casinoAbbreviation(sess, "sp"); !ok || got != "spin" { + t.Fatalf("sp at Big 6 resolved to %q (ok=%v), want spin", got, ok) + } + // Prefixes of other games' verbs (split, roll, hit, double) must not + // resolve at this table. + for _, input := range []string{"spl", "spli", "ro", "hi", "dd"} { + if got, ok := g.casinoAbbreviation(sess, input); ok { + t.Fatalf("Big 6 %q unexpectedly abbreviated to %q", input, got) + } + } + g.handleGameCommand(sess, "sp") + if qc, ok := g.queue.PeekActive("alice"); !ok || qc.Command != "spin" { + t.Fatalf("sp queued %+v (ok=%v), want spin", qc, ok) + } +} + +func TestBigSixCommandsAndVisibility(t *testing.T) { + g, sess, conn := houseEdgeGame(t, "name: Wheel\ncasino_tables:\n - id: big6\n game: big6\n") + g.executePlay(sess, []string{"big6"}, "play big6") + table, playing := g.Casino.Participation(sess.Player.Name) + if !playing || table == nil { + t.Fatal("join failed", string(conn.data)) + } + for _, target := range []string{"1", "$20", "sword", "shield"} { + g.executeBet(sess, []string{"2", "on", target}, "bet 2 on "+target) + } + if sess.Player.Credits != 92 || table.State() != "waiting" { + t.Fatal("bet/spin conflated", sess.Player.Credits, table.State(), string(conn.data)) + } + conn.data = nil + g.executeList(sess, nil, "list") + if !strings.Contains(string(conn.data), "SWORD") || !strings.Contains(string(conn.data), "47:1") { + t.Fatal("list missing targets", string(conn.data)) + } + conn.data = nil + g.executeTableStatus(sess, nil, "table") + if !strings.Contains(string(conn.data), "Bets:") { + t.Fatal("table not routed", string(conn.data)) + } + conn.data = nil + g.executeRules(sess, nil, "rules") + if !strings.Contains(string(conn.data), "48/49") { + t.Fatal("help not routed", string(conn.data)) + } + g.executeSpin(sess, nil, "spin") + if table.State() != "playing" || sess.Player.Credits != 92 { + t.Fatal("spin rebet/debit", string(conn.data)) + } + g.executeSpin(sess, nil, "spin") + if sess.Player.Credits != 92 { + t.Fatal("second spin debited") + } + beforePrompt := len(conn.data) + g.writePrompt(sess) + if len(conn.data) != beforePrompt { + t.Fatal("prompt interrupted wheel") + } + if !table.Busy(sess.Player.Name) { + t.Fatal("animation prompt handling") + } + if !g.seesCasinoDetails(sess, casino.Event{RoomID: 1, TableID: "gone", Snapshot: &casino.BigSixSnapshot{Players: []string{sess.Player.Name}}}) { + t.Fatal("departing seat cannot see final frame") + } +} diff --git a/internal/game/blackjack_rules.go b/internal/game/blackjack_rules.go index 7cea977..9e36466 100644 --- a/internal/game/blackjack_rules.go +++ b/internal/game/blackjack_rules.go @@ -22,6 +22,10 @@ func (g *Game) lookCrapsTable(sess *net.Session, target string) bool { return g.lookCasinoTable(sess, target, casino.GameCraps) } +func (g *Game) lookBigSixTable(sess *net.Session, target string) bool { + return g.lookCasinoTable(sess, target, casino.GameBigSix) +} + func (g *Game) lookRouletteTable(sess *net.Session, target string) bool { return g.lookCasinoTable(sess, target, casino.GameRoulette) } diff --git a/internal/game/casino.go b/internal/game/casino.go index 8f18614..6dce0bd 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -380,6 +380,21 @@ func (g *Game) startCasinoGame(sess *net.Session, p *player.Player, gameName str g.emitCasinoEvents(events) } +// Keep slots' spin-as-bet behavior, while Big 6 spins already committed wagers. +func (g *Game) executeSpin(sess *net.Session, args []string, rawInput string) { + if sess.Player != nil { + if table, playing := g.Casino.Participation(sess.Player.Name); playing && table != nil && table.Config.Game == casino.GameBigSix { + if len(args) != 0 { + sess.WriteLine("Use spin after placing your bets.") + return + } + g.executeTableAction(sess, "spin") + return + } + } + g.executeBet(sess, args, rawInput) +} + func (g *Game) executeBet(sess *net.Session, args []string, rawInput string) { p := sess.Player if p == nil { @@ -537,7 +552,13 @@ func (g *Game) rouletteSpinning(sess *net.Session) bool { return false } table, playing := g.Casino.Participation(sess.Player.Name) - if !playing || table == nil || table.Config.Game != casino.GameRoulette { + if !playing || table == nil { + return false + } + if table.Config.Game == casino.GameBigSix { + return table.Busy(sess.Player.Name) + } + if table.Config.Game != casino.GameRoulette { return false } s, ok := table.Board(sess.Player.Name).(*casino.RouletteSnapshot) @@ -677,8 +698,8 @@ func (g *Game) casinoHintsVisible(sess *net.Session, menu *casino.MenuView) bool } } -// casinoBoardReminder splits a persistent-board menu (craps, roulette, video -// poker, Pai Gow) so its instructions print under the board they describe. +// casinoBoardReminder splits a persistent-board menu (craps, roulette, Big 6, +// video poker, Pai Gow) so its instructions print under the board they describe. // Every other game, and compact displays, keep their menu in one block. func (g *Game) casinoBoardReminder(sess *net.Session, category string, menu *casino.MenuView, snapshot casino.Snapshot, message string) (reminder string, ok bool) { if category != "casino_menu" || menu == nil || sess.Player == nil { @@ -687,11 +708,13 @@ func (g *Game) casinoBoardReminder(sess *net.Session, category string, menu *cas _, isCraps := snapshot.(*casino.CrapsSnapshot) _, isPoker := snapshot.(*casino.VideoPokerSnapshot) _, isPaiGow := snapshot.(*casino.PaiGowSnapshot) + b, isBigSix := snapshot.(*casino.BigSixSnapshot) + isBigSix = isBigSix && b.Phase != "playing" && b.Phase != "result" s, isRoulette := snapshot.(*casino.RouletteSnapshot) - if !isPoker && !isCraps && !isPaiGow && (!isRoulette || s.Phase == "playing" || s.Phase == "result") { + if !isPoker && !isCraps && !isPaiGow && !isBigSix && (!isRoulette || s.Phase == "playing" || s.Phase == "result") { return "", false } - if !isPoker && !isCraps && !isPaiGow && sess.Player.OptionString("casino_display") == "compact" && (menu.Repeat || !menu.ShowBalance) { + if !isPoker && !isCraps && !isPaiGow && !isBigSix && sess.Player.OptionString("casino_display") == "compact" && (menu.Repeat || !menu.ShowBalance) { // The compact reminder is already a short block; leave it intact. return "", false } @@ -780,6 +803,8 @@ func (g *Game) renderCasinoSnapshot(sess *net.Session, snapshot casino.Snapshot) return renderVideoPoker(s, mode, unicode, size, sess.Player.OptionString("card_style"), g.CardArt) case *casino.CrapsSnapshot: return renderCrapsSnapshot(s, mode, unicode, sess.Player.OptionString("card_style")) + case *casino.BigSixSnapshot: + return renderBigSixSnapshot(s, mode, unicode) case *casino.RouletteSnapshot: return renderRouletteSnapshot(s, mode, unicode, size) case *casino.SlotSnapshot: diff --git a/internal/game/casino_ux.go b/internal/game/casino_ux.go index e44da54..bc1906f 100644 --- a/internal/game/casino_ux.go +++ b/internal/game/casino_ux.go @@ -66,6 +66,8 @@ func resolveCasinoChoice(choices []casinoChoice, input string) (casinoChoice, bo func casinoTableAliases(cfg casino.TableConfig) []string { names := []string{string(cfg.Game)} switch cfg.Game { + case casino.GameBigSix: + names = append(names, "big-six", "big_six", "big six", "big 6") case casino.GameBlackjack: names = append(names, "bj") case casino.GameBaccarat: @@ -235,6 +237,12 @@ func (g *Game) seesCasinoDetails(sess *net.Session, event casino.Event) bool { return true } } + case *casino.BigSixSnapshot: + for _, name := range s.Players { + if name == sess.Player.Name { + return true + } + } case *casino.RouletteSnapshot: for _, name := range s.Players { if name == sess.Player.Name { diff --git a/internal/game/casino_ux_test.go b/internal/game/casino_ux_test.go index c83db27..423469c 100644 --- a/internal/game/casino_ux_test.go +++ b/internal/game/casino_ux_test.go @@ -93,23 +93,64 @@ func TestCasinoCommandAbbreviations(t *testing.T) { } g.executePlay(sess, []string{"bj"}, "play bj") for input, want := range map[string]string{ - "b": "bet", "be": "bet", "spl": "split", "su": "surrender", - "ins": "insurance", "ro": "roll", "wa": "watch", "ta": "table", - "li": "list", "ga": "game", + "b": "bet", "be": "bet", "spl": "split", "sp": "split", "su": "surrender", + "ins": "insurance", "wa": "watch", "ta": "table", + "li": "list", "ga": "game", "sto": "stop", "ru": "rules", + // The terse aliases resolve only because their verb is a blackjack verb. + "h": "hit", "st": "stand", "dd": "double", } { got, ok := g.casinoAbbreviation(sess, input) if !ok || got != want { t.Fatalf("%q resolved to %q (ok=%v), want %q", input, got, ok, want) } } - // stop and rules are full-word only, and movement keeps its own keys. - for _, input := range []string{"sto", "r", "ru", "n", "s"} { + // No other game's verbs leak into a blackjack table. + for _, input := range []string{"ro", "rol", "ra", "au", "dr", "pa", "ha", "ho"} { + if got, ok := g.casinoAbbreviation(sess, input); ok { + t.Fatalf("blackjack %q unexpectedly abbreviated to %q", input, got) + } + } + // Exact commands keep their meaning: movement, info, and whole words that + // are already real commands. + for _, input := range []string{"n", "s", "e", "w", "i", "l", "hit"} { if got, ok := g.casinoAbbreviation(sess, input); ok { t.Fatalf("%q unexpectedly abbreviated to %q", input, got) } } } +func TestCasinoAbbreviationsAreGameScoped(t *testing.T) { + // Baccarat has neither split nor spin, so "sp" matches nothing there. + g, sess, _ := uxCasinoGame(t) + g.executePlay(sess, []string{"bac"}, "play bac") + for _, input := range []string{"sp", "spl", "ro", "au"} { + if got, ok := g.casinoAbbreviation(sess, input); ok { + t.Fatalf("baccarat %q unexpectedly abbreviated to %q", input, got) + } + } + if got, ok := g.casinoAbbreviation(sess, "be"); !ok || got != "bet" { + t.Fatalf("baccarat be resolved to %q (ok=%v), want bet", got, ok) + } + + // Craps owns roll/autoroll; a blackjack table must not resolve them. + g2, sess2, _ := casinoCrapsGame(t, "name: Pit\ncasino_tables:\n - id: cr\n game: craps\n") + g2.executePlay(sess2, []string{"craps"}, "play craps") + if got, ok := g2.casinoAbbreviation(sess2, "ro"); !ok || got != "roll" { + t.Fatalf("craps ro resolved to %q (ok=%v), want roll", got, ok) + } + if got, ok := g2.casinoAbbreviation(sess2, "rol"); !ok || got != "roll" { + t.Fatalf("craps rol resolved to %q (ok=%v), want roll", got, ok) + } + if got, ok := g2.casinoAbbreviation(sess2, "au"); !ok || got != "autoroll" { + t.Fatalf("craps au resolved to %q (ok=%v), want autoroll", got, ok) + } + for _, input := range []string{"sp", "spl", "ins", "su"} { + if got, ok := g2.casinoAbbreviation(sess2, input); ok { + t.Fatalf("craps %q unexpectedly abbreviated to %q", input, got) + } + } +} + func TestAbbreviatedCasinoCommandReachesQueue(t *testing.T) { g, sess, _ := uxCasinoGame(t) g.queue = NewCommandQueue() diff --git a/internal/game/cmd_registry.go b/internal/game/cmd_registry.go index 710dd92..5b60118 100644 --- a/internal/game/cmd_registry.go +++ b/internal/game/cmd_registry.go @@ -70,7 +70,7 @@ var commandRegistry = map[string]commandDef{ "dd": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "double") }, ClassActive}, "sp": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "split") }, ClassActive}, "bet": {(*Game).executeBet, ClassActive}, - "spin": {(*Game).executeBet, ClassActive}, + "spin": {(*Game).executeSpin, ClassActive}, "autobet": {(*Game).executeAutoBet, ClassActive}, "autospin": {(*Game).executeAutoBet, ClassActive}, "hit": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "hit") }, ClassActive}, @@ -240,35 +240,96 @@ func classifyCommand(cmd string) CommandClass { return ClassUnknown } -// casinoShortVerbs are the casino verbs a seated player may abbreviate to an -// unambiguous prefix. "stop" and "rules" are deliberately absent: their -// prefixes (st, r, ru) would otherwise shadow stand and movement, so those two -// commands must be typed in full. -var casinoShortVerbs = []string{ - "bet", "deal", "draw", "hold", "paytable", "denom", "denomination", - "hands", "feature", "game", "roll", "autoroll", "unbet", "table", - "status", "list", "watch", "decline", "hit", "stand", - "double", "split", "insurance", "surrender", "spin", "autobet", - "autospin", "rebet", +// casinoCommonVerbs are the generic controls a seated player may abbreviate +// at any casino game; they are not tied to one game's rules. +var casinoCommonVerbs = []string{"watch", "game", "table", "list", "stop", "rules"} + +// casinoVerbsByGame scopes the rest of the abbreviable verbs to the game the +// player is actually in. A prefix can therefore never match another game's +// command: "sp" is split at a blackjack table, but spin at a Big 6 wheel, +// because "split" is not a Big 6 verb and "spin" is not a blackjack verb. +var casinoVerbsByGame = map[casino.GameName][]string{ + casino.GameBlackjack: {"bet", "rebet", "unbet", "hit", "stand", "double", "split", "insurance", "surrender", "decline"}, + casino.GameBaccarat: {"bet", "rebet", "unbet"}, + casino.GameRoulette: {"bet", "rebet", "unbet"}, + casino.GameCraps: {"bet", "rebet", "unbet", "roll", "autoroll"}, + casino.GamePaiGow: {"bet", "rebet", "unbet"}, + casino.GameVideoPoker: {"bet", "deal", "draw", "hold", "paytable", "denom", "denomination", "hands", "feature"}, + casino.GameSlots: {"bet", "spin", "autospin", "autobet"}, + casino.GameBigSix: {"bet", "rebet", "unbet", "spin"}, +} + +// casinoShortAliases maps the registry's terse aliases onto the verb they +// stand for. An alias only applies when its verb belongs to the current game; +// otherwise the letters are re-read as a fresh prefix, so "sp" is split at a +// blackjack table and spin at a Big 6 wheel. +var casinoShortAliases = map[string]string{ + "h": "hit", "st": "stand", "dd": "double", "sp": "split", +} + +// casinoVerbsFor returns the game-scoped verb vocabulary for a seated player, +// or nil when they are not in a casino game. +func (g *Game) casinoVerbsFor(name string) []string { + if g.Casino == nil { + return nil + } + table, playing := g.Casino.Participation(name) + if !playing { + return nil + } + var game casino.GameName + switch { + case table != nil: + game = table.Config.Game + default: + machine, ok := g.Casino.MachineFor(name) + if !ok { + return nil + } + game = machine.Config.Game + } + verbs := append([]string(nil), casinoCommonVerbs...) + return append(verbs, casinoVerbsByGame[game]...) } -// casinoAbbreviation resolves a seated casino player's unambiguous command -// prefix to its full verb. An exact command (including the h/st/dd/sp aliases -// and video poker's d) always wins, so a prefix never shadows a real command; -// an ambiguous prefix resolves to nothing and falls through unchanged. +// casinoAbbreviation resolves a seated casino player's partial command to the +// closest verb that is actually relevant to the game they are in. Exact +// commands always win, so movement, look and the game's own real verbs are +// never shadowed; a short alias applies only when its verb belongs to this +// game; an ambiguous prefix resolves to nothing and falls through unchanged. func (g *Game) casinoAbbreviation(sess *net.Session, cmd string) (string, bool) { - if sess == nil || sess.Player == nil || cmd == "" || !g.inCasinoGame(sess.Player.Name) { + if sess == nil || sess.Player == nil || cmd == "" { + return "", false + } + verbs := g.casinoVerbsFor(sess.Player.Name) + if len(verbs) == 0 { return "", false } - if _, ok := commandRegistry[cmd]; ok { + // A real casino verb needs no abbreviation: the registry dispatches it. + for _, verb := range verbs { + if verb == cmd { + return "", false + } + } + if target, ok := casinoShortAliases[cmd]; ok { + for _, verb := range verbs { + if verb == target { + return target, true + } + } + // The alias names another game's verb: fall through and read the + // letters as a prefix of this game's vocabulary instead. + } else if _, ok := commandRegistry[cmd]; ok { + // Any other real command (movement, look, inventory, ...) wins over a + // casino prefix. return "", false } match := "" - for _, verb := range casinoShortVerbs { + for _, verb := range verbs { if !strings.HasPrefix(verb, cmd) { continue } - if match != "" { + if match != "" && match != verb { return "", false } match = verb diff --git a/internal/game/core_login_char.go b/internal/game/core_login_char.go index 41e25b8..479e397 100644 --- a/internal/game/core_login_char.go +++ b/internal/game/core_login_char.go @@ -111,6 +111,10 @@ func (g *Game) connectCharacter(sess *net.Session, name string) { g.showMenu(sess) return } + // Log the disk state before identity backfill, missing-room rescue, or + // recording this login's visit can change it. Paired with shutdown saves, + // this distinguishes lost saves from loading a different/older file. + log.Printf("character loaded: %s room=%d explored=%d file=%s", p.Name, p.RoomID, p.Stats.RoomsVisited.Len(), g.AccountStore.CharPath(name)) g.adoptCharacterIdentity(p, sess.Account.Name) if g.Hub != nil { diff --git a/internal/game/game.go b/internal/game/game.go index e5192c0..a3a9684 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -343,8 +343,13 @@ func (g *Game) saveAllOnlineCharacters() error { if p := sess.Player; p != nil { g.restoreGodPlayer(p) g.persistLockedOnDisconnect(p) - if err := g.AccountStore.SaveCharacter(p); err != nil && firstErr == nil { - firstErr = fmt.Errorf("save %s: %w", p.Name, err) + if err := g.AccountStore.SaveCharacter(p); err != nil { + if firstErr == nil { + firstErr = fmt.Errorf("save %s: %w", p.Name, err) + } + log.Printf("shutdown: character save failed: %s: %v", p.Name, err) + } else { + log.Printf("shutdown: character saved: %s room=%d explored=%d file=%s", p.Name, p.RoomID, p.Stats.RoomsVisited.Len(), g.AccountStore.CharPath(p.Name)) } } } @@ -619,9 +624,10 @@ func (g *Game) handleGameCommand(sess *net.Session, input string) { } cmd := parts[0] - // Seated casino players may shorten any casino verb to an unambiguous - // prefix (b 1000 -> bet 1000). Exact commands always win, so movement and - // the existing short aliases are never shadowed. + // Seated casino players may shorten any of their game's verbs to an + // unambiguous prefix (b 1000 -> bet 1000, sp -> spin at Big 6). Only the + // current game's vocabulary is considered, and exact commands still win, so + // movement and non-casino commands are never shadowed. if canon, ok := g.casinoAbbreviation(sess, cmd); ok { cmd = canon parts[0] = canon diff --git a/internal/game/hardening_shutdown_save_error_test.go b/internal/game/hardening_shutdown_save_error_test.go index c75f6fc..5842f9b 100644 --- a/internal/game/hardening_shutdown_save_error_test.go +++ b/internal/game/hardening_shutdown_save_error_test.go @@ -7,10 +7,59 @@ package game import ( "os" "path/filepath" + "reflect" "strings" "testing" + "time" + + "thehouseoficarus/internal/player" ) +func TestShutdownPreservesOnlineLocationAndExploration(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice") + p := h.seedCharacter("alice", "alice") + p.RoomID = 6101 + p.Stats.RecordRoomVisit(6101) + if err := h.g.AccountStore.SaveCharacter(p); err != nil { + t.Fatal(err) + } + sess, _ := h.connect("alice") + wantRooms := []int{6101, 6182, 6183, 6199} + h.g.RunOnOwner(func() { + sess.Player.RoomID = 6199 + for _, id := range wantRooms { + sess.Player.Stats.RecordRoomVisit(id) + } + }) + // Deliberately leave disk at the older state. The signal shutdown path + // must persist the connected character before closing the transport, + // without requiring the player to quit or disconnect first. + var saved *player.Player + var loadErr error + h.g.SetTransportStop(func() { + saved, loadErr = player.NewAccountStore(h.dir).LoadCharacter("alice") + }) + h.g.RequestShutdown("signal") + select { + case <-h.g.ShutdownDone(): + case <-time.After(5 * time.Second): + t.Fatal("shutdown did not finish") + } + if err := h.g.ShutdownSaveError(); err != nil { + t.Fatal(err) + } + if loadErr != nil { + t.Fatal(loadErr) + } + if saved == nil { + t.Fatal("transport stop was not called") + } + if saved.RoomID != 6199 || !reflect.DeepEqual(saved.Stats.RoomsVisited.Keys(), wantRooms) { + t.Fatalf("shutdown lost progress: room=%d explored=%v", saved.RoomID, saved.Stats.RoomsVisited.Keys()) + } +} + // TestShutdownSaveErrorReportsFailedFinalSave makes the character save fail // (the character file is replaced by a directory, so the atomic replace cannot // land) and requires the shutdown sequence to record the failure on the Game. diff --git a/internal/game/look_casino.go b/internal/game/look_casino.go index 8d2b5c3..ec9ab61 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: + case casino.GameRoulette, casino.GameBigSix: // 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 != "" { diff --git a/internal/game/look_target.go b/internal/game/look_target.go index d296b35..9065ccc 100644 --- a/internal/game/look_target.go +++ b/internal/game/look_target.go @@ -47,7 +47,7 @@ func (g *Game) doLookTarget(sess *net.Session, input string) { return } - if g.lookBlackjackTable(sess, lower) || g.lookBaccaratTable(sess, lower) || g.lookRouletteTable(sess, lower) || g.lookCrapsTable(sess, lower) || g.lookPaiGowTable(sess, lower) || g.lookVideoPokerCabinet(sess, lower) { + if g.lookBigSixTable(sess, lower) || g.lookBlackjackTable(sess, lower) || g.lookBaccaratTable(sess, lower) || g.lookRouletteTable(sess, lower) || g.lookCrapsTable(sess, lower) || g.lookPaiGowTable(sess, lower) || g.lookVideoPokerCabinet(sess, lower) { return } diff --git a/internal/game/render_big_six.go b/internal/game/render_big_six.go new file mode 100644 index 0000000..19579f0 --- /dev/null +++ b/internal/game/render_big_six.go @@ -0,0 +1,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() +} |
