@idealic/poker-engine
Version:
Professional poker game engine and hand evaluator with built-in iterator utilities
181 lines • 6.38 kB
TypeScript
import type { Game, Action } from './types';
/**
* Union type of all available command names
*/
export type CommandName = 'fold' | 'call' | 'check' | 'bet' | 'raise' | 'allIn' | 'dealBoard' | 'dealHoleCards' | 'dealStreet' | 'showCards';
/**
* Interface for command request objects used with the Command constructor
*/
export interface CommandRequest {
/** Type of command to execute */
type: CommandName;
/** Game state to operate on */
game: Game;
/** Index of the player (0-based) */
playerIndex: number;
/** Amount for bet/raise commands */
amount?: number;
/** Cards for deal commands */
cards?: string[];
/** Allow extension with additional properties */
[key: string]: any;
}
/**
* Command constructor/factory function that creates actions from a request object.
* Acts as a unified interface for creating poker actions with validation.
*
* @param props - Command request properties
* @returns Action string that can be applied to the game
*
* @example
* const action = Command({
* type: 'bet',
* game: gameState,
* playerIndex: 1,
* amount: 100
* });
*
* @example
* const action = Command({
* type: 'fold',
* game: gameState,
* playerIndex: 0
* });
*/
export declare function Command(props: Partial<CommandRequest> & {
type: CommandName;
game: Game;
}): Action;
/**
* Returns a fold action string without applying it
*/
declare function fold(_: Game, playerIndex: number): Action;
/**
* Returns a check action string without applying it
*/
declare function check(game: Game, playerIndex: number): Action;
/**
* Returns a call action string without applying it.
* Available stack includes current bet since it will be returned when calling.
*/
declare function call(game: Game, playerIndex: number): Action;
/**
* Returns a bet action string without applying it.
* Available stack includes current bet since it will be returned when betting.
*/
declare function bet(game: Game, playerIndex: number, amount: number): Action;
/**
* Returns a raise action string without applying it.
* Available stack includes current bet since it will be returned when raising.
*/
declare function raise(game: Game, playerIndex: number, amount: number): Action;
/**
* Player bets their entire remaining stack.
* This action automatically determines whether it's a bet or raise based on the current game state.
*
* @param game - The current game state
* @param playerIndex - Index of the player (0-based)
* @returns Action string for going all-in
*/
declare function allIn(game: Game, playerIndex: number): Action;
/**
* Returns a deal board action string without applying it
*/
declare function dealBoard(_table: Game, cards: string[]): Action;
/**
* Returns a deal hole cards action string without applying it
*/
declare function dealHoleCards(_table: Game, playerIndex: number, cards: string[]): Action;
/**
* Advances the game to the next betting round by dealing appropriate cards.
*
* @param game - The current game state
* @returns Action string for dealing street cards
*/
declare function dealStreet(game: Game): Action;
/**
* Shows cards for showdown or mucking.
*
* @param game - The current game state
* @returns Action string for showing cards
*/
declare function showCards(game: Game): Action;
/**
* Command namespace containing all command functions.
* These functions generate action strings that can be applied to the game using Game.applyAction().
*/
export declare namespace Command {
/**
* Player folds their hand and forfeits the current round
* @param game - Current game state
* @param playerIndex - Index of the player (0-based)
* @returns Action string for folding
*/
const fold: (game: Game, playerIndex: number) => Action;
/**
* Player matches the current bet amount
* @param game - Current game state
* @param playerIndex - Index of the player (0-based)
* @returns Action string for calling
*/
const call: (game: Game, playerIndex: number) => Action;
/**
* Player passes when no bet is required
* @param game - Current game state
* @param playerIndex - Index of the player (0-based)
* @returns Action string for checking
*/
const check: (game: Game, playerIndex: number) => Action;
/**
* Player makes an initial bet
* @param game - Current game state
* @param playerIndex - Index of the player (0-based)
* @param amount - Total bet amount
* @returns Action string for betting
*/
const bet: (game: Game, playerIndex: number, amount: number) => Action;
/**
* Player increases the current bet
* @param game - Current game state
* @param playerIndex - Index of the player (0-based)
* @param amount - Total raise amount
* @returns Action string for raising
*/
const raise: (game: Game, playerIndex: number, amount: number) => Action;
/**
* Player bets their entire remaining stack
* @param game - Current game state
* @param playerIndex - Index of the player (0-based)
* @returns Action string for going all-in
*/
const allIn: (game: Game, playerIndex: number) => Action;
/**
* Deals community cards to the board
* @param game - Current game state
* @param cards - Array of card strings to deal
* @returns Action string for dealing board cards
*/
const dealBoard: (game: Game, cards: string[]) => Action;
/**
* Deals hole cards to a specific player
* @param game - Current game state
* @param playerIndex - Index of the player (0-based)
* @param cards - Array of card strings to deal
* @returns Action string for dealing hole cards
*/
const dealHoleCards: (game: Game, playerIndex: number, cards: string[]) => Action;
/**
* Advances the game to the next betting round
* @param game - Current game state
* @returns Action string for dealing street cards
*/
const dealStreet: (game: Game) => Action;
/**
* Shows cards for showdown or mucking
* @param game - Current game state
* @returns Action string for showing cards
*/
const showCards: (game: Game) => Action;
}
export { fold, check, call, bet, raise, dealBoard, dealHoleCards, dealStreet, showCards, allIn };
//# sourceMappingURL=Command.d.ts.map