diff options
| author | historia <[not public]> | 2026-09-19 01:55:34 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-19 01:55:34 -0400 |
| commit | cc33072eced3d5460512c09c42ec4531c807d7af (patch) | |
| tree | b1b451fa87fa389cb8343a3645372f3b43f5523e /internal/casino/registry.go | |
| parent | 2c38386484cdb507c4687caceb37e0b963e33594 (diff) | |
| download | thehouseoficarus-cc33072eced3d5460512c09c42ec4531c807d7af.tar.gz | |
fix: casino stake preservation, world state reconciliation, casino game registration
Diffstat (limited to 'internal/casino/registry.go')
| -rw-r--r-- | internal/casino/registry.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/casino/registry.go b/internal/casino/registry.go new file mode 100644 index 0000000..9a973d4 --- /dev/null +++ b/internal/casino/registry.go @@ -0,0 +1,59 @@ +package casino + +import "math/rand" + +// tableGameDef is the single registration point for a multiplayer table game. +// A game's validation, rule defaults, and constructor live together here, so +// adding a game is one entry instead of edits to three independent switches +// (TableConfig.Validate, TableConfig.Normalize, and newTable) that could +// silently drift apart. The rule structs stay on TableConfig; this does not +// introduce a config union. +type tableGameDef struct { + // validate checks a raw (pre-Normalize) table config. + validate func(TableConfig) error + // normalize applies this game's rule defaults to a table config. + normalize func(TableConfig) TableConfig + // new builds the game. It is called only after validate passes and the + // shared table config has been normalized. + new func(roomID int, cfg TableConfig, rng *rand.Rand) tableGame +} + +// tableGames is populated in init, not in a var initializer: the constructors +// transitively call TableConfig.Normalize, which consults tableGames, and Go +// rejects that as an initialization cycle when the map is a literal. +var tableGames map[GameName]tableGameDef + +func init() { + tableGames = map[GameName]tableGameDef{ + GameBlackjack: { + validate: validateBlackjackTable, + normalize: normalizeBlackjackTable, + new: func(roomID int, cfg TableConfig, rng *rand.Rand) tableGame { + return newBlackjackTable(roomID, cfg, rng) + }, + }, + GameBaccarat: { + validate: validateBaccaratTable, + normalize: normalizeBaccaratTable, + new: func(roomID int, cfg TableConfig, rng *rand.Rand) tableGame { + return newBaccaratTable(roomID, cfg, rng) + }, + }, + } +} + +// tableGameDefFor returns the registration for a game, or false when the game +// has no multiplayer table implementation. +func tableGameDefFor(game GameName) (tableGameDef, bool) { + def, ok := tableGames[game] + return def, ok +} + +// slotVariants maps a machine variant name to the profile that variant plays. +// This is the content seam for a new slot cabinet: a variant is a profile +// lookup, not a new code path through Validate and the machine constructor. +// The map is shared by MachineConfig.Validate and machineSlotProfile so the +// accepted set and the played set cannot disagree. +var slotVariants = map[string]func() SlotProfile{ + "huff_and_even_more_puff": DefaultHuffAndPuffProfile, +} |
