Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

holdem source pure

Package holdem implements the chain-independent rules of no-limit Texas Hold'em: hand evaluation, side pots and the b...

Overview

Package holdem implements the chain-independent rules of no-limit Texas Hold'em: hand evaluation, side pots and the betting state machine of one hand. Cards are indices 0..51 with rank = c % 13 (0 = Two .. 12 = Ace) and suit = c / 13.

Constants 3

const MaxPlayers

1const MaxPlayers = 6
source

MaxPlayers is the largest number of players in one hand.

Functions 7

func Category

1func Category(score int) int
source

Category returns the hand category of a score.

func CategoryName

1func CategoryName(score int) string
source

CategoryName names the category of a score.

func Distribute

1func Distribute(pots []Pot, scores []int, oddOrder []int) []int64
source

Distribute awards each pot to its best eligible scores, splitting ties equally. The odd chips of a split pot all go to the winner that comes first in oddOrder (player indices clockwise from the button). It returns the amount won per player; the sum always equals the sum of the pots. It panics for more than MaxPlayers scores.

func Evaluate

1func Evaluate(cards []int) int
source

Evaluate scores the best five-card hand among 5 to 7 cards. Higher is better; equal scores tie.

func OddChipOrder

1func OddChipOrder(n int) []int
source

OddChipOrder returns player indices clockwise starting left of the button, for hand players indexed from the small blind (heads-up: index 0 is the button). It panics unless 0 <= n <= MaxPlayers.

func NewBetting

1func NewBetting(stacks []int64, smallBlind, bigBlind int64) *Betting
source

NewBetting posts the blinds and sets the first player to act preflop.

func BuildPots

1func BuildPots(contrib []int64, folded []bool) []Pot
source

BuildPots splits contributions into a main pot and side pots. Folded players' chips go into the pots but they are never eligible. Chips above the largest contribution of any live player form a last pot that only the live players with that contribution can win (an uncalled bet returns to its owner this way).

Types 3

type Betting

struct
1type Betting struct {
2	Players    []*Player
3	SmallBlind int64
4	BigBlind   int64
5	Street     int
6	CurrentBet int64 // highest street bet
7	MinRaise   int64 // size of the last full bet or raise on this street
8	Turn       int   // index to act, -1 when the street needs no more action
9}
source

Betting is the no-limit betting state of one hand. Players are indexed from the small blind (heads-up: index 0 is the button and small blind).

Methods on Betting

func Act

method on Betting
1func (b *Betting) Act(i int, action string, amount int64) error
source

Act applies an action by player i. For "raise", amount is the player's total street bet after the action; it also opens the betting when nobody has bet.

func CanCheck

method on Betting
1func (b *Betting) CanCheck(i int) bool
source

CanCheck reports whether player i may check.

func CanRaise

method on Betting
1func (b *Betting) CanRaise(i int) bool
source

CanRaise reports whether player i may bet or raise: they have chips beyond a call, and either have not acted on this street or face at least a full raise since they last acted (a short all-in does not reopen the betting).

func Closed

method on Betting
1func (b *Betting) Closed() bool
source

Closed reports whether no further betting is possible in the hand: one live player left, or the street is complete and at most one live player still has chips.

func Live

method on Betting
1func (b *Betting) Live() int
source

Live returns the number of players who have not folded.

func MinRaiseTo

method on Betting
1func (b *Betting) MinRaiseTo() int64
source

MinRaiseTo returns the smallest legal total street bet for a non all-in bet or raise.

func NextStreet

method on Betting
1func (b *Betting) NextStreet()
source

NextStreet resets street state and sets the first player to act. It must only be called when the current street is complete and betting not closed.

func Pot

method on Betting
1func (b *Betting) Pot() int64
source

Pot returns the total contributed by all players.

func StreetComplete

method on Betting
1func (b *Betting) StreetComplete() bool
source

StreetComplete reports whether nobody has to act on this street.

type Player

struct
1type Player struct {
2	Stack       int64 // chips behind
3	StreetBet   int64 // chips put in on the current street
4	Contributed int64 // chips put in during the whole hand
5	Folded      bool
6	AllIn       bool
7	Acted       bool  // acted since the bet last increased
8	LastActBet  int64 // current bet right after this player's last action this street, -1 if none
9}
source

Player is one hand player's betting state.

type Pot

struct
1type Pot struct {
2	Amount   int64
3	Eligible []int // player indices that can win this pot
4}
source

Pot is one main or side pot.

Dependencies

Imports 1

/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/poker/holdem

Imported by indexer

Source Files 4