@idealic/poker-engine
Version:
Professional poker game engine and hand evaluator with built-in iterator utilities
189 lines • 6.99 kB
TypeScript
import type { Variant, Player, Card, Street, Action, CommandName } from './types';
import type { PlayerStreetStats } from './stats/types';
import { applyAction as originalApplyAction } from './actions/processor';
import { isShowdown, needsBlinds, createCensoredTable } from './game/table';
import { can } from './game/validation';
import { Hand } from './Hand';
/**
* Represents the current state of the table
*/
export interface Game {
/** Name of the venue where the hand was played */
venue?: string;
/** Unique identifier for the game */
tableId: string;
/** Hand identifier */
hand: number;
/** Game identifier */
gameId: string;
/** Timestamp of the game start */
gameTimestamp: number;
/** Game variant being played (e.g. NT for No-Limit Texas Hold'em) */
variant: Variant;
/** Array of players at the table with their current state */
players: Player[];
/** Community cards on the board */
board: Card[];
/** Total amount of chips in the pot */
pot: number;
/** Current betting round (preflop, flop, turn, river) */
street: Street;
/** Current bet amount that players need to call */
bet: number;
/** Mininmum bet amount possible, typically big blind */
minBet: number;
/** Random seed for deterministic card dealing */
seed?: number;
/** Number of cards that have been dealt in the hand */
usedCards: number;
/** Shuffled deck of cards for deterministic dealing */
deck?: string[];
/** Index of the dealer button position (0-based) */
buttonIndex: number;
/** Index of the small blind position (0-based) */
smallBlindIndex: number;
/** Index of the big blind position (0-based) */
bigBlindIndex: number;
/** Last action taken in the current street */
lastAction?: Action;
/** Last bet/raise action in the current street */
lastBetAction?: Action;
/** Whether the current betting round is complete (all active players have acted and matched bets) */
isBettingComplete?: boolean;
/** Whether the hand is complete (showdown or all but one player folded) */
isHandComplete?: boolean;
/** Last player action in the current street, undefined if no player has acted yet */
lastPlayerAction?: Action;
/** Amount taken by the house from the pot */
rake?: number;
/** Rake percentage used to calculate rake when absolute amount is not provided (0.05 = 5%) */
rakePercentage?: number;
/** Final pot size excluded rake */
finalPot?: number;
/** Game statistics tracker */
stats: PlayerStreetStats[];
/** Index of the next player to act */
nextPlayerIndex: number;
/** Whether the hand is a showdown hand */
isShowdown: boolean;
/** Timestamp of the last action */
lastTimestamp?: number;
}
/**
* Game constructor/guard function that creates a validated Game object.
* Acts as a factory function with sensible defaults and validation.
*
* @param hand - Hand object to create game from
* @param actions - Optional actions array (defaults to hand.actions)
* @returns A validated Game object
*
* @example
* // Create from Hand object (new behavior)
* const game = Game(hand);
* const game = Game(hand, customActions);
*
* // Create from Game properties (legacy behavior)
* const game = Game({
* tableId: 'table-1',
* variant: 'NT',
* players: [
* { name: 'Alice', stack: 1000, position: 0 },
* { name: 'Bob', stack: 1000, position: 1 }
* ],
* minBet: 20
* });
*/
export declare function Game(hand: Hand, actions?: Action[]): Game;
export declare function Game(props: Partial<Game> & {
players: Array<Partial<Player> & {
name: string;
stack: number;
}>;
}): Game;
/**
* Game namespace for methods that operate on Game objects.
*/
export declare namespace Game {
/**
* Apply an action to the game state
* @param game - Current game state
* @param action - Action to apply
* @returns Updated game state
*/
const applyAction: typeof originalApplyAction;
/**
* Advance the game by executing pending dealer actions
* @param game - Current game state
* @returns Updated game state
*/
function advanceGame(game: Game): Game;
/**
* Get time remaining for current player to act
* @param game - Current game state
* @returns Time remaining in seconds (or elapsed time in ms for legacy)
*/
function getTimeLeftFunc(game: Game): number;
/**
* Get the index of the author player
* @param game - Game state or hand
* @returns Author player index or -1 if not found
*/
function getAuthorPlayerIndexFunc(game: Game | Hand): number;
/**
* Check if the game is in showdown
* @param game - Current game state
* @returns True if in showdown
*/
const isShowdownFunc: typeof isShowdown;
/**
* Check if the game needs blinds
* @param game - Current game state
* @returns True if blinds are needed
*/
const needsBlindsFunc: typeof needsBlinds;
/**
* Create a censored table for player perspective
* @param hand - Hand to create censored table from
* @param playerId - Player ID for perspective
* @returns Game state with censored information
*/
const createCensoredTableFunc: typeof createCensoredTable;
/**
* Export a game state with an optional player perspective
* @param game - The game state to export
* @param playerId - Optional player ID to add as author and apply card censoring
* @returns The game state as a Hand type with optional author and censored cards
*/
function output(game: any, playerId?: string): Hand;
/**
* Check if a player can perform an action
* @param game - Current game state
* @returns Validation result
*/
const canFunc: typeof can;
/**
* Execute a command on the game
* @param game - Current game state
* @param command - Command to execute
* @param args - Command arguments
* @returns Action string
*/
function actFunc(game: Game, command: CommandName, ...args: any[]): Action;
/**
* Command object mapping command names to action functions
*/
const Command: {
fold: (game: Game, playerIndex: number) => Action;
call: (game: Game, playerIndex: number) => Action;
check: (game: Game, playerIndex: number) => Action;
bet: (game: Game, playerIndex: number, amount: number) => Action;
raise: (game: Game, playerIndex: number, amount: number) => Action;
allIn: (game: Game, playerIndex: number) => Action;
dealBoard: (game: Game, cards: string[]) => Action;
dealHoleCards: (game: Game, playerIndex: number, cards: string[]) => Action;
dealStreet: (game: Game) => Action;
showCards: (game: Game) => Action;
};
}
import './game/analytics';
//# sourceMappingURL=Game.d.ts.map