blackjack

package
v0.0.0-...-fd03e07 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONFIG_FILE_NAME = "config"
)
View Source
const (
	PluginName = "blackjack"
)

Variables

View Source
var (
	ErrAllPlayersBusted    = errors.New("all players have busted. The dealer wins.")
	ErrCannotDoubleDown    = errors.New("you cannot double down on this hand.")
	ErrCannotSplit         = errors.New("you cannot split this hand.")
	ErrCannotSurrender     = errors.New("you cannot surrender this hand.")
	ErrGameActive          = errors.New("the game has already started.")
	ErrGameFull            = errors.New("the game is already full.")
	ErrGameNotStarted      = errors.New("the blackjack game has not started yet. Please wait for the game to start before joining.")
	ErrGameStarted         = errors.New("an active blackjack game already exists.")
	ErrNoActiveGame        = errors.New("there is no active blackjack game. Please start a new game to play.")
	ErrNotActivePlayer     = errors.New("you are not the active player.")
	ErrPlayerAlreadyInGame = errors.New("you already joined the game.")
	ErrPlayerNotFound      = errors.New("player not found in the game.")
)

Functions

func GetHandValue

func GetHandValue(hand *bj.Hand, hidden bool) string

GetHandValue returns a string representation of the hand value using the provided symbols.

func SetDB

func SetDB(d *mongo.MongoDB)

SetDB sets the database to be used by the slots system. This is used for testing.

func Start

func Start()

Start creates and registers the plugin for the slots system

Types

type Action

type Action int
const (
	Hit Action
	Stand
	DoubleDown
	Split
	Surrender
)

func (Action) String

func (a Action) String() string

String returns a string representation of the Action type for logging and debugging purposes.

type ChipManager

type ChipManager struct {
	// contains filtered or unexported fields
}

ChipManager manages the chips for a blackjack player using a bank account.

func NewChipManager

func NewChipManager(game *Game, memberID string) *ChipManager

NewChipManager returns a new ChipManager for the given guild and member.

func (*ChipManager) AddChips

func (c *ChipManager) AddChips(amount int)

AddChips adds the specified amount of chips to the player's account.

func (*ChipManager) DeductChips

func (c *ChipManager) DeductChips(amount int) error

DeductChips deducts the specified amount of chips from the player's account.

func (*ChipManager) GetChips

func (c *ChipManager) GetChips() int

GetChips returns the current number of chips the player has.

func (*ChipManager) HasEnoughChips

func (c *ChipManager) HasEnoughChips(amount int) bool

HasEnoughChips checks if the player has enough chips for the specified amount.

func (*ChipManager) SetChips

func (c *ChipManager) SetChips(amount int)

SetChips sets the number of chips the player has. This is a no-op since chips are managed via the bank account.

type Config

type Config struct {
	ID                primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	GuildID           string             `json:"guild_id" bson:"guild_id"`
	MaxPlayers        int                `json:"max_players" bson:"max_players"`
	Decks             int                `json:"decks" bson:"decks"`
	BetAmount         int                `json:"bet_amount" bson:"bet_amount"`
	DelayBetweenGames time.Duration      `json:"delay_between_games" bson:"delay_between_games"`
	WaitForPlayers    time.Duration      `json:"wait_for_players" bson:"wait_for_players"`
	PlayerTimeout     time.Duration      `json:"player_timeout" bson:"player_timeout"`
	ShowPlayerTurn    time.Duration      `json:"show_player_turn" bson:"show_player_turn"`
	ShowDealerTurn    time.Duration      `json:"show_dealer_turn" bson:"show_dealer_turn"`
	PayoutPercent     int                `json:"payout_percent" bson:"payout_percent"`
	SinglePlayerMode  bool               `json:"single_player_mode" bson:"single_player_mode"`
}

Config holds the configuration settings for the blackjack game.

func GetConfig

func GetConfig(guildID string) *Config

GetConfig retrieves the blackjack configuration, either from a file or defaults.

func (*Config) String

func (c *Config) String() string

String returns a string representation of the Config struct.

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game represents a blackjack game for a specific guild.

func GetGame

func GetGame(guildID string, uid string) *Game

GetGame retrieves the blackjack game for the specified guild. If no game exists, a new one is created.

func StartGame

func StartGame(guildID string, memberID string) (*Game, error)

StartGame starts a new blackjack game for the specified guild and member.

func (*Game) DealInitialCards

func (g *Game) DealInitialCards() error

DealInitialCards deals the initial cards to all players and the dealer.

func (*Game) Dealer

func (g *Game) Dealer() *bj.Dealer

Dealer returns the dealer of the blackjack game.

func (*Game) DealerPlay

func (g *Game) DealerPlay() error

DealerPlay processes the dealer's play according to blackjack rules.

func (*Game) EndRound

func (g *Game) EndRound()

EndRound ends the current round of blackjack for the guild, removing all players from the game.

func (*Game) EvaluateHand

func (g *Game) EvaluateHand(hand *bj.Hand) bj.GameResult

EvaluateHand evaluates the result of a specific hand for a player.

func (*Game) GetActivePlayer

func (g *Game) GetActivePlayer() *bj.Player

GetACtivePlayer retrieves the currently active player in the blackjack game.

func (*Game) GetPlayer

func (g *Game) GetPlayer(memberID string) *bj.Player

GetPlayer retrieves a player from the blackjack game by their member ID.

func (*Game) IsDealingHands

func (g *Game) IsDealingHands() bool

IsDealingHands returns whether the blackjack game is currently dealing initial hands to players.

func (*Game) IsStartingRound

func (g *Game) IsStartingRound() bool

IsStartingRound returns whether the blackjack game is in the process of starting a new round, which occurs after the initial hands have been dealt and before player turns begin.

func (*Game) IsWaitingForPlayers

func (g *Game) IsWaitingForPlayers() bool

IsWaitingForPlayers returns whether the blackjack game is waiting for players to join.

func (*Game) Lock

func (g *Game) Lock()

Lock locks the game's mutex.

func (*Game) NotStarted

func (g *Game) NotStarted() bool

NotStarted returns whether the blackjack game has not yet started.

func (*Game) PayoutResults

func (g *Game) PayoutResults()

PayoutResults pays out the results of the blackjack game.

func (*Game) PlayerActionRequest

func (g *Game) PlayerActionRequest(memberID string, action Action) error

PlayerActionRequest processes a request from a player to take an action, ensuring that the player is active and the game is in progress.

func (*Game) PlayerDoubleDown

func (g *Game) PlayerDoubleDown(player *bj.Player) error

PlayerDoubleDown processes a double down hit action for the specified player.

func (*Game) PlayerHit

func (g *Game) PlayerHit(player *bj.Player) error

PlayerHit processes a hit action for the specified player.

func (*Game) PlayerSplit

func (g *Game) PlayerSplit(player *bj.Player) error

PlayerSplit processes a split action for the specified player.

func (*Game) PlayerStand

func (g *Game) PlayerStand(player *bj.Player) error

PlayerStand processes a stand action for the specified player.

func (*Game) PlayerSurrender

func (g *Game) PlayerSurrender(player *bj.Player) error

PlayerSurrender processes a surrender action for the specified player.

func (*Game) Players

func (g *Game) Players() []*bj.Player

Players returns a slice of all players in the blackjack game.

func (*Game) Round

func (g *Game) Round() int

Round returns the current round number of the blackjack game.

func (*Game) SecondsBeforeStart

func (g *Game) SecondsBeforeStart() int

SecondsBeforeStart returns the number of seconds remaining to wait for players before starting the game. If the wait time has elapsed, it returns 0.

func (*Game) SetState

func (g *Game) SetState(state GameState)

SetState sets the current state of the blackjack game.

func (*Game) StartNewRound

func (g *Game) StartNewRound() error

StartNewRound starts a new round of blackjack in the game.

func (*Game) Unlock

func (g *Game) Unlock()

Unlock unlocks the game's mutex.

type GameState

type GameState int
const (
	NotStarted GameState
	WaitingForPlayers
	StartingRound
	DealingHands
)

func (GameState) String

func (s GameState) String() string

String returns a string representation of the GameState type for logging and debugging purposes.

type Member

type Member struct {
	ID           primitive.ObjectID `json:"id" bson:"_id,omitempty"`
	GuildID      string             `json:"guild_id" bson:"guild_id"`
	MemberID     string             `json:"member_id" bson:"member_id"`
	RoundsPlayed int                `json:"rounds_played" bson:"rounds_played"`
	HandsPlayed  int                `json:"hands_played" bson:"hands_played"`
	Wins         int                `json:"wins" bson:"wins"`
	Losses       int                `json:"losses" bson:"losses"`
	Pushes       int                `json:"pushes" bson:"pushes"`
	Blackjacks   int                `json:"blackjacks" bson:"blackjacks"`
	Splits       int                `json:"splits" bson:"splits"`
	Surrenders   int                `json:"surrenders" bson:"surrenders"`
	CreditsBet   int                `json:"credits_bet" bson:"credits_bet"`
	CreditsWon   int                `json:"credits_won" bson:"credits_won"`
	CreditsLost  int                `json:"credits_lost" bson:"credits_lost"`
	LastPlayed   time.Time          `json:"last_played" bson:"last_played"`
}

Member represents a member's statistics for the blackjack game.

func GetMember

func GetMember(guildID, userID string) *Member

GetMember retrieves the member statistics for a specific guild and user. If the member does not exist, a new member is created and returned.

func (*Member) RoundPlayed

func (m *Member) RoundPlayed(game *Game, player *bj.Player)

RoundPlayed updates the member statistics based on the results of a played round.

func (*Member) String

func (m *Member) String() string

String returns a string representation of the Member struct.

type Plugin

type Plugin struct{}

Plugin is the plugin for the slots system used by the bot

func (*Plugin) GetAdminHelp

func (plugin *Plugin) GetAdminHelp() []string

GetAdminHelp returns the admin help for the slots system

func (*Plugin) GetCommandHandlers

func (plugin *Plugin) GetCommandHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)

GetCommandHandlers returns the command handlers for the slots system

func (*Plugin) GetCommands

func (plugin *Plugin) GetCommands() []*discordgo.ApplicationCommand

GetCommands returns the commands for the slots system

func (*Plugin) GetComponentHandlers

func (plugin *Plugin) GetComponentHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)

GetComponentHandlers returns the component handlers for the slots system

func (*Plugin) GetHelp

func (plugin *Plugin) GetHelp() []string

GetHelp returns the member help for the slots system

func (*Plugin) GetName

func (plugin *Plugin) GetName() string

GetName returns the name of the slots system plugin

func (*Plugin) Initialize

func (plugin *Plugin) Initialize(b *discord.Bot, d *mongo.MongoDB)

Initialize saves the Discord bot to be used by the slots system

func (*Plugin) Status

func (plugin *Plugin) Status() discord.PluginStatus

Status returns the status of the heist game. This is used to determine if the plugin is running or not.

func (*Plugin) Stop

func (plugin *Plugin) Stop()

Stop stops the heist game. This is called when the bot is shutting down.

type Symbols

type Symbols map[string]map[string]string

func GetSymbols

func GetSymbols() Symbols

func (Symbols) GetHand

func (s Symbols) GetHand(hand *bj.Hand, hidden bool) string

GetHand returns a string representation of the hand using the provided symbols.

func (Symbols) GetHandWithoutValue

func (s Symbols) GetHandWithoutValue(hand *bj.Hand, hidden bool) string

GetHandWithoutValue returns a string representation of the hand using the provided symbols.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL