Documentation ¶
Index ¶
- Constants
- Variables
- func BestHand(p *Player, tableCards Cards) (Cards, HandKind)
- type Board
- type BoardState
- type Cards
- func Flush(cards Cards) (winningCards Cards, found bool)
- func FourOfAKind(cards Cards) (winningCards Cards, found bool)
- func FullHouse(cards Cards) (winningCards Cards, found bool)
- func HighCard(cards Cards) (winningCards Cards, found bool)
- func JoinCards(cards ...Cards) Cards
- func NewCard(cardStr string) Cards
- func Pair(cards Cards) (winningCards Cards, found bool)
- func RoyalFlush(cards Cards) (winningCards Cards, found bool)
- func Straight(cards Cards) (winningCards Cards, found bool)
- func StraightFlush(cards Cards) (winningCards Cards, found bool)
- func ThreeOfAKind(cards Cards) (winningCards Cards, found bool)
- func TwoPair(cards Cards) (winningCards Cards, found bool)
- func (c Cards) AddCards(cardsToAdd Cards) Cards
- func (c Cards) BitToggle(pos int) Cards
- func (c Cards) CardsArePresent(cards Cards) bool
- func (c Cards) ClearBit(pos int) Cards
- func (c Cards) Count() int
- func (c Cards) HasBit(pos int) bool
- func (c Cards) QuitCards(cardsToQuit Cards) Cards
- func (c Cards) SetBit(pos int) Cards
- func (c Cards) Split() []Cards
- func (c Cards) String() string
- type Deck
- type Game
- type HandKind
- type Player
- type PlayerHandValue
Constants ¶
const ( MAX_CARDS = 4 * 13 // suits * cards per suit MAX_CARDS_IN_BOARD = 5 MAX_BURNED_CARDS = 3 MAX_CARDS_PER_HAND = 2 )
const ( CLUBS = FIRST_SUIT << (iota * 13) DIAMONDS HEARTS SPADES )
Variables ¶
var ( TOTAL_CARDS = len(SUIT_VALUES) * len(NUMBER_VALUES) SUIT_VALUES = map[Cards]string{ DIAMONDS: "d", CLUBS: "c", HEARTS: "h", SPADES: "s", } NUMBER_VALUES = map[Cards]string{ ACES: "A", KINGS: "K", QUEENS: "Q", JACKS: "J", TENS: "T", NINES: "9", EIGHTS: "8", SEVENS: "7", SIXS: "6", FIVES: "5", FOURS: "4", THREES: "3", TWOS: "2", } )
Functions ¶
Types ¶
type Board ¶
type Board struct { TableCards []Cards BurnedCards []Cards State BoardState // contains filtered or unexported fields }
Board represents a table where you can access to the current flipped cards, burned cards, and the board state (preflop, flop, etc.).
func NewBoard ¶
NewBoard creates a board with an specific deck, and sets the boards as the initial state.
func (*Board) NextBoardState ¶
NextBoardState add corresponding cards to TableCards and BurnedCards, depending on the current State. Returns an error if there are no more cards in deck, or if you try to get next state in the SHOWDOWN.
type Cards ¶
type Cards uint64
Cards represents a set of cards joined into an uint64 where each bit represent one card from the deck. From the 0 to 12 one suit, 13 to 25 other one, etc.
func Flush ¶
Flush receives a set of cards, if it is possible to find a Flush combination, returns the best combination and true, in another case, random cards, and false.
func FourOfAKind ¶
FourOfAKind receives a set of cards, if it is possible to find a FourOfAKind combination, returns the best combination and true, in another case, random cards, and false.
func FullHouse ¶
FullHouse receives a set of cards, if it is possible to find a FullHouse combination, returns the best combination and true, in another case, random cards, and false.
func HighCard ¶
HighCard receives a set of cards, if it is possible to find a HighCard combination, returns the best combination and true, in another case, random cards, and false.
func NewCard ¶
NewCard reads the string and returns the card, only if string has valid number and suit.
Valid numbers are A K Q J T 9 8 7 6 5 4 3 2.
Valid suits are s c h d.
An example of card in string is "Ah".
func Pair ¶
Pair receives a set of cards, if it is possible to find a Pair combination, returns the best combination and true, in another case, random cards, and false.
func RoyalFlush ¶
RoyalFlush receives a set of cards, if it is possible to find a RoyalFlush combination, returns the best combination and true, in another case, random cards, and false.
func Straight ¶
Straight receives a set of cards, if it is possible to find a Straight combination, returns the best combination and true, in another case, random cards, and false.
func StraightFlush ¶
StraightFlush receives a set of cards, if it is possible to find a StraightFlush combination, returns the best combination and true, in another case, random cards, and false.
func ThreeOfAKind ¶
ThreeOfAKind receives a set of cards, if it is possible to find a ThreeOfAKind combination, returns the best combination and true, in another case, random cards, and false.
func TwoPair ¶
TwoPair receives a set of cards, if it is possible to find a TwoPair combination, returns the best combination and true, in another case, random cards, and false.
func (Cards) AddCards ¶
AddCards receives cardsToAdd, and returns the original card with cardsToAdd.
func (Cards) BitToggle ¶
BitToggle toggles the bit in that position.
Warning!! Use only if you know how the `Cards uint64` is built.
func (Cards) CardsArePresent ¶
CardsArePresent returns true if any of cards passed is present.
func (Cards) ClearBit ¶
ClearBit clears the bit in that position.
Warning!! Use only if you know how the `Cards uint64` is built.
func (Cards) HasBit ¶
HasBit returns true if there is a bit marked as 1 in that position.
Warning!! Use only if you know how the `Cards uint64` is built.
func (Cards) QuitCards ¶
QuitCards receives cardsToQuit, and returns the original card without cardsToQuit.
func (Cards) SetBit ¶
SetBit sets the bit in that position.
Warning!! Use only if you know how the `Cards uint64` is built.
type Deck ¶
type Deck struct {
// contains filtered or unexported fields
}
Deck represents a deck with the 52 cards, you should always call NewDeck to build a deck.
func NewDeck ¶
func NewDeck() *Deck
NewDeck fills the deck with the 52 cards, and returns the reference to this deck.
func (*Deck) GetNextCard ¶
GetNextCard returns the next card in the deck, and moves the pointer to the next card.
type Player ¶
type Player struct { Name string Hand Cards Coins uint BetCoins uint HasFolded bool HasChecked bool }
Player stores all the player information.
type PlayerHandValue ¶
PlayerHandValue is a structure to represent what is the best hand the player can have, and which kind of hand is (HIGHCARD, PAIR, etc.).
func GetWinners ¶
func GetWinners(tableCards Cards, players []*Player) []PlayerHandValue
GetWinners returns an array with the players with the best hand (it can be one or more than one)