pwbtable

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

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

Go to latest
Published: Mar 16, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// General
	UnsetValue = -1

	// CompetitionMode
	CompetitionMode_Cash = "cash"

	// CompetitionRule
	CompetitionRule_Default   = "default"
	CompetitionRule_ShortDeck = "short_deck"
	CompetitionRule_Omaha     = "omaha"

	// Position
	Position_Unknown = "unknown"
	Position_Dealer  = "dealer"
	Position_SB      = "sb"
	Position_BB      = "bb"
	Position_UG      = "ug"
	Position_UG2     = "ug2"
	Position_UG3     = "ug3"
	Position_MP      = "mp"
	Position_MP2     = "mp2"
	Position_HJ      = "hj"
	Position_CO      = "co"

	// Action
	Action_Ready = "ready"
	Action_Pay   = "pay"

	// Wager Action
	WagerAction_Fold  = "fold"
	WagerAction_Check = "check"
	WagerAction_Call  = "call"
	WagerAction_AllIn = "allin"
	WagerAction_Bet   = "bet"
	WagerAction_Raise = "raise"

	// Round
	GameRound_Preflop = "preflop"
	GameRound_Flop    = "flop"
	GameRound_Turn    = "turn"
	GameRound_River   = "river"
)

Variables

View Source
var (
	ErrTableNoEmptySeats            = errors.New("table: no empty seats available")
	ErrTableInvalidCreateSetting    = errors.New("table: invalid create table setting")
	ErrTablePlayerNotFound          = errors.New("table: player not found")
	ErrTablePlayerInvalidGameAction = errors.New("table: player invalid game action")
	ErrTablePlayerInvalidAction     = errors.New("table: player invalid action")
	ErrTablePlayerSeatUnavailable   = errors.New("table: player seat unavailable")
	ErrTableOpenGameFailed          = errors.New("table: failed to open game")
)
View Source
var (
	ErrGamePlayerNotFound      = errors.New("game: player not found")
	ErrGameInvalidAction       = errors.New("game: invalid action")
	ErrGameUnknownEvent        = errors.New("game: unknown event")
	ErrGameUnknownEventHandler = errors.New("game: unknown event handler")
)
View Source
var (
	ErrManagerTableNotFound = errors.New("manager: table not found")
)

Functions

func FindDealerPlayerIndex

func FindDealerPlayerIndex(gameCount, prevDealerSeatIdx, minPlayingCount, maxSeatCount int, players []*TablePlayerState, seatMap []int) int

func FindGamePlayerIndexes

func FindGamePlayerIndexes(dealerSeatIdx int, seatMap []int, players []*TablePlayerState) []int

func GetPlayerPositionMap

func GetPlayerPositionMap(rule string, players []*TablePlayerState, gamePlayerIndexes []int) map[int][]string

func IsBetweenDealerBB

func IsBetweenDealerBB(seatIdx, currDealerTableSeatIdx, currBBTableSeatIdx, maxPlayerCount int, rule string) bool

func NewDefaultSeatMap

func NewDefaultSeatMap(seatCount int) []int

func NewGame

func NewGame(backend GameBackend, opts *pokerface.GameOptions) *game

func RandomSeats

func RandomSeats(seatMap []int, count int) ([]int, error)

Types

type Game

type Game interface {
	// Events
	OnGameStateUpdated(func(*pokerface.GameState))
	OnGameErrorUpdated(func(*pokerface.GameState, error))

	// Others
	GetGameState() *pokerface.GameState
	Start() (*pokerface.GameState, error)
	Next() (*pokerface.GameState, error)

	// Group Actions
	ReadyForAll() (*pokerface.GameState, error)
	PayAnte() (*pokerface.GameState, error)
	PayBlinds() (*pokerface.GameState, error)

	// Single Actions
	Ready(playerIdx int) (*pokerface.GameState, error)
	Pay(playerIdx int, chips int64) (*pokerface.GameState, error)
	Pass(playerIdx int) (*pokerface.GameState, error)
	Fold(playerIdx int) (*pokerface.GameState, error)
	Check(playerIdx int) (*pokerface.GameState, error)
	Call(playerIdx int) (*pokerface.GameState, error)
	Allin(playerIdx int) (*pokerface.GameState, error)
	Bet(playerIdx int, chips int64) (*pokerface.GameState, error)
	Raise(playerIdx int, chipLevel int64) (*pokerface.GameState, error)
}

type JoinPlayer

type JoinPlayer struct {
	PlayerID    string `json:"player_id"`
	RedeemChips int64  `json:"redeem_chips"`
	Seat        int    `json:"seat"`
}

type Manager

type Manager interface {
	Reset()

	// Table Actions
	GetTableEngine(tableID string) (TableEngine, error)
	CreateTable(options *TableEngineOptions, callbacks *TableEngineCallbacks, setting TableSetting) (*Table, error)
	PauseTable(tableID string) error
	CloseTable(tableID string) error
	StartTableGame(tableID string) error
	TableGameOpen(tableID string) error
	UpdateBlind(tableID string, level int, ante, dealer, sb, bb int64) error

	// Player Table Actions
	PlayerReserve(tableID string, joinPlayer JoinPlayer) error
	PlayerJoin(tableID, playerID string) error
	PlayerRedeemChips(tableID string, joinPlayer JoinPlayer) error
	PlayersLeave(tableID string, playerIDs []string) error

	// Player Game Actions
	PlayerReady(tableID, playerID string) error
	PlayerPay(tableID, playerID string, chips int64) error
	PlayerBet(tableID, playerID string, chips int64) error
	PlayerRaise(tableID, playerID string, chipLevel int64) error
	PlayerCall(tableID, playerID string) error
	PlayerAllin(tableID, playerID string) error
	PlayerCheck(tableID, playerID string) error
	PlayerFold(tableID, playerID string) error
	PlayerPass(tableID, playerID string) error
}

func NewManager

func NewManager() Manager

type NativeGameBackend

type NativeGameBackend struct {
	// contains filtered or unexported fields
}

func NewNativeGameBackend

func NewNativeGameBackend() *NativeGameBackend

func (*NativeGameBackend) Allin

func (*NativeGameBackend) Bet

func (*NativeGameBackend) Call

func (*NativeGameBackend) Check

func (*NativeGameBackend) CreateGame

func (ngb *NativeGameBackend) CreateGame(opts *pokerface.GameOptions) (*pokerface.GameState, error)

func (*NativeGameBackend) Fold

func (*NativeGameBackend) Next

func (*NativeGameBackend) Pass

func (*NativeGameBackend) Pay

func (*NativeGameBackend) PayAnte

func (*NativeGameBackend) PayBlinds

func (*NativeGameBackend) Raise

func (ngb *NativeGameBackend) Raise(gs *pokerface.GameState, chipLevel int64) (*pokerface.GameState, error)

func (*NativeGameBackend) ReadyForAll

func (ngb *NativeGameBackend) ReadyForAll(gs *pokerface.GameState) (*pokerface.GameState, error)

type Table

type Table struct {
	UpdateSerial int64       `json:"update_serial"`
	ID           string      `json:"id"`
	Meta         TableMeta   `json:"meta"`
	State        *TableState `json:"state"`
	UpdateAt     int64       `json:"update_at"`
}

func (Table) AlivePlayers

func (t Table) AlivePlayers() []*TablePlayerState

func (Table) Clone

func (t Table) Clone() (*Table, error)

func (Table) FindGamePlayerIdx

func (t Table) FindGamePlayerIdx(playerID string) int

func (Table) FindPlayerIdx

func (t Table) FindPlayerIdx(playerID string) int

func (Table) GamePlayerIndex

func (t Table) GamePlayerIndex(playerID string) int

func (Table) GetGameStateJSON

func (t Table) GetGameStateJSON() (string, error)

func (Table) GetJSON

func (t Table) GetJSON() (string, error)

func (Table) ParticipatedPlayers

func (t Table) ParticipatedPlayers() []*TablePlayerState

func (Table) PlayerSeatMap

func (t Table) PlayerSeatMap() map[string]int

func (Table) ShouldPause

func (t Table) ShouldPause() bool

type TableBlindState

type TableBlindState struct {
	Level  int   `json:"level"`
	Ante   int64 `json:"ante"`
	Dealer int64 `json:"dealer"`
	SB     int64 `json:"sb"`
	BB     int64 `json:"bb"`
}

func (TableBlindState) IsBreaking

func (bs TableBlindState) IsBreaking() bool

func (TableBlindState) IsSet

func (bs TableBlindState) IsSet() bool

type TableEngine

type TableEngine interface {
	OnTableUpdated(fn func(table *Table))
	OnTableErrorUpdated(fn func(table *Table, err error))
	OnTableStateUpdated(fn func(string, *Table))
	OnTablePlayerStateUpdated(fn func(string, string, *TablePlayerState))
	OnTablePlayerReserved(fn func(competitionID, tableID string, playerState *TablePlayerState))
	OnGamePlayerActionUpdated(fn func(TablePlayerGameAction))

	GetTable() *Table
	GetGame() Game
	CreateTable(tableSetting TableSetting) (*Table, error)
	PauseTable() error
	CloseTable() error
	StartTableGame() error
	TableGameOpen() error
	UpdateBlind(level int, ante, dealer, sb, bb int64)

	PlayerReserve(joinPlayer JoinPlayer) error
	PlayerJoin(playerID string) error
	PlayerRedeemChips(joinPlayer JoinPlayer) error
	PlayersLeave(playerIDs []string) error

	PlayerReady(playerID string) error
	PlayerPay(playerID string, chips int64) error
	PlayerBet(playerID string, chips int64) error
	PlayerRaise(playerID string, chipLevel int64) error
	PlayerCall(playerID string) error
	PlayerAllin(playerID string) error
	PlayerCheck(playerID string) error
	PlayerFold(playerID string) error
	PlayerPass(playerID string) error
}

func NewTableEngine

func NewTableEngine(options *TableEngineOptions, opts ...TableEngineOpt) TableEngine

type TableEngineCallbacks

type TableEngineCallbacks struct {
	OnTableUpdated            func(t *Table)
	OnTableErrorUpdated       func(t *Table, err error)
	OnTableStateUpdated       func(string, *Table)
	OnTablePlayerStateUpdated func(string, string, *TablePlayerState)
	OnTablePlayerReserved     func(string, string, *TablePlayerState)
	OnGamePlayerActionUpdated func(TablePlayerGameAction)
}

func NewTableEngineCallbacks

func NewTableEngineCallbacks() *TableEngineCallbacks

type TableEngineOpt

type TableEngineOpt func(*tableEngine)

func WithGameBackend

func WithGameBackend(gb GameBackend) TableEngineOpt

type TableEngineOptions

type TableEngineOptions struct {
	Interval int
}

func NewTableEngineOptions

func NewTableEngineOptions() *TableEngineOptions

type TableMeta

type TableMeta struct {
	CompetitionID       string `json:"competition_id"`
	Rule                string `json:"rule"`
	Mode                string `json:"mode"`
	MaxDuration         int    `json:"max_duration"`
	TableMaxSeatCount   int    `json:"table_max_seat_count"`
	TableMinPlayerCount int    `json:"table_min_player_count"`
	MinChipUnit         int64  `json:"min_chip_unit"`
	ActionTime          int    `json:"action_time"`
}

type TablePlayerGameAction

type TablePlayerGameAction struct {
	CompetitionID    string   `json:"competition_id"`
	TableID          string   `json:"table_id"`
	GameID           string   `json:"game_id"`
	GameCount        int      `json:"game_count"`
	Round            string   `json:"round"`
	UpdateAt         int64    `json:"update_at"`
	PlayerID         string   `json:"player_id"`
	Seat             int      `json:"seat"`
	Positions        []string `json:"positions"`
	Action           string   `json:"action"`
	Chips            int64    `json:"chips"`
	Bankroll         int64    `json:"bankroll"`
	InitialStackSize int64    `json:"initial_stack_size"`
	StackSize        int64    `json:"stack_size"`
	Pot              int64    `json:"pot"`
	Wager            int64    `json:"wager"`
}

type TablePlayerGameStatistics

type TablePlayerGameStatistics struct {
	ActionTimes int    `json:"action_times"`
	RaiseTimes  int    `json:"raise_times"`
	CallTimes   int    `json:"call_times"`
	CheckTimes  int    `json:"check_times"`
	IsFold      bool   `json:"is_fold"`
	FoldRound   string `json:"fold_round"`
}

type TablePlayerState

type TablePlayerState struct {
	PlayerID          string                    `json:"player_id"`
	Seat              int                       `json:"seat"`
	Positions         []string                  `json:"positions"`
	IsParticipated    bool                      `json:"is_participated"`
	IsBetweenDealerBB bool                      `json:"is_between_dealer_bb"`
	Bankroll          int64                     `json:"bankroll"`
	IsIn              bool                      `json:"is_in"`
	GameStatistics    TablePlayerGameStatistics `json:"game_statistics"`
}

type TableSetting

type TableSetting struct {
	TableID     string       `json:"table_id"`
	Meta        TableMeta    `json:"table_meta"`
	JoinPlayers []JoinPlayer `json:"join_players"`
}

type TableState

type TableState struct {
	Status            TableStateStatus     `json:"status"`
	StartAt           int64                `json:"start_at"`
	SeatMap           []int                `json:"seat_map"`
	BlindState        *TableBlindState     `json:"blind_state"`
	CurrentDealerSeat int                  `json:"current_dealer_seat"`
	CurrentBBSeat     int                  `json:"current_bb_seat"`
	PlayerStates      []*TablePlayerState  `json:"player_states"`
	GameCount         int                  `json:"game_count"`
	GamePlayerIndexes []int                `json:"game_player_indexes"`
	GameState         *pokerface.GameState `json:"game_state"`
}

type TableStateStatus

type TableStateStatus string
const (
	TableStateStatus_TableCreated   TableStateStatus = "table_created"
	TableStateStatus_TablePausing   TableStateStatus = "table_pausing"
	TableStateStatus_TableRestoring TableStateStatus = "table_restoring"
	TableStateStatus_TableBalancing TableStateStatus = "table_balancing"
	TableStateStatus_TableClosed    TableStateStatus = "table_closed"

	TableStateStatus_TableGameOpened  TableStateStatus = "table_game_opened"
	TableStateStatus_TableGamePlaying TableStateStatus = "table_game_playing"
	TableStateStatus_TableGameSettled TableStateStatus = "table_game_settled"
	TableStateStatus_TableGameStandby TableStateStatus = "table_game_standby"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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