game

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionHit = iota + 1
	ActionStay
	ActionSplit
	ActionDouble
	ActionSurrender
	ActionStats
	ActionExit
	ActionInvalid
)

Actions a player can take.

View Source
const (
	ResultWin = iota + 1
	ResultLoss
	ResultTie
	ResultNone
	ResultInvalid
)

Results of playing a hand.

Variables

View Source
var ErrDeckEmpty = errors.New("deck is empty")

ErrDeckEmpty means the deck is empty.

View Source
var UseCardSymbols = false

UseCardSymbols determines whether to use the unicode card symbols for the text representation or straight text.

Functions

func NewUUID added in v1.1.0

func NewUUID() string

NewUUID safely creates a UUID string.

func ReadInput

func ReadInput() string

ReadInput will read a string from stdin.

Types

type Action

type Action int

Action a player can take.

func ParseAction added in v1.1.0

func ParseAction(value string) Action

ParseAction will return the Action represented by the given string.

func (Action) String added in v1.1.0

func (a Action) String() string

String will return the string representation of an Action.

type Card

type Card struct {
	Hidden bool
	// contains filtered or unexported fields
}

Card represents a single card.

func NewCard

func NewCard(suit Suit, rank Rank) Card

NewCard will return a new card with the given suit and rank.

func (Card) Rank

func (c Card) Rank() Rank

Rank will return the card's rank or a default value if the card is hidden.

func (Card) String

func (c Card) String() string

String will return the string representation of the card.

func (Card) Suit

func (c Card) Suit() Suit

Suit will return the card's suit or a default value if the card is hidden.

func (Card) Symbol

func (c Card) Symbol() string

Symbol will return the unicode card symbol representation of the card.

func (Card) Text

func (c Card) Text() string

Text will return the text representation of the card.

type Deck

type Deck struct {
	Cards []Card
}

Deck represents a deck of cards.

func NewDeck

func NewDeck() *Deck

NewDeck creates a new deck of 52 cards. The cards are not in random order.

func NewEmptyDeck

func NewEmptyDeck() *Deck

NewEmptyDeck will create an empty deck.

func (*Deck) Add

func (d *Deck) Add(i int, card Card)

Add a card to the deck at the specific index.

func (*Deck) Count

func (d *Deck) Count() int

Count returns the number of cards in the deck.

func (*Deck) Deal

func (d *Deck) Deal() (Card, error)

Deal the top card from the deck. This removes the card from the deck.

func (*Deck) String

func (d *Deck) String() string

String will return a string representation of the deck.

type Hand

type Hand struct {
	ID          string
	Cards       []Card
	Bet         float64
	Surrendered bool
}

Hand represents a hand of cards.

func NewHand

func NewHand(cards ...Card) *Hand

NewHand will create a new hand with the given cards.

func (*Hand) Add

func (h *Hand) Add(card Card)

Add a single card to the hand.

func (*Hand) CanDouble

func (h *Hand) CanDouble() bool

CanDouble will return true if doubling down is allowed.

func (*Hand) CanSplit

func (h *Hand) CanSplit() bool

CanSplit will return true if splitting is allowed.

func (*Hand) Clear

func (h *Hand) Clear()

Clear will reset a hand to empty.

func (*Hand) Count

func (h *Hand) Count() int

Count will return the number of cards in the hand.

func (*Hand) Hard

func (h *Hand) Hard() bool

Hard returns true if the hand is a hard hand, meaning it includes no aces or only aces that are counted as 1.

func (*Hand) IsInitialHand

func (h *Hand) IsInitialHand() bool

IsInitialHand will return true if hand only has two cards.

func (*Hand) IsNatural

func (h *Hand) IsNatural() bool

IsNatural will return true if this hand is a natural blackjack (21 from two cards).

func (*Hand) Soft

func (h *Hand) Soft() bool

Soft returns true if the hand is a soft hand, meaning it includes an ace that is counted as 11.

func (*Hand) String

func (h *Hand) String() string

String will return a string representation of the hand.

func (*Hand) Total

func (h *Hand) Total() int

Total returns the highest hand total without busting, unless busting is unavoidable.

type Rank

type Rank int

Rank represents a rank (the value) on a card.

const (
	RankAce  Rank = 1
	RankJack Rank = iota + 10
	RankQueen
	RankKing
)

Rank types.

func (Rank) String

func (r Rank) String() string

String returns the string representation of the rank.

type Result added in v1.1.0

type Result int

Result of playing a hand.

func ParseResult added in v1.1.0

func ParseResult(value string) Result

ParseResult will return the Result represented by the given string.

func (Result) String added in v1.1.0

func (a Result) String() string

String will return the string representation of a Result.

type Shuffler

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

Shuffler will shuffle a deck of cards and deal from the top.

func NewShuffler

func NewShuffler() Shuffler

NewShuffler will create a new shuffler.

func (Shuffler) Add

func (s Shuffler) Add(cards ...Card)

Add will shuffle the given cards into the shuffler.

func (Shuffler) Deal

func (s Shuffler) Deal() (Card, error)

Deal will deal the top card from the shuffler.

type Suit

type Suit int

Suit represents a suit on a card.

const (
	SuitClubs Suit = iota + 1
	SuitSpades
	SuitHearts
	SuitDiamonds
)

Suit types.

func (Suit) String

func (s Suit) String() string

String returns the symbol representation of the suit.

Jump to

Keyboard shortcuts

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