Card symbols
const ( SymbolHearts = "♥" SymbolDiamonds = "♦" SymbolClubs = "♣" SymbolSpades = "♠" SymbolJoker = "!" )
Invalid is the text shown when a valid face or suit is not found.
const Invalid = "?"
AllFaces is a slice of all faces.
var AllFaces = []CardFace{ FaceAce, Face2, Face3, Face4, Face5, Face6, Face7, Face8, Face9, Face10, FaceJack, FaceQueen, FaceKing, FaceJoker, }
AllSuits is a slice of all suits.
var AllSuits = []CardSuit{ SuitHearts, SuitDiamonds, SuitClubs, SuitSpades, SuitJoker, }
StandardCards is a slice of standard cards.
var StandardCards = Cards{ Card{FaceAce, SuitHearts}, Card{Face2, SuitHearts}, Card{Face3, SuitHearts}, Card{Face4, SuitHearts}, Card{Face5, SuitHearts}, Card{Face6, SuitHearts}, Card{Face7, SuitHearts}, Card{Face8, SuitHearts}, Card{Face9, SuitHearts}, Card{Face10, SuitHearts}, Card{FaceJack, SuitHearts}, Card{FaceQueen, SuitHearts}, Card{FaceKing, SuitHearts}, Card{FaceAce, SuitDiamonds}, Card{Face2, SuitDiamonds}, Card{Face3, SuitDiamonds}, Card{Face4, SuitDiamonds}, Card{Face5, SuitDiamonds}, Card{Face6, SuitDiamonds}, Card{Face7, SuitDiamonds}, Card{Face8, SuitDiamonds}, Card{Face9, SuitDiamonds}, Card{Face10, SuitDiamonds}, Card{FaceJack, SuitDiamonds}, Card{FaceQueen, SuitDiamonds}, Card{FaceKing, SuitDiamonds}, Card{FaceAce, SuitClubs}, Card{Face2, SuitClubs}, Card{Face3, SuitClubs}, Card{Face4, SuitClubs}, Card{Face5, SuitClubs}, Card{Face6, SuitClubs}, Card{Face7, SuitClubs}, Card{Face8, SuitClubs}, Card{Face9, SuitClubs}, Card{Face10, SuitClubs}, Card{FaceJack, SuitClubs}, Card{FaceQueen, SuitClubs}, Card{FaceKing, SuitClubs}, Card{FaceAce, SuitSpades}, Card{Face2, SuitSpades}, Card{Face3, SuitSpades}, Card{Face4, SuitSpades}, Card{Face5, SuitSpades}, Card{Face6, SuitSpades}, Card{Face7, SuitSpades}, Card{Face8, SuitSpades}, Card{Face9, SuitSpades}, Card{Face10, SuitSpades}, Card{FaceJack, SuitSpades}, Card{FaceQueen, SuitSpades}, Card{FaceKing, SuitSpades}, }
StandardFaces is a slice of all faces except Jokers.
var StandardFaces = []CardFace{ FaceAce, Face2, Face3, Face4, Face5, Face6, Face7, Face8, Face9, Face10, FaceJack, FaceQueen, FaceKing, }
StandardSuits is a slice of all card suits except Jokers.
var StandardSuits = []CardSuit{ SuitHearts, SuitDiamonds, SuitClubs, SuitSpades, }
Card defines a playing card with a face and suit.
type Card struct { Face CardFace Suit CardSuit }
func Parse(identifier string) (Card, bool)
Parse parses a card identifier to construct a card.
func (c Card) Equal(b Card) bool
Equal returns whether both cards have the same face and suit.
func (c Card) Identifier() string
Identifier returns a machine-readable representation of a card.
func (c Card) MarshalJSON() ([]byte, error)
MarshalJSON marshals a Card.
func (c Card) String() string
String returns a human-readable representation of a Card.
func (c *Card) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals a Card.
func (c Card) Value() int
Value returns the numeric value of a card.
CardFace defines a card face.
type CardFace int
Card faces
const ( FaceAce CardFace = 1 Face2 CardFace = 2 Face3 CardFace = 3 Face4 CardFace = 4 Face5 CardFace = 5 Face6 CardFace = 6 Face7 CardFace = 7 Face8 CardFace = 8 Face9 CardFace = 9 Face10 CardFace = 10 FaceJack CardFace = 11 FaceQueen CardFace = 12 FaceKing CardFace = 13 FaceJoker CardFace = 14 )
func (f CardFace) Name() string
Name returns the card face name.
func (f CardFace) String() string
String returns the card face name.
CardSuit defines a card suit.
type CardSuit int
Card suits
const ( SuitHearts CardSuit = 1 SuitDiamonds CardSuit = 2 SuitClubs CardSuit = 3 SuitSpades CardSuit = 4 SuitJoker CardSuit = 5 )
func (s CardSuit) Name() string
Name returns the card suit name.
func (s CardSuit) String() string
String returns the card suit name.
func (s CardSuit) Symbol() string
Symbol returns the card suit symbol.
Cards is a slice of Cards.
type Cards []Card
func (c Cards) Contains(card Card) bool
Contains returns whether the supplied cards contain the specified card.
func (c Cards) Copy() Cards
Copy returns a copy of the supplied cards.
func (c Cards) Count(card Card) int
Count returns the number of occurrences of the specified card.
func (c Cards) Equal(cards Cards) bool
Equal returns whether the supplied cards are equal to another set of cards.
func (c Cards) High() Card
High returns the highest valued card.
func (c Cards) Len() int
func (c Cards) Less(i, j int) bool
func (c Cards) Low() Card
Low returns the lowest valued card.
func (c Cards) Permutations() []Cards
Permutations returns all permutations of the supplied cards.
func (c Cards) Remove(card Card) Cards
Remove returns the supplied cards with the specified card removed one time.
func (c Cards) RemoveIndex(i int) Cards
RemoveIndex returns the supplied cards excluding the card at the specified index.
func (c Cards) Reversed() Cards
Reversed returns the supplied cards in reverse order.
func (c Cards) Sorted() Cards
Sorted returns the supplied cards in order.
func (c Cards) String() string
func (c Cards) Swap(i, j int)
Deck defines a playing card deck containing any number of cards.
type Deck struct { Cards Cards // contains filtered or unexported fields }
func NewDeck(c Cards, seed int64) *Deck
NewDeck initializes a deck of cards. A seed value of 0 is replaced with the current unix time in nanoseconds.
func (d *Deck) Draw(count int) (cards Cards, ok bool)
Draw removes cards from the deck and returns them as a slice.
func (d *Deck) Shuffle()
Shuffle randomizes the order of the deck using the Fisher-Yates shuffle algorithm.