cards

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

cards

A package representing the 'standard' 52-card deck of French-suited playing cards.

Documentation

Overview

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Package cards provides a comprehensive implementation of playing card types and operations for a standard 52-card French-suited deck.

Index

Constants

View Source
const (
	CA, C2, C3, C4, C5, C6, C7, C8, C9, CT, CJ, CQ, CK = Card(0), Card(1), Card(2), Card(3), Card(4), Card(5), Card(6), Card(7), Card(8), Card(9), Card(10), Card(11), Card(12)
	DA, D2, D3, D4, D5, D6, D7, D8, D9, DT, DJ, DQ, DK = Card(13), Card(14), Card(15), Card(16), Card(17), Card(18), Card(19), Card(20), Card(21), Card(22), Card(23), Card(24), Card(25)
	HA, H2, H3, H4, H5, H6, H7, H8, H9, HT, HJ, HQ, HK = Card(26), Card(27), Card(28), Card(29), Card(30), Card(31), Card(32), Card(33), Card(34), Card(35), Card(36), Card(37), Card(38)
	SA, S2, S3, S4, S5, S6, S7, S8, S9, ST, SJ, SQ, SK = Card(39), Card(40), Card(41), Card(42), Card(43), Card(44), Card(45), Card(46), Card(47), Card(48), Card(49), Card(50), Card(51)
)
View Source
const (
	ErrSyntax = cardErr("invalid syntax")
	ErrRange  = cardErr("input out of range")
)
View Source
const (
	Ace   = Rank(0)  // 'A' "Ace"
	Two   = Rank(1)  // '2' "Two"
	Three = Rank(2)  // '3' "Three"
	Four  = Rank(3)  // '4' "Four"
	Five  = Rank(4)  // '5' "Five"
	Six   = Rank(5)  // '6' "Six"
	Seven = Rank(6)  // '7' "Seven"
	Eight = Rank(7)  // '8' "Eight"
	Nine  = Rank(8)  // '9' "Nine"
	Ten   = Rank(9)  // 'T' "Ten"
	Jack  = Rank(10) // 'J' "Jack"
	Queen = Rank(11) // 'Q' "Queen"
	King  = Rank(12) // 'K' "King"
)
View Source
const (
	Clubs    = Suit(0) // '♣' "Clubs"
	Diamonds = Suit(1) // '♦' "Diamonds"
	Hearts   = Suit(2) // '♥' "Hearts"
	Spades   = Suit(3) // '♠' "Spades"
)

Variables

This section is empty.

Functions

func Asc

func Asc(a, b Card) bool

Asc[ending] order by card value.

func Desc

func Desc(a, b Card) bool

Desc[ending] order by card value.

func Equal

func Equal(hands int) func(int) bool

Equal hands; stop when no more equal hands can be dealt.

func FisherYates

func FisherYates(r rand.Rand) func(Deck) Deck

FisherYates shuffle algorithm, see https://en.wikipedia.org/wiki/Fisher–Yates_shuffle

func Num

func Num(num int) func(int) bool

Num[ber] of cards to deal in total; stop when 'num' cards has been reached.

func RankAsc

func RankAsc(a, b Card) bool

RankAsc[ending] order by rank value.

func RankDesc

func RankDesc(a, b Card) bool

RankDesc[ending] order by rank value.

func Size

func Size(hands, size int) func(int) bool

Size of hands to deal; stop when each hand contains 'size' cards.

func SuitAsc

func SuitAsc(a, b Card) bool

SuitAsc[ending] order by suit value.

func SuitDesc

func SuitDesc(a, b Card) bool

SuitDesc[ending] order by suit value.

Types

type Card

type Card uint8

Card in a standard 52-card deck of French-suited playing cards.

func Parse

func Parse(card string) (Card, error)

Parse the card string.

func (Card) MarshalJSON added in v1.1.0

func (c Card) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Card) MarshalText added in v1.1.0

func (c Card) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Card) Name

func (c Card) Name() string

Name of the card (proper noun).

func (Card) Rank

func (c Card) Rank() Rank

Rank of the card (suit independant value).

func (*Card) Scan added in v1.1.0

func (c *Card) Scan(src any) error

Scan card value from the database.

func (Card) String

func (c Card) String() string

String representation of the card.

func (Card) Suit

func (c Card) Suit() Suit

Suit of the card (rank independant value).

func (Card) Symbol

func (c Card) Symbol() rune

Symbol representation of the card.

func (*Card) UnmarshalJSON added in v1.1.0

func (c *Card) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Card) UnmarshalText added in v1.1.0

func (c *Card) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Card) Value added in v1.1.0

func (c Card) Value() (driver.Value, error)

Value of the Card as a driver.Value (for writing to a DB).

type Deck

type Deck [52]Card

Deck of 52 cards.

func OrderedDeck

func OrderedDeck() Deck

OrderedDeck in alphabetic-suit and ascenting-rank order.

func (Deck) Deal

func (d Deck) Deal(hands int, stop func(i int) bool) []Hand

Deal the deck to the number of hands.

func (Deck) Shuffle

func (d Deck) Shuffle(r rand.Rand) Deck

Shuffle with the math/rand algorithm.

func (Deck) ShuffleWith

func (d Deck) ShuffleWith(alg func(Deck) Deck) Deck

ShuffleWith the provided algorithm.

func (Deck) Sort

func (d Deck) Sort(less func(a, b Card) bool) Deck

Sort the Deck using the provided less function. Sorting is stable; ordering of equal values is maintained.

type Hand

type Hand []Card

Hand of cards.

func (Hand) Contains

func (h Hand) Contains(card Card) bool

Contains at least one of the card.

func (Hand) ContainsRank

func (h Hand) ContainsRank(rank Rank) bool

ContainsRank at least once.

func (Hand) ContainsSuit

func (h Hand) ContainsSuit(suit Suit) bool

ContainsSuit at least once.

func (Hand) Find

func (h Hand) Find(a Card) (int, bool)

Find the index of the first instance of the provided card, or false if not in the hand.

func (Hand) Remove

func (h Hand) Remove(card Card) Hand

Remove first instance of card from hand.

func (Hand) RemoveAll

func (h Hand) RemoveAll(card Card) Hand

RemoveAll instances of a card from a hand.

func (Hand) Sort

func (h Hand) Sort(less func(a, b Card) bool)

Sort the Hand using the provided less function. Sorting is stable; ordering of equal values is maintained.

type ParseErr

type ParseErr struct {
	Func  string
	Input string
	Err   error
}

func (ParseErr) Error

func (e ParseErr) Error() string

func (ParseErr) Unwrap

func (e ParseErr) Unwrap() error

type Rank

type Rank uint8

Rank of a card (suit independant value).

func ParseRank

func ParseRank(rank string) (Rank, error)

ParseRank string to a Rank.

func (Rank) Card

func (r Rank) Card(s Suit) Card

Card with corresponding rank given its suit.

func (Rank) MarshalJSON added in v1.1.0

func (r Rank) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Rank) MarshalText added in v1.1.0

func (r Rank) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Rank) Name

func (r Rank) Name() string

Name of the rank (proper noun).

func (*Rank) Scan added in v1.1.0

func (r *Rank) Scan(src any) error

Scan rank value from the database.

func (Rank) String

func (r Rank) String() string

String representation of the rank.

func (Rank) Symbol

func (r Rank) Symbol() rune

Symbol representation of the rank.

func (*Rank) UnmarshalJSON added in v1.1.0

func (r *Rank) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Rank) UnmarshalText added in v1.1.0

func (r *Rank) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Rank) Value added in v1.1.0

func (r Rank) Value() (driver.Value, error)

Value of the Rank as a driver.Value (for writing to a DB).

type Suit

type Suit uint8

Suit of a Card (one of ♣, ♦, ♥, ♠).

func ParseSuit

func ParseSuit(suit string) (Suit, error)

ParseSuit string to a Suit.

func (Suit) Card

func (s Suit) Card(r Rank) Card

Card in the suit given its rank.

func (Suit) MarshalJSON added in v1.1.0

func (s Suit) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Suit) MarshalText added in v1.1.0

func (s Suit) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Suit) Name

func (s Suit) Name() string

Name of the suit (proper noun).

func (*Suit) Scan added in v1.1.0

func (s *Suit) Scan(src any) error

Scan suite value from the database.

func (Suit) String

func (s Suit) String() string

String representation of the suit.

func (Suit) Symbol

func (s Suit) Symbol() rune

Symbol representation of the suit.

func (*Suit) UnmarshalJSON added in v1.1.0

func (s *Suit) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Suit) UnmarshalText added in v1.1.0

func (s *Suit) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Suit) Value added in v1.1.0

func (s Suit) Value() (driver.Value, error)

Value of the Suite as a driver.Value (for writing to a DB).

Jump to

Keyboard shortcuts

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