decks

package
v0.0.0-...-c470439 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DeckSize of a normal deck of cards.
	DeckSize = int(SuitsCnt) * int(RanksCnt)
)

Variables

This section is empty.

Functions

func DefaultComparator

func DefaultComparator(deck *Deck) func(i, j int) bool

DefaultComparator is the default comparator used for sorting a deck of cards.

Types

type Card

type Card struct {
	Rank
	Suit
	IsJoker bool
}

Card represents a playing card from a deck of cards. It contains a rank (e.g. Ace) and a suit (e.g. Clovers). It also contains a boolean flag denoting this card as a joker.

func (Card) String

func (c Card) String() string

type Comparator

type Comparator func(deck *Deck) func(i, j int) bool

Comparator is used to sort a deck of cards based on a user-defined comparator.

type Deck

type Deck struct {
	Cards []Card
}

Deck encapsulates a normal deck of cards and defines some operations on them.

func New

func New(opts ...Option) (*Deck, error)

New deck of cards, based on the options provided. In case none are passed, a sorted default deck of cards (without jokers) will be returned.

func (*Deck) Draw

func (d *Deck) Draw() Card

Draw a card from the deck. The drawn card is returned and removed from the deck.

func (*Deck) InsertBottom

func (d *Deck) InsertBottom(cs []Card)

InsertBottom puts the given cards at the bottom of the deck.

func (*Deck) Shuffle

func (d *Deck) Shuffle() error

Shuffle the deck randomly.

type Option

type Option func(*Deck) error

Option is a function alias used for constructing a functional-options constructor for a deck.

func Filter

func Filter(filterFunc func(fc Card) bool) Option

Filter is a functional option for filtering given cards from the deck.

func Shuffle

func Shuffle() Option

Shuffle is a functional option for shuffling the deck in a random way.

func ShuffleWithSeed

func ShuffleWithSeed(s int64) Option

ShuffleWithSeed is a functional option for shuffling the deck based on a random seed.

func Sort

func Sort(comp Comparator) Option

Sort is a functional option for sorting the deck based on a user-defined comparator.

func WithDecks

func WithDecks(cnt int) Option

WithDecks is a functional option for specifying the amount of decks to include.

func WithJokers

func WithJokers(cnt int) Option

WithJokers is a functional option for specifying how many jokers to include.

type Rank

type Rank uint8

Rank from a normal deck of cards. i.e. Ace, Two, Jack, etc...

const (
	Ace Rank = iota
	Two
	Three
	Four
	Five
	Six
	Seven
	Eight
	Nine
	Ten
	Jack
	Queen
	King
	RanksCnt
)

The ranks from a normal deck of cards.

type Suit

type Suit uint8

Suit from a normal deck of cards. i.e. Clovers, Diamonds, etc...

const (
	Clovers Suit = iota
	Diamonds
	Hearts
	Spades
	SuitsCnt
)

Suits from a normal deck of cards

Jump to

Keyboard shortcuts

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