diff options
Diffstat (limited to 'internal/casino/types.go')
| -rw-r--r-- | internal/casino/types.go | 114 |
1 files changed, 100 insertions, 14 deletions
diff --git a/internal/casino/types.go b/internal/casino/types.go index f284869..1c4326a 100644 --- a/internal/casino/types.go +++ b/internal/casino/types.go @@ -1,20 +1,73 @@ package casino -import "fmt" - type GameName string const ( - GameSlots GameName = "slots" + GameSlots GameName = "slots" + GameBlackjack GameName = "blackjack" ) +type BlackjackConfig struct { + Decks int `yaml:"decks,omitempty"` + ShuffleAt float64 `yaml:"shuffle_at,omitempty"` + BlackjackPayout float64 `yaml:"blackjack_payout,omitempty"` + DealerHitSoft17 *bool `yaml:"dealer_hit_soft_17,omitempty"` + MaxSplitHands int `yaml:"max_split_hands,omitempty"` + ResplitAces *bool `yaml:"resplit_aces,omitempty"` + DoubleAfterSplit *bool `yaml:"double_after_split,omitempty"` + DoubleSplitBlackjack *bool `yaml:"double_split_blackjack,omitempty"` + InsurancePayout float64 `yaml:"insurance_payout,omitempty"` + Surrender *bool `yaml:"surrender,omitempty"` + ActionTicks int `yaml:"action_ticks,omitempty"` + SplitUnlikeTenValues *bool `yaml:"split_unlike_ten_values,omitempty"` +} + +func ruleBool(value *bool, defaultValue bool) bool { + if value == nil { + return defaultValue + } + return *value +} + +func (c BlackjackConfig) DealerHitsSoft17() bool { return ruleBool(c.DealerHitSoft17, false) } +func (c BlackjackConfig) AllowsResplitAces() bool { return ruleBool(c.ResplitAces, false) } +func (c BlackjackConfig) AllowsDoubleAfterSplit() bool { return ruleBool(c.DoubleAfterSplit, true) } +func (c BlackjackConfig) CountsDoubleSplitBlackjack() bool { + return ruleBool(c.DoubleSplitBlackjack, true) +} +func (c BlackjackConfig) AllowsSurrender() bool { return ruleBool(c.Surrender, false) } +func (c BlackjackConfig) AllowsUnlikeTenSplit() bool { return ruleBool(c.SplitUnlikeTenValues, true) } + +func (c BlackjackConfig) Normalize() BlackjackConfig { + if c.Decks <= 0 { + c.Decks = 8 + } + if c.ShuffleAt <= 0 || c.ShuffleAt >= 1 { + c.ShuffleAt = 0.25 + } + if c.BlackjackPayout <= 0 { + c.BlackjackPayout = 1.5 + } + if c.MaxSplitHands <= 0 { + c.MaxSplitHands = 4 + } + if c.InsurancePayout <= 0 { + c.InsurancePayout = 2 + } + if c.ActionTicks <= 0 { + c.ActionTicks = 20 + } + return c +} + type TableConfig struct { - ID string `yaml:"id"` - Game GameName `yaml:"game"` - MaxPlayers int `yaml:"max_players,omitempty"` - BettingTicks int `yaml:"betting_ticks,omitempty"` - MinBet int `yaml:"min_bet,omitempty"` - MaxBet int `yaml:"max_bet,omitempty"` + ID string `yaml:"id"` + Game GameName `yaml:"game"` + MaxPlayers int `yaml:"max_players,omitempty"` + BettingTicks int `yaml:"betting_ticks,omitempty"` + MinBet int `yaml:"min_bet,omitempty"` + MaxBet int `yaml:"max_bet,omitempty"` + Blackjack BlackjackConfig `yaml:"blackjack,omitempty"` } type MachineConfig struct { @@ -87,6 +140,24 @@ const ( EventClosed EventType = "closed" ) +type MenuKind string + +const ( + MenuSlotCommands MenuKind = "slot_commands" + MenuBlackjackBet MenuKind = "blackjack_bet" + MenuBlackjackTurn MenuKind = "blackjack_turn" +) + +// MenuView carries a structured menu alongside its plain-text Message so the +// presentation layer can enrich it (balances, command colors) without parsing +// message prefixes. +type MenuView struct { + Kind MenuKind + Body string // command list (MenuSlotCommands) + Title string // prompt heading (MenuBlackjackTurn) + Actions []string // available commands (MenuBlackjackTurn) +} + type Event struct { RoomID int TableID string @@ -98,6 +169,8 @@ type Event struct { Color string Public bool Slot *SlotSnapshot + Blackjack *BlackjackSnapshot + Menu *MenuView } type SlotSnapshot struct { @@ -105,11 +178,24 @@ type SlotSnapshot struct { StoppedReels int } -func (e Event) String() string { - if e.Message != "" { - return e.Message - } - return fmt.Sprintf("%s at %s", e.Type, e.TableID) +type BlackjackCardView struct { + Rank string + Suit string + Hidden bool +} + +type BlackjackPlayerView struct { + Name string + Cards []BlackjackCardView + Score string +} + +type BlackjackSnapshot struct { + Dealer []BlackjackCardView + DealerShownScore string + DealerScore string + DealerRevealed bool + Players []BlackjackPlayerView } type Participant struct { |
