Documentation
¶
Index ¶
- Constants
- type Action
- type ActionType
- type ChipManager
- type Dealer
- func (d *Dealer) ClearHand()
- func (d *Dealer) DealCard(card cards.Card)
- func (d *Dealer) Hand() *Hand
- func (d *Dealer) HasBlackjack() bool
- func (d *Dealer) Hit(card cards.Card)
- func (d *Dealer) IsBusted() bool
- func (d *Dealer) RevealHoleCard() string
- func (d *Dealer) ShouldHit() bool
- func (d *Dealer) ShowFirstCard() cards.Card
- func (d *Dealer) Stand()
- func (d *Dealer) String() string
- func (d *Dealer) StringHidden() string
- func (d *Dealer) Value() int
- type DefaultChipManager
- type Game
- func (bg *Game) AddPlayer(name string, options ...Option)
- func (bg *Game) DealCard() error
- func (bg *Game) DealInitialCards() error
- func (bg *Game) Dealer() *Dealer
- func (bg *Game) DealerPlay() error
- func (bg *Game) EvaluateHand(playerHand *Hand) GameResult
- func (bg *Game) GetActivePlayer() *Player
- func (bg *Game) GetGameStatus(showDealerHole bool) string
- func (bg *Game) GetPlayer(name string) *Player
- func (bg *Game) IsRoundComplete() bool
- func (bg *Game) PayoutResults()
- func (bg *Game) PlayerDoubleDownHit(playerName string) error
- func (bg *Game) PlayerHit(playerName string) error
- func (bg *Game) PlayerSplit(playerName string) error
- func (bg *Game) PlayerStand(playerName string) error
- func (bg *Game) PlayerSurrender(playerName string) error
- func (bg *Game) Players() []*Player
- func (bg *Game) RemovePlayer(name string) bool
- func (bg *Game) Round() int
- func (bg *Game) Shoe() *Shoe
- func (bg *Game) StartNewRound() error
- type GameResult
- type Hand
- func (h *Hand) ActionSummary() string
- func (h *Hand) Actions() []Action
- func (h *Hand) AddCard(card cards.Card)
- func (h *Hand) AddCardWithAction(card cards.Card, actionType ActionType, details string)
- func (h *Hand) AddWinnings(amount int)
- func (h *Hand) Bet() int
- func (h *Hand) CanDoubleDown() bool
- func (h *Hand) CanSplit() bool
- func (h *Hand) CanSurrender() bool
- func (h *Hand) Cards() []cards.Card
- func (h *Hand) Clear()
- func (h *Hand) Count() int
- func (h *Hand) DealCard(card cards.Card)
- func (h *Hand) DoubleDown() error
- func (h *Hand) DoubleDownHit(card cards.Card)
- func (h *Hand) Hit(card cards.Card)
- func (h *Hand) IsActive() bool
- func (h *Hand) IsBlackjack() bool
- func (h *Hand) IsBusted() bool
- func (h *Hand) IsSoft() bool
- func (h *Hand) IsSplit() bool
- func (h *Hand) IsStood() bool
- func (h *Hand) IsSurrendered() bool
- func (h *Hand) LoseBet()
- func (h *Hand) PlaceBet(amount int) error
- func (h *Hand) PushBet()
- func (h *Hand) RecordAction(actionType ActionType, details string)
- func (h *Hand) SetActive(active bool)
- func (h *Hand) SetBet(amount int)
- func (h *Hand) SetWinnings(amount int)
- func (h *Hand) Split() error
- func (h *Hand) Stand()
- func (h *Hand) String() string
- func (h *Hand) StringHidden() string
- func (h *Hand) Surrender()
- func (h *Hand) Value() int
- func (h *Hand) WinBet(multiplier float64)
- func (h *Hand) Winnings() int
- type Option
- type Player
- func (p *Player) AddChips(amount int)
- func (p *Player) Chips() int
- func (p *Player) ClearHands()
- func (p *Player) CurrentHand() *Hand
- func (p *Player) GetAllHandValues() []int
- func (p *Player) GetCurrentHandNumber() int
- func (p *Player) Hands() []*Hand
- func (p *Player) HasActiveHands() bool
- func (p *Player) IsActive() bool
- func (p *Player) IsStanding() bool
- func (p *Player) MoveToNextActiveHand() bool
- func (p *Player) Name() string
- func (p *Player) NextHand() bool
- func (p *Player) SetActive(active bool)
- func (p *Player) String() string
- type Shoe
Constants ¶
const ( CutCardPenetration = 0.75 // CutCardPenetration is the fraction of the shoe dealt before reshuffling NumCardsInDeck = 52 // NumCardsInDeck is the number of cards in a standard deck )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
Type ActionType `json:"type"`
Card *cards.Card `json:"card,omitempty"` // Card involved (for deal/hit)
Timestamp time.Time `json:"timestamp"`
Details string `json:"details,omitempty"` // Additional details about the action
}
Action represents an action taken on a hand
type ActionType ¶
type ActionType string
ActionType represents the type of action taken on a hand
const ( ActionDeal ActionType = "deal" ActionHit ActionType = "hit" ActionStand ActionType = "stand" ActionDouble ActionType = "double" ActionSplit ActionType = "split" ActionSurrender ActionType = "surrender" )
type ChipManager ¶
type ChipManager interface {
GetChips() int // GetChips returns the current chip count
SetChips(amount int) // SetChips sets the chip count to the specified amount
AddChips(amount int) // AddChips adds the specified amount to the chip count
DeductChips(amount int) error // DeductChips removes the specified amount from the chip count
HasEnoughChips(amount int) bool // HasEnoughChips returns true if there are enough chips for the specified amount
}
ChipManager interface defines the operations for managing player chips
type Dealer ¶
type Dealer struct {
// contains filtered or unexported fields
}
Dealer represents the blackjack dealer
func (*Dealer) ClearHand ¶
func (d *Dealer) ClearHand()
ClearHand clears the dealer's hand for a new round
func (*Dealer) HasBlackjack ¶
HasBlackjack returns true if dealer has blackjack
func (*Dealer) RevealHoleCard ¶
RevealHoleCard shows the dealer's full hand
func (*Dealer) ShouldHit ¶
ShouldHit returns true if the dealer should hit according to standard blackjack rules Dealer hits on 16 or less, stands on 17 or more (including soft 17)
func (*Dealer) ShowFirstCard ¶
ShowFirstCard returns the dealer's first card (face up)
func (*Dealer) String ¶
String returns a string representation of the dealer with both cards showing
func (*Dealer) StringHidden ¶
StringHidden returns a string representation of the dealer with hole card hidden
type DefaultChipManager ¶
type DefaultChipManager struct {
// contains filtered or unexported fields
}
DefaultChipManager implements ChipManager with simple integer-based chip management
func NewDefaultChipManager ¶
func NewDefaultChipManager(initialChips int) *DefaultChipManager
NewDefaultChipManager creates a new default chip manager with the given initial amount
func (*DefaultChipManager) AddChips ¶
func (c *DefaultChipManager) AddChips(amount int)
AddChips adds the specified amount to the chip count
func (*DefaultChipManager) DeductChips ¶
func (c *DefaultChipManager) DeductChips(amount int) error
DeductChips removes the specified amount from the chip count
func (*DefaultChipManager) GetChips ¶
func (c *DefaultChipManager) GetChips() int
GetChips returns the current chip count
func (*DefaultChipManager) HasEnoughChips ¶
func (c *DefaultChipManager) HasEnoughChips(amount int) bool
HasEnoughChips returns true if there are enough chips for the specified amount
func (*DefaultChipManager) SetChips ¶
func (c *DefaultChipManager) SetChips(amount int)
SetChips sets the chip count to the specified amount
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game represents the main game
func (*Game) DealInitialCards ¶
DealInitialCards deals two cards to each player and dealer
func (*Game) DealerPlay ¶
DealerPlay handles the dealer's turn according to blackjack rules
func (*Game) EvaluateHand ¶
func (bg *Game) EvaluateHand(playerHand *Hand) GameResult
EvaluateHand determines the result of a player's hand against the dealer
func (*Game) GetActivePlayer ¶
GetActivePlayer returns the first active player who hasn't finished their hand
func (*Game) GetGameStatus ¶
GetGameStatus returns a string representation of the current game state
func (*Game) IsRoundComplete ¶
IsRoundComplete returns true if all players have finished their hands
func (*Game) PayoutResults ¶
func (bg *Game) PayoutResults()
PayoutResults handles payouts for all players
func (*Game) PlayerDoubleDownHit ¶
PlayerDoubleDownHit deals a card to a specific player as part of a double down
func (*Game) PlayerSplit ¶
PlayerSplit processes a split action for the specified player.
func (*Game) PlayerStand ¶
PlayerStand handles a player standing on their current hand
func (*Game) PlayerSurrender ¶
PlayerSurrender handles a player surrendering their current hand
func (*Game) RemovePlayer ¶
RemovePlayer removes a player from the game
func (*Game) StartNewRound ¶
StartNewRound starts a new round of blackjack
type GameResult ¶
type GameResult int
GameResult represents the outcome of a hand
const ( PlayerWin GameResult // PlayerWin reprepsents a win for the player DealerWin // DealerWin represents a win for the dealer Push // Push represents a tie PlayerBlackjack // PlayerBlackjack represents a player blackjack DealerBlackjack // DealerBlackjack represents a dealer blackjack )
func (GameResult) String ¶
func (gr GameResult) String() string
String returns a string representation of the game result
type Hand ¶
type Hand struct {
// contains filtered or unexported fields
}
Hand represents a hand of cards in blackjack
func NewDealerHand ¶ added in v1.3.0
func NewDealerHand() *Hand
NewDealerHand creates a new dealer hand without a chip manager
func (*Hand) ActionSummary ¶
ActionSummary returns a string summary of all actions taken on this hand
func (*Hand) AddCardWithAction ¶
func (h *Hand) AddCardWithAction(card cards.Card, actionType ActionType, details string)
AddCardWithAction adds a card to the hand and records the specific action
func (*Hand) AddWinnings ¶ added in v1.1.0
AddWinnings adds to the winnings for this hand
func (*Hand) CanDoubleDown ¶ added in v1.3.0
CanDoubleDown returns true if the hand can be doubled down
func (*Hand) CanSurrender ¶ added in v1.3.0
CanSurrender returns true if the player can surrender (typically only on first two cards)
func (*Hand) DealCard ¶ added in v1.3.0
DealCard adds a card to the player's hand as part of the initial deal
func (*Hand) DoubleDown ¶ added in v1.3.0
DoubleDown performs the double down action on the hand
func (*Hand) DoubleDownHit ¶ added in v1.3.0
DoubleDownHit adds a card to the player's hand as part of a double down
func (*Hand) IsBlackjack ¶
IsBlackjack returns true if the hand is a natural blackjack (21 with 2 cards)
func (*Hand) IsSurrendered ¶ added in v1.3.2
IsSurrendered returns true if the hand has been surrendered
func (*Hand) LoseBet ¶ added in v1.3.0
func (h *Hand) LoseBet()
LoseBet removes the player's bet for the current hand (already deducted when placed)
func (*Hand) PushBet ¶ added in v1.3.0
func (h *Hand) PushBet()
PushBet returns the bet to the player for the current hand (tie)
func (*Hand) RecordAction ¶
func (h *Hand) RecordAction(actionType ActionType, details string)
RecordAction records an action without a card (like stand, surrender)
func (*Hand) SetWinnings ¶ added in v1.1.0
SetWinnings sets the winnings for this hand
func (*Hand) StringHidden ¶
StringHidden returns a string representation with the first card hidden (for dealer)
func (*Hand) Surrender ¶ added in v1.3.0
func (h *Hand) Surrender()
Surrender allows the player to forfeit their hand and lose half their bet
type Option ¶
type Option func(*Player)
Option is a function that modifies a message.
func WithChipManager ¶
func WithChipManager(cm ChipManager) Option
WithChipManager sets a custom chip manager for the player.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player represents a blackjack player
func NewPlayer ¶
NewPlayer creates a new player with the given name, initial chips, and optional settings
func (*Player) ClearHands ¶ added in v1.3.0
func (p *Player) ClearHands()
ClearHands clears all of the player's hands for a new round
func (*Player) CurrentHand ¶
CurrentHand returns the player's current hand
func (*Player) GetAllHandValues ¶
GetAllHandValues returns the values of all hands
func (*Player) GetCurrentHandNumber ¶ added in v1.3.0
GetCurrentHandNumber returns the index of the current hand
func (*Player) HasActiveHands ¶
HasActiveHands returns true if the player has any active hands left to play
func (*Player) IsStanding ¶
IsStanding returns true if the current hand should stand (busted, blackjack, or inactive)
func (*Player) MoveToNextActiveHand ¶
MoveToNextActiveHand moves to the next active hand, returns true if successful
func (*Player) NextHand ¶
NextHand moves to the next hand if available, returning true if successful
type Shoe ¶
type Shoe struct {
// contains filtered or unexported fields
}
Shoe wraps the cards.Shoe with blackjack-specific functionality
func (*Shoe) CardsRemaining ¶
CardsRemaining returns the number of cards left in the shoe
func (*Shoe) NeedsReshuffle ¶
NeedsReshuffle returns true if the cut card has been reached
func (*Shoe) Penetration ¶
Penetration returns the percentage of cards that have been dealt