pokerlib

package module
v0.0.0-...-fb9c7b5 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: Apache-2.0 Imports: 13 Imported by: 2

README

pokerlib

pokerlib is poker game engine written in golang.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoDeck                      = errors.New("game: no deck")
	ErrNotEnoughBackroll           = errors.New("game: backroll is not enough")
	ErrNoDealer                    = errors.New("game: no dealer")
	ErrInsufficientNumberOfPlayers = errors.New("game: insufficient number of players")
	ErrUnknownRound                = errors.New("game: unknown round")
	ErrNotFoundDealer              = errors.New("game: not found dealer")
	ErrUnknownTask                 = errors.New("game: unknown task")
	ErrNotClosedRound              = errors.New("game: round is not closed")
)
View Source
var (
	ErrInvalidAction = errors.New("player: invalid action")
	ErrIllegalRaise  = errors.New("player: illegal raise")
)
View Source
var CardPoints = []string{
	"2",
	"3",
	"4",
	"5",
	"6",
	"7",
	"8",
	"9",
	"T",
	"J",
	"Q",
	"K",
	"A",
}
View Source
var CardSuits = []string{
	"S",
	"H",
	"D",
	"C",
}
View Source
var GameEventBySymbol = map[string]GameEvent{
	"Started":             GameEvent_Started,
	"Initialized":         GameEvent_Initialized,
	"Prepared":            GameEvent_Prepared,
	"AnteRequested":       GameEvent_AnteRequested,
	"AntePaid":            GameEvent_AntePaid,
	"BlindsRequested":     GameEvent_BlindsRequested,
	"BlindsPaid":          GameEvent_BlindsPaid,
	"ReadyRequested":      GameEvent_ReadyRequested,
	"Readiness":           GameEvent_Readiness,
	"PreflopRoundEntered": GameEvent_PreflopRoundEntered,
	"FlopRoundEntered":    GameEvent_FlopRoundEntered,
	"TurnRoundEntered":    GameEvent_TurnRoundEntered,
	"RiverRoundEntered":   GameEvent_RiverRoundEntered,
	"RoundInitialized":    GameEvent_RoundInitialized,
	"RoundPrepared":       GameEvent_RoundPrepared,
	"RoundStarted":        GameEvent_RoundStarted,
	"RoundClosed":         GameEvent_RoundClosed,
	"GameCompleted":       GameEvent_GameCompleted,
	"SettlementRequested": GameEvent_SettlementRequested,
	"SettlementCompleted": GameEvent_SettlementCompleted,
	"GameClosed":          GameEvent_GameClosed,
}
View Source
var GameEventSymbols = map[GameEvent]string{
	GameEvent_Started:             "Started",
	GameEvent_Initialized:         "Initialized",
	GameEvent_Prepared:            "Prepared",
	GameEvent_AnteRequested:       "AnteRequested",
	GameEvent_AntePaid:            "AntePaid",
	GameEvent_BlindsRequested:     "BlindsRequested",
	GameEvent_BlindsPaid:          "BlindsPaid",
	GameEvent_ReadyRequested:      "ReadyRequested",
	GameEvent_Readiness:           "Readiness",
	GameEvent_PreflopRoundEntered: "PreflopRoundEntered",
	GameEvent_FlopRoundEntered:    "FlopRoundEntered",
	GameEvent_TurnRoundEntered:    "TurnRoundEntered",
	GameEvent_RiverRoundEntered:   "RiverRoundEntered",
	GameEvent_RoundInitialized:    "RoundInitialized",
	GameEvent_RoundPrepared:       "RoundPrepared",
	GameEvent_RoundStarted:        "RoundStarted",
	GameEvent_RoundClosed:         "RoundClosed",
	GameEvent_GameCompleted:       "GameCompleted",
	GameEvent_SettlementRequested: "SettlementRequested",
	GameEvent_SettlementCompleted: "SettlementCompleted",
	GameEvent_GameClosed:          "GameClosed",
}

Functions

func NewGame

func NewGame(opts *GameOptions) *game

func NewGameFromState

func NewGameFromState(gs *GameState) *game

func NewShortDeckCards

func NewShortDeckCards() []string

func NewStandardDeckCards

func NewStandardDeckCards() []string

func ShuffleCards

func ShuffleCards(cards []string) []string

Types

type Action

type Action struct {
	Source int    `json:"source"`
	Type   string `json:"type"`
	Value  int64  `json:"value,omitempty"`
}

type BlindSetting

type BlindSetting struct {
	Dealer int64 `json:"dealer"`
	SB     int64 `json:"sb"`
	BB     int64 `json:"bb"`
}

type CardSuit

type CardSuit int32
const (
	CardSuitSpade CardSuit = iota
	CardSuitHeart
	CardSuitDiamond
	CardSuitClub
)

type CombinationInfo

type CombinationInfo struct {
	Type  string   `json:"type"`
	Cards []string `json:"cards"`
	Power int      `json:"power"`
}

type Game

type Game interface {
	ApplyOptions(opts *GameOptions) error
	Start() error
	Resume() error
	GetEvent() string
	GetState() *GameState
	GetStateJSON() ([]byte, error)
	LoadState(gs *GameState) error
	Player(idx int) Player
	Dealer() Player
	SmallBlind() Player
	BigBlind() Player
	Deal(count int) []string
	Burn(count int) error
	BecomeRaiser(Player) error
	ResetActedPlayers() error
	ResetAllPlayerStatus() error
	StartAtDealer() (Player, error)
	GetPlayerCount() int
	GetPlayers() []Player
	SetCurrentPlayer(Player) error
	GetCurrentPlayer() Player
	GetAllowedActions(Player) []string
	GetAvailableActions(Player) []string
	GetAlivePlayerCount() int
	GetMovablePlayerCount() int
	UpdateLastAction(source int, ptype string, value int64) error
	EmitEvent(event GameEvent) error
	PrintState() error
	PrintPots()

	// Operations
	Next() error
	ReadyForAll() error
	PayAnte() error
	PayBlinds() error

	// Actions
	Pass() error
	Pay(chips int64) error
	Fold() error
	Check() error
	Call() error
	Allin() error
	Bet(chips int64) error
	Raise(chipLevel int64) error
}

type GameEvent

type GameEvent int32
const (

	// Initialization
	GameEvent_Started GameEvent = iota
	GameEvent_Initialized
	GameEvent_Prepared
	GameEvent_AnteRequested
	GameEvent_AntePaid
	GameEvent_BlindsRequested
	GameEvent_BlindsPaid
	GameEvent_ReadyRequested
	GameEvent_Readiness

	// Rounds
	GameEvent_PreflopRoundEntered
	GameEvent_FlopRoundEntered
	GameEvent_TurnRoundEntered
	GameEvent_RiverRoundEntered
	GameEvent_RoundInitialized
	GameEvent_RoundPrepared
	GameEvent_RoundStarted
	GameEvent_RoundClosed

	// Result
	GameEvent_GameCompleted
	GameEvent_SettlementRequested
	GameEvent_SettlementCompleted
	GameEvent_GameClosed
)

type GameOptions

type GameOptions struct {
	Ante                   int64                     `json:"ante"`
	Blind                  BlindSetting              `json:"blind"`
	Limit                  string                    `json:"limit"`
	HoleCardsCount         int                       `json:"hole_cards_count"`
	RequiredHoleCardsCount int                       `json:"required_hole_cards_count"`
	CombinationPowers      []combination.Combination `json:"combination_powers"`
	Deck                   []string                  `json:"deck"`
	BurnCount              int                       `json:"burn_count"`
	Players                []*PlayerSetting          `json:"players"`
}

func NewShortDeckGameOptions

func NewShortDeckGameOptions() *GameOptions

func NewStardardGameOptions

func NewStardardGameOptions() *GameOptions

type GameState

type GameState struct {
	GameID    string             `json:"game_id"`
	CreatedAt int64              `json:"created_at"`
	UpdatedAt int64              `json:"updated_at"`
	Meta      Meta               `json:"meta"`
	Status    Status             `json:"status"`
	Players   []*PlayerState     `json:"players"`
	Result    *settlement.Result `json:"result,omitempty"`
}

func (*GameState) AsObserver

func (gs *GameState) AsObserver()

func (*GameState) AsPlayer

func (gs *GameState) AsPlayer(idx int)

func (*GameState) GetPlayer

func (gs *GameState) GetPlayer(idx int) *PlayerState

func (*GameState) HasAction

func (gs *GameState) HasAction(idx int, action string) bool

func (*GameState) HasPosition

func (gs *GameState) HasPosition(idx int, position string) bool

type Meta

type Meta struct {
	Ante                   int64                     `json:"ante"`
	Blind                  BlindSetting              `json:"blind"`
	Limit                  string                    `json:"limit"`
	HoleCardsCount         int                       `json:"hole_cards_count"`
	RequiredHoleCardsCount int                       `json:"required_hole_cards_count"`
	CombinationPowers      combination.PowerRankings `json:"combination_powers"`
	Deck                   []string                  `json:"deck"`
	BurnCount              int                       `json:"burn_count"`
}

type Player

type Player interface {
	State() *PlayerState
	SeatIndex() int
	CheckAction(action string) bool
	CheckPosition(pos string) bool
	AllowActions(actions []string) error
	ResetAllowedActions() error
	Reset() error
	Pass() error
	Pay(chips int64) error
	PayAnte() error
	PayBlinds() error
	Fold() error
	Check() error
	Call() error
	Allin() error
	Bet(chips int64) error
	Raise(chipLevel int64) error
}

type PlayerSetting

type PlayerSetting struct {
	PlayerID  string   `json:"player_id"`
	Bankroll  int64    `json:"bankroll"`
	Positions []string `json:"positions"`
}

type PlayerState

type PlayerState struct {
	Idx       int      `json:"idx"`
	Positions []string `json:"positions"`

	// Status
	Acted          bool     `json:"acted"`
	DidAction      string   `json:"did_action,omitempty"`
	Fold           bool     `json:"fold"`
	VPIP           bool     `json:"vpip"` // Voluntarily Put In Pot
	AllowedActions []string `json:"allowed_actions,omitempty"`

	// Stack and wager
	Bankroll         int64 `json:"bankroll"`
	InitialStackSize int64 `json:"initial_stack_size"` // bankroll - pot
	StackSize        int64 `json:"stack_size"`         // initial_stack_size - wager
	Pot              int64 `json:"pot"`
	Wager            int64 `json:"wager"`

	// Hole cards information
	HoleCards   []string         `json:"hole_cards,omitempty"`
	Combination *CombinationInfo `json:"combination,omitempty"`
}

func (*PlayerState) AllowAction

func (ps *PlayerState) AllowAction(action string)

type PokerFace

type PokerFace interface {
	NewGame(opts *GameOptions) Game
	NewGameFromState(gs *GameState) Game
}

func NewPokerFace

func NewPokerFace() PokerFace

type RankInfo

type RankInfo struct {
	Player *PlayerState
	Power  *combination.PowerState
}

type Status

type Status struct {
	MiniBet             int64      `json:"mini_bet"`
	MaxWager            int64      `json:"max_wager"`
	Pots                []*pot.Pot `json:"pots"`
	Round               string     `json:"round,omitempty"`
	Burned              []string   `json:"burned,omitempty"`
	Board               []string   `json:"board,omitempty"`
	PreviousRaiseSize   int64      `json:"previous_raise_size"`
	CurrentDeckPosition int        `json:"current_deck_position"`
	CurrentRoundPot     int64      `json:"current_round_pot"`
	CurrentWager        int64      `json:"current_wager"`
	CurrentRaiser       int        `json:"current_raiser"`
	CurrentPlayer       int        `json:"current_player"`
	CurrentEvent        string     `json:"current_event"`
	LastAction          *Action    `json:"last_action,omitempty"`
}

Directories

Path Synopsis
cmd
pokergame command
shuffletest command

Jump to

Keyboard shortcuts

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