Documentation ¶
Index ¶
- Constants
- Variables
- type Card
- type Set
- func (s *Set) Add(card Card)
- func (s *Set) AddAll(cards Set)
- func (s *Set) AddN(card Card, n int)
- func (s Set) AsSlice() []Card
- func (s Set) Contains(card Card) bool
- func (s Set) CountOf(card Card) uint8
- func (s Set) Counts() map[Card]uint8
- func (s Set) Distinct() []Card
- func (s Set) IsEmpty() bool
- func (s Set) Iter(cb func(card Card, count uint8))
- func (s Set) Len() int
- func (s *Set) Remove(card Card)
- func (s *Set) RemoveAll(cards Set)
- func (s *Set) RemoveN(card Card, n int)
- func (s Set) String() string
- type Stack
- func (s *Stack) InsertCard(card Card, n int)
- func (s Stack) IsEmpty() bool
- func (s Stack) Iter(cb func(card Card))
- func (s Stack) Len() int
- func (s Stack) NthCard(n int) Card
- func (s *Stack) RemoveCard(n int)
- func (s *Stack) SetNthCard(n int, card Card)
- func (s Stack) String() string
- func (s Stack) ToSet() Set
Constants ¶
const NumTypes = len(cardStr)
The number of distinct types of Cards.
Variables ¶
var CoreDeck = NewSetFromCards([]Card{ Skip, Skip, Skip, Skip, Skip, Slap1x, Slap1x, Slap1x, Slap2x, SeeTheFuture, SeeTheFuture, SeeTheFuture, Shuffle, Shuffle, DrawFromTheBottom, DrawFromTheBottom, Cat, Cat, Cat, })
Cards in the 2-player core deck in the iOS app. Does not include the ExplodingKitten, or the Defuse
var TestDeck = NewSetFromCards([]Card{ SeeTheFuture, Slap1x, Slap2x, Skip, DrawFromTheBottom, Cat, })
Smaller deck for testing.
Functions ¶
This section is empty.
Types ¶
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 NewSetFromCards ¶
NewSetFromCards creates a new Set from the given slice of Cards.
func (Set) AsSlice ¶
AsSlice returns a slice of Cards with the given number of each Card as found in this Set.
func (Set) Contains ¶
Contains returns whether the Set contains at least one of the given type of Card.
func (*Set) Remove ¶
Remove removes one of the given Card from the Set. Remove panics if the card is not present in the Set.
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 NewStackFromCards ¶
NewStack creates a new Stack from the given slice of Cards.
func (*Stack) InsertCard ¶
InsertCard places the given card inserted in the Nth position.
func (Stack) Len ¶
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 ¶
NthCard returns the identity of the card in the Nth position of the stack. The Card may be Unknown.
func (*Stack) RemoveCard ¶
RemoveCard removes the Card in the Nth position.
func (*Stack) SetNthCard ¶
SetNthCard returns a new CardPile with the identity of the Nth card in the stack set to card.