poker

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: MIT Imports: 4 Imported by: 0

README

Poker hand evaluator

This go package provides a reasonably fast poker hand evaluator.

It can evaluate 3-card and 5-card hands, and provides a function for finding the best 5-card hand out of a set of 7 cards (for example, to find the rank of a Texas Holdem or 7-card stud hand.

Here's the package documentation on godoc

The code is MIT licensed (see LICENSE.txt).

Documentation

Overview

Package poker provides functions for poker tools.

Index

Constants

View Source
const (
	Club    = Suit(0)
	Diamond = Suit(1)
	Heart   = Suit(2)
	Spade   = Suit(3)

	BadSuit = Suit(255)
)
View Source
const ScoreMax = 7929

ScoreMax is the largest possible result from Eval (with replace=true).

Variables

View Source
var Cards []Card

Cards is a full deck of all cards. Sorted by suit and then rank.

View Source
var NameToCard = map[string]Card{}

NameToCard maps card names (for example, "C8" or "HA") to a card value.

Functions

func Describe

func Describe(c []Card) (string, error)

Describe fully describes a 3, 5 or 7 card poker hand.

func DescribeShort

func DescribeShort(c []Card) (string, error)

Describe describes a 3, 5 or 7 card poker hand with enough detail to compare it to another poker hand which shares no cards in common. For example, KKK-87 is represented as KKK-x-y since the kickers can never matter (except that they are different).

func Eval

func Eval(c []Card) int16

Eval takes a 3- or 5- card poker hand and returns a number which can be used to rank it against other poker hands. The returned value is in the range 0 to ScoreMax.

func Eval3

func Eval3(c *[3]Card) int16

Eval3 is an optimized version of Eval which requires a 3-card hand.

func Eval5

func Eval5(c *[5]Card) int16

Eval5 is an optimized version of Eval which requires a 5-card hand.

func Eval7

func Eval7(c *[7]Card) int16

Eval7 returns the ranking of the best 5-card hand that's a subset of the given 7 cards.

Types

type Card

type Card uint16

A Card is a single playing card. The top two bits are the suit, and the lowest 6 bits store the (r-1)th prime number. This representation enables fast hand evaluation. Heavily based on the ideas from Cactus Pete's poker hand evaluator, which can be found here: See http://www.suffecool.net/poker/evaluator.html

func EvalToHand3

func EvalToHand3(e int16) ([]Card, bool)

EvalToHand3 returns an example 3-card hand with the given eval score. The second return value is whether the result is valid.

func EvalToHand5

func EvalToHand5(e int16) ([]Card, bool)

EvalToHand5 returns an example 5-card hand with the given eval score. The second return value is whether the result is valid.

func MakeCard

func MakeCard(s Suit, r Rank) (Card, error)

MakeCard constructs a card from a suit and rank.

func (Card) Rank

func (c Card) Rank() Rank

Rank returns the rank of a card.

func (Card) RawRank

func (c Card) RawRank() int

RawRank returns a number from 0 to 12 representing the strength of the card. 2->0, 3->1, ..., K->11, A->12.

func (Card) String

func (c Card) String() string

func (Card) Suit

func (c Card) Suit() Suit

Suit returns the suit of a card. It may return BadSuit if the card isn't valid, but may also return a valid suit.

func (Card) Valid

func (c Card) Valid() bool

Valid reports whether the card is a valid card.

type Equity

type Equity struct {
	Equity float64 // total equity in the pot
	Win    float64 // equity gained from outright winning the pot
	Tie    float64 // probability of tieing with 1 or more hands
	Boards int     // how many runouts were computed
}

func HoldemEquities

func HoldemEquities(hands [][2]Card, board []Card) ([]Equity, error)

HoldemEquities returns the river equities for the given holdem hands given a board of up to 5 cards. The hands and board must be distinct, and the board can't have more than 5 cards in it.

type Rank

type Rank int

A Rank describes the rank of a card: A23456789TJQK. Ace is 1, King is 13.

func (Rank) String

func (r Rank) String() string

type Suit

type Suit uint8

A Suit is a suit: clubs, diamonds, hearts or spades.

func (Suit) String

func (s Suit) String() string

Directories

Path Synopsis
cmd
holdemeval
Binary holdemeval computes exact holdem hand equities for a given set of hands.
Binary holdemeval computes exact holdem hand equities for a given set of hands.

Jump to

Keyboard shortcuts

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