card

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCode = errors.New("invalid code")

ErrInvalidCode is returned when a code is invalid.

View Source
var ErrInvalidRank = errors.New("invalid rank")

ErrInvalidRank is returned when a rank is invalid.

View Source
var ErrInvalidSuit = errors.New("invalid suit")

ErrInvalidSuit is returned when a suit is invalid.

Functions

This section is empty.

Types

type Card

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

Card represents a card in a deck.

func NewCard

func NewCard(r Rank, s Suit) (*Card, error)

NewCard returns a new card given a rank and suit.

func (*Card) Code

func (c *Card) Code() Code

Code returns the code of the card.

func (*Card) Rank

func (c *Card) Rank() Rank

Rank returns the rank of the card.

func (*Card) Suit

func (c *Card) Suit() Suit

Suit returns the suit of the card.

type Code

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

Code represents a card code.

func CodeFromRankSuit added in v0.2.0

func CodeFromRankSuit(r Rank, s Suit) (*Code, error)

CodeFromRankSuit returns a new code given a rank and suit.

func CodeFromString added in v0.2.0

func CodeFromString(c string) (*Code, error)

CodeFromString returns a new card code given a string. The string must be 2 characters long. The first character must be a valid rank. The second character must be a valid suit.

func CodesFromStrings added in v0.2.0

func CodesFromStrings(cc ...string) ([]Code, error)

CodesFromStrings returns a collection of codes given a collection of string.

func (Code) Rank

func (c Code) Rank() string

Rank returns the rank.

func (Code) String

func (c Code) String() string

String implements the Stringer interface.

func (Code) Suit

func (c Code) Suit() string

Suit returns the suit.

type Rank

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

Rank represents the rank of a card.

func NewRank

func NewRank(name, code string) Rank

NewRank returns a new rank given a name and code.

func (Rank) Code

func (r Rank) Code() string

Code returns the code of the rank.

func (Rank) String

func (r Rank) String() string

String implements the Stringer interface.

type Ranks

type Ranks []Rank

Ranks is a collection of Rank.

func (Ranks) RankFromCode

func (rs Ranks) RankFromCode(c Code) (*Rank, error)

RankFromCode returns the rank from the given code.

func (Ranks) Ranks

func (rs Ranks) Ranks() []Rank

Ranks returns the french ranks.

type Suit

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

Suit represents the suit of a card.

func NewSuit

func NewSuit(name, code string) Suit

NewSuit returns a new suit given a name and code.

func (Suit) Code

func (s Suit) Code() string

Code returns the code of the suit.

func (Suit) String

func (s Suit) String() string

String implements the Stringer interface.

type Suits

type Suits []Suit

Suits is a collection of Suit.

func (Suits) SuitFromCode

func (ss Suits) SuitFromCode(c Code) (*Suit, error)

SuitFromCode returns the suit from the given code.

func (Suits) Suits

func (ss Suits) Suits() []Suit

Suits returns the french suits.

Jump to

Keyboard shortcuts

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