Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadCard = errors.New("invalid card string")
ErrBadCard is the error returned by ParseCardBytes if the passed []byte does not match the correct format
Functions ¶
func HandValue ¶
HandValue takes five cards, and returns an integer [1, 7462] representing their rank among all possible 5-card poker hands. Lower is better (e.g. a royal flush is 1, a 7-5-4-3-2 offsuit is 7462).
WARNING: Passing an ill-formed combination of 5 cards will result in undefined behavior, and may cause anything from a segmentation fault to completely silent failure. Ill-formed combinations include nonsensical cards, or hands that include duplicate cards. HandValue most often recieves values from internal, not external sources so it intentionally does not perform checks on the values it is passed to optimize performance. If you intend to pass HandValue data directly from an external source it is your responsibility to ensure the integrity of that data.
Types ¶
type Card ¶
type Card int32
Card is the type representing a single laying card. It is 32 bits long, packed according to the following schematic:
+--------+--------+--------+--------+ |xxxbbbbb|bbbbbbbb|cdhsrrrr|xxpppppp| +--------+--------+--------+--------+ p = prime number of rank (deuce=2,trey=3,four=5,...,ace=41) r = rank of card (deuce=0,trey=1,four=2,five=3,...,ace=12) cdhs = suit of card (bit turned on based on suit of card) b = bit turned on depending on rank of card
func BestFiveOfSeven ¶
BestFiveOfSeven uses HandValue as an oracle to find the optimal combination of 5 cards from the 7 passed in. BestFiveOfSeven returns a slice of the 5 cards which make up the best hand, and the score associated with that hand (lower is better).
WARNING: See the warning associated with HandValue.
func BestFiveOfSix ¶
BestFiveOfSix uses HandValue as an oracle to find the optimal combination of 5 cards from the 6 passed in. BestFiveOfSix returns a slice of the 5 cards which make up the best hand, and the score associated with that hand (lower is better).
WARNING: See the warning associated with HandValue.
func MustParseCardBytes ¶
MustParseCardBytes is the same as ParseCardBytes, except it panics if b is not in L
func MustParseCardString ¶
MustParseCardString is the same as MustParseCardBytes, except it takes a string as an arg
func ParseCardBytes ¶
ParseCardBytes is a helper function that will convert a human-readable representation of a card to the equivalent 32 bit layout. It accepts strings composed of a rank concatenated with a suit. The rank may be 2-10,T,J,Q,K, or A, and the suit may be C, D, H, or S. It is not case sensative, and 10 and T are equivalent. It discards whitespace before and after. More precisely, it accepts the language L defined by:
^\s*(10|[2-9]|[TJQKAtjqka])([CDHScdhs])\s*$
Should there be a conflict between the plain english and the regular expression, the regular expression takes precedence. If b is not in L, ParseCardBytes returns an error value. Otherwise, it returns a Card in native format and nil
func (Card) Scan ¶
Scan wraps ParseCardBytes to satisfy the fmt.Scanner interface If ParseCardBytes returns an error, c is guaranteed not to change
func (Card) String ¶
CardToString outputs a human-readable representation of a Card. Unlike Scan, this may be useful for creating serialized GameViews for the end user. The returned string will be in all uppercase, and the rank 10 will be represented using the letter T. Calling this method on an poorly formed card will result in undefined behavior.
type Deck ¶
type Deck []Card
Deck is the basic type representing a deck of playing cards
var DefaultDeck Deck
DefaultDeck contains all 52 cards. It may be ordered, but that is not guaranteed in the future
func (Deck) Marshal ¶
Marshal returns an empty interface, the underlying type of which is a string, or []byte. The string is a binary representation of the deck, and the characters within are not guaranteed to be printable. Marshal returns an error if the internal write operation fails.
func (*Deck) Push ¶
Push places card onto the top of the deck. Useful for constructing known orderings, if you want.