cards

package
v0.0.0-...-c5f2fd3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrettyCardsString

func PrettyCardsString(h []Card) string

Types

type Card

type Card struct {
	Color
	Value
}

Card UNO card type

func NewVanilla

func NewVanilla(opts ...Option) []Card

NewVanilla returns a vanilla set of UNO cards

func Shuffle

func Shuffle(cards []Card) []Card

Shuffle returns a copy of cards in a random order for true randomness, remember to set a seed to the rand package

func (Card) String

func (c Card) String() string
Example
fmt.Println(Card{Color: Red, Value: Reverse})
fmt.Println(Card{Color: Yellow, Value: One})
fmt.Println(Card{Color: Green, Value: Skip})
fmt.Println(Card{Color: Blue, Value: Nine})
fmt.Println(Card{Color: Wild, Value: DrawFour})
fmt.Println(Card{Color: Wild, Value: Choose})
Output:

Red Reverse
Yellow One
Green Skip
Blue Nine
Wild Draw Four
Wild Choose

type Color

type Color uint8

Color represents the color of a UNO card

const (
	Wild Color = iota
	Red
	Yellow
	Green
	Blue
)

UNO card colors, Wild represents black cards

func (Color) String

func (i Color) String() string

type Option

type Option func([]Card) []Card

func Filter

func Filter(f func(c Card) bool) Option

Filter returns a new slice of cards, containing only the cards that pass the filter function

func Multiply

func Multiply(n int) Option

Multiply returns an option that copies all cards in a deck X amount of times

type Value

type Value uint8

Value represents the value of a UNO card

const (
	Zero Value = iota
	One
	Two
	Three
	Four
	Five
	Six
	Seven
	Eight
	Nine
	Skip
	Reverse
	DrawTwo  //Draw Two
	DrawFour //Draw Four
	Choose
)

UNO card values

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