deck

package
v0.0.0-...-56ad08b Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddJokers

func AddJokers(n int) func(Deck) Deck

AddJokers adds a number of jokers to the deck.

func FilterCard

func FilterCard(remove ...Card) func(Deck) Deck

FilterCard removes all copies of a specific card from the deck.

func FilterDeck

func FilterDeck(exclude Deck) func(Deck) Deck

FilterDeck removes all cards of a deck from the other.

func Multiply

func Multiply(n int) func(Deck) Deck

Multiply adds n decks to the current deck.

func Shuffle

func Shuffle() func(Deck) Deck

Shuffle shuffles the deck (doh). Our shuffling going to be "craptographically" secure because we are using math/rand.Shuffle.

func Sort

func Sort() func(Deck) Deck

Sort sorts the deck.

Types

type Card

type Card struct {
	Suit
	Value
}

Card represents a playing card.

func CreateJoker

func CreateJoker() Card

CreateJoker returns a joker Card. TODO: Value of 1 for joker might not make any difference unless it's assigned a numerical value later in the exercise.

func (Card) String

func (c Card) String() string

String is the stringer for Card.

type Deck

type Deck struct {
	Cards []Card
}

Deck represents a pack of cards.

func New

func New(opts ...func(Deck) Deck) Deck

New generates a deck of cards with options. Options are in form of functions with this signature "func(Deck) Deck" They are executed on the deck and each transforms the deck.

func NewDefault

func NewDefault() Deck

NewDefault generates a new deck without jokers or any options.

func (Deck) Contains

func (d Deck) Contains(c Card) bool

Contains checks if a specific card is in the deck.

func (Deck) Len

func (d Deck) Len() int

Len returns the number of cards in the deck.

func (Deck) Less

func (d Deck) Less(i, j int) bool

Less is the comparison function used for sorting the deck.

func (Deck) String

func (d Deck) String() string

String is stringer for deck and prints all deck cards.

func (Deck) Swap

func (d Deck) Swap(i, j int)

Swap performs a swap on two cards in the deck.“

type Suit

type Suit int

Suit represents the card Suit.

const (
	Spade Suit = iota
	Diamond
	Club
	Heart
	Joker // Added after seeing the joker requirement.
)

Seems like the sequence here is important. Spades come first.

func (Suit) String

func (i Suit) String() string

type Value

type Value int

Value is the card's value.

const (
	Ace Value = iota + 1
	Two
	Three
	Four
	Five
	Six
	Seven
	Eight
	Nine
	Ten
	Jack
	Queen
	King
)

func (Value) String

func (i Value) String() string

Jump to

Keyboard shortcuts

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