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, }