joker

package module
v0.1.2-0...-b012663 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 6 Imported by: 0

README

joker

GoDoc builds.sr.ht status Donate

Playing card library

Extensions

The following libraries extend joker:

Documentation

Documentation is available on godoc.

Support

Please share issues/suggestions here.

Documentation

Overview

Package joker provides playing cards.

Cards

To initialize a card:

card := joker.Card{FaceAce, SuitSpades}

To sort a set of cards:

hand := joker.Cards{
  Card{FaceAce, SuitSpades},
  Card{Face3, SuitSpades},
  Card{Face2, SuitSpades}
}
sort.Sort(hand)

Deck

To initialize a deck, call NewDeck with a seed for the random number generator used when shuffling. A seed value of zero will be replaced with the current unix time in nanoseconds.

deck := joker.NewDeck(StandardCards, 0)

Index

Constants

View Source
const (
	SymbolHearts   = "♥"
	SymbolDiamonds = "♦"
	SymbolClubs    = "♣"
	SymbolSpades   = "♠"
	SymbolJoker    = "!"
)

Card symbols

View Source
const Invalid = "?"

Invalid is the text shown when a valid face or suit is not found.

Variables

AllFaces is a slice of all faces.

AllSuits is a slice of all suits.

StandardCards is a slice of standard cards.

StandardFaces is a slice of all faces except Jokers.

StandardSuits is a slice of all card suits except Jokers.

Functions

This section is empty.

Types

type Card

type Card struct {
	Face CardFace
	Suit CardSuit
}

Card defines a playing card with a face and suit.

func (Card) Equal

func (c Card) Equal(b Card) bool

Equal returns whether both cards have the same face and suit.

func (Card) Identifier

func (c Card) Identifier() string

Identifier returns a machine-readable representation of a card.

func (Card) MarshalJSON

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

MarshalJSON marshals a Card.

func (Card) String

func (c Card) String() string

String returns a human-readable representation of a Card.

func (*Card) UnmarshalJSON

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

UnmarshalJSON unmarshals a Card.

func (Card) Value

func (c Card) Value() int

Value returns the numeric value of a card.

type CardFace

type CardFace int

CardFace defines a card face.

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
)

Card faces

func (CardFace) Name

func (f CardFace) Name() string

Name returns the card face name.

func (CardFace) String

func (f CardFace) String() string

String returns the card face name.

type CardSuit

type CardSuit int

CardSuit defines a card suit.

const (
	SuitHearts   CardSuit = 1
	SuitDiamonds CardSuit = 2
	SuitClubs    CardSuit = 3
	SuitSpades   CardSuit = 4
	SuitJoker    CardSuit = 5
)

Card suits

func (CardSuit) Name

func (s CardSuit) Name() string

Name returns the card suit name.

func (CardSuit) String

func (s CardSuit) String() string

String returns the card suit name.

func (CardSuit) Symbol

func (s CardSuit) Symbol() string

Symbol returns the card suit symbol.

type Cards

type Cards []Card

Cards is a slice of Cards.

func (Cards) Contains

func (c Cards) Contains(card Card) bool

Contains returns whether the supplied cards contain the specified card.

func (Cards) Copy

func (c Cards) Copy() Cards

Copy returns a copy of the supplied cards.

func (Cards) Count

func (c Cards) Count(card Card) int

Count returns the number of occurrences of the specified card.

func (Cards) Equal

func (c Cards) Equal(cards Cards) bool

Equal returns whether the supplied cards are equal to another set of cards.

func (Cards) High

func (c Cards) High() Card

High returns the highest valued card.

func (Cards) Len

func (c Cards) Len() int

func (Cards) Less

func (c Cards) Less(i, j int) bool

func (Cards) Low

func (c Cards) Low() Card

Low returns the lowest valued card.

func (Cards) Permutations

func (c Cards) Permutations() []Cards

Permutations returns all permutations of the supplied cards.

func (Cards) Remove

func (c Cards) Remove(i int) Cards

Remove returns the supplied cards excluding the card at the specified index.

func (Cards) Reversed

func (c Cards) Reversed() Cards

Reversed returns the supplied cards in reverse order.

func (Cards) Sorted

func (c Cards) Sorted() Cards

Sorted returns the supplied cards in order.

func (Cards) Swap

func (c Cards) Swap(i, j int)

type Deck

type Deck struct {
	Cards Cards
	// contains filtered or unexported fields
}

Deck defines a playing card deck containing any number of cards.

func NewDeck

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 (*Deck) Draw

func (d *Deck) Draw(count int) (cards Cards, ok bool)

Draw removes cards from the deck and returns them as a slice.

func (*Deck) Shuffle

func (d *Deck) Shuffle()

Shuffle randomizes the deck.

Jump to

Keyboard shortcuts

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