cards

package
v0.0.0-...-014f423 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const NumTypes = len(cardStr)

The number of distinct types of Cards.

Variables

Cards in the 2-player core deck in the iOS app. Does not include the ExplodingKitten, or the Defuse

Smaller deck for testing.

Functions

This section is empty.

Types

type Card

type Card uint8

Card represents one card from the Exploding Kittens game deck.

const (
	Unknown Card = iota
	ExplodingKitten
	Defuse
	Skip
	Slap1x
	Slap2x
	SeeTheFuture
	Shuffle
	DrawFromTheBottom
	Cat
	// Placeholder used for cards that have not been determinized yet.
	TBD
)

func (Card) String

func (c Card) String() string

String implements Stringer.

type Set

type Set uint64

Set represents an unordered set of cards. Set[Card] is the number of that Card in the set.

The maximum value for a single type of Card is 63. Therefore the counts for all Cards can fit in a single uint64: 6 bits per Card x 10 types of Cards = 60 bits.

func NewSet

func NewSet() Set

func NewSetFromCards

func NewSetFromCards(cards []Card) Set

NewSetFromCards creates a new Set from the given slice of Cards.

func (*Set) Add

func (s *Set) Add(card Card)

Add includes one of the given Card in the Set.

func (*Set) AddAll

func (s *Set) AddAll(cards Set)

AddAll adds the given cards to the Set.

func (*Set) AddN

func (s *Set) AddN(card Card, n int)

func (Set) AsSlice

func (s Set) AsSlice() []Card

AsSlice returns a slice of Cards with the given number of each Card as found in this Set.

func (Set) Contains

func (s Set) Contains(card Card) bool

Contains returns whether the Set contains at least one of the given type of Card.

func (Set) CountOf

func (s Set) CountOf(card Card) uint8

CountOf gets the number of the given type of Card in the Set.

func (Set) Counts

func (s Set) Counts() map[Card]uint8

Counts returns a map of the number of each type of card in this Set.

func (Set) Distinct

func (s Set) Distinct() []Card

Distinct gets a slice of the distinct Cards in the Set.

func (Set) IsEmpty

func (s Set) IsEmpty() bool

IsEmpty returns whether this Set contains any Cards.

func (Set) Iter

func (s Set) Iter(cb func(card Card, count uint8))

func (Set) Len

func (s Set) Len() int

Len gets the total number of Cards in the Set.

func (*Set) Remove

func (s *Set) Remove(card Card)

Remove removes one of the given Card from the Set. Remove panics if the card is not present in the Set.

func (*Set) RemoveAll

func (s *Set) RemoveAll(cards Set)

RemoveAll removes the given cards from the set. RemoveAll panics if the cards are not present to be removed.

func (*Set) RemoveN

func (s *Set) RemoveN(card Card, n int)

func (Set) String

func (s Set) String() string

String implements Stringer.

type Stack

type Stack uint64

Stack represents an ordered pile of cards, some of which may be unknown.

The pile is encoded as a hexadecimal integer, where each digit (4 bits) corresponds to the identity of a Card. The top card in the pile is always the lowest order digit.

NOTE: This implementation relies on the fact that there are at most 13 cards in the draw pile, and 10 distinct cards. Therefore, we can represent the identity of each card using 4 bits, and the identities of all 13 cards in the pile in 13 * 4 = 52 bits, or a single uint64. Cards that are Unknown are set to zero.

func NewStack

func NewStack() Stack

func NewStackFromCards

func NewStackFromCards(cards []Card) Stack

NewStack creates a new Stack from the given slice of Cards.

func (*Stack) InsertCard

func (s *Stack) InsertCard(card Card, n int)

InsertCard places the given card inserted in the Nth position.

func (Stack) IsEmpty

func (s Stack) IsEmpty() bool

func (Stack) Iter

func (s Stack) Iter(cb func(card Card))

func (Stack) Len

func (s Stack) Len() int

Len is the number of cards in the Stack. Note that Unknown cards on the ends of the stack are not counted.

Len is O(n) for the number of Cards in the Stack.

func (Stack) NthCard

func (s Stack) NthCard(n int) Card

NthCard returns the identity of the card in the Nth position of the stack. The Card may be Unknown.

func (*Stack) RemoveCard

func (s *Stack) RemoveCard(n int)

RemoveCard removes the Card in the Nth position.

func (*Stack) SetNthCard

func (s *Stack) SetNthCard(n int, card Card)

SetNthCard returns a new CardPile with the identity of the Nth card in the stack set to card.

func (Stack) String

func (s Stack) String() string

String implements Stringer.

func (Stack) ToSet

func (s Stack) ToSet() Set

Jump to

Keyboard shortcuts

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