game

package
v0.0.0-...-2c2e33e Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeckCapacity = int(SuitsTotalCount) * int(ValuesTotalCount)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Suit
	Value
}

func ParseCard

func ParseCard(str string) (Card, error)

ParseCard will parse the given string into a card object from short ("ad") or long ("ace of diamonds") forms

func (Card) ShortString

func (c Card) ShortString() string

ShortString will return something like "ah"

func (Card) String

func (c Card) String() string

String will return something like "ace of hearts"

type Deck

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

func DeckDeserialize

func DeckDeserialize(str string) (*Deck, error)

func NewDeck

func NewDeck() *Deck

NewDeck initializes the deck with 52 unique cards in sorted order

func (*Deck) DealCard

func (d *Deck) DealCard() (Card, error)

DealCard removes the top card from the deck (subtracts it from the slice's front) and returns it

func (*Deck) Len

func (d *Deck) Len() int

Len returns the current deck's size

func (*Deck) ReturnCard

func (d *Deck) ReturnCard(card Card) error

ReturnCard adds the given card to the deck (at the end of the slice)

func (*Deck) Serialize

func (d *Deck) Serialize() string

func (*Deck) Shuffle

func (d *Deck) Shuffle()

Shuffle permutes the deck of cards using a pseudo-random algorithm seeded at deck creation time

type Suit

type Suit uint8

Suit represents one of the 4 card categories (Clubs / Hearts / Diamonds / Spades)

const (
	SuitClubs Suit = iota
	SuitHearts
	SuitDiamonds
	SuitSpades
	SuitsTotalCount // the total number of suits
)

Suit values

func ParseSuit

func ParseSuit(str string) (Suit, error)

ParseSuit will parse a suit string in short (c) or long (clubs) forms

func (Suit) ShortString

func (s Suit) ShortString() string

Short string representation of the suit, used for persistence

func (Suit) String

func (s Suit) String() string

String representation of the suit

type Value

type Value uint8

Value represents one of the 13 card face values (Ace - King)

const (
	ValueAce Value = iota
	ValueTwo
	ValueThree
	ValueFour
	ValueFive
	ValueSix
	ValueSeven
	ValueEight
	ValueNine
	ValueTen
	ValueJack
	ValueQueen
	ValueKing
	ValuesTotalCount // a marker for the end of this enum
)

Value values

func ParseValue

func ParseValue(str string) (Value, error)

ParseValue will parse the given card value string in short (a) or long (ace) forms

func (Value) ShortString

func (v Value) ShortString() string

func (Value) String

func (v Value) String() string

Jump to

Keyboard shortcuts

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