@idealic/poker-engine
Version:
Professional poker game engine and hand evaluator with built-in iterator utilities
117 lines • 4.67 kB
TypeScript
import type { Action, ActionType, Player, Street, Game } from '../types';
/**
* Extracts specific player index from action (1-based)
* @param action - The action string containing a player index
* @returns Player index or undefined if no player index is present
*/
export declare function getActionPlayerIndex(action: Action): number | undefined;
/**
* Extracts phh action type from action
* @param action - The action string containing an action type
* @returns Action type or '?' if no action type is present
*/
export declare function getActionType(action?: Action): ActionType;
/**
* Extracts comment from action
* @param action - The action string containing a comment
* @returns Comment or undefined if no comment is present
*/
export declare function getActionComment(action: Action): string | undefined;
/**
* Extracts timestamp from action and its comment
* @param action - The action string containing a comment
* @returns Timestamp or undefined if no timestamp is present
*/
export declare function getActionTimestamp(action: Action, useDefault?: boolean): number | null;
/**
* Adds or replaces timestamp in an action
* @param action - The action string to timestamp
* @param timestamp - Optional timestamp (defaults to Date.now())
* @returns Action with timestamp appended as comment
*/
export declare function timestampAction(action: Action, timestamp?: number): Action;
/**
* Extracts cards from dealer actions
* @param action - The action string containing dealer actions
* @returns Array of cards or undefined if no cards are present
*/
export declare function getActionCards(action: Action): string[] | undefined;
/**
* Extracts amount from action
* @param action - The action string containing an amount
* @returns Amount or 0 if no amount is present
*/
export declare function getActionAmount(action: Action): number;
/**
* Finds next eligible player to act starting from given index.
* This function ONLY checks player flags and does not deal with betting logic.
* Returns -1 if no eligible player found.
*
* @instructions
* This function ONLY checks player eligibility based on:
* 1. Not folded (hasFolded flag)
* 2. Not all-in (isAllIn flag)
* 3. Circular search (wraps around table)
* 4. Stops if full circle made (no eligible found)
*
* It does NOT:
* - Check betting amounts
* - Handle betting logic
* - Reset any flags
* - Deal with positions
* - Consider street or game state
*
* The function relies on:
* - Player flags being accurate (hasFolded, isAllIn)
* - Valid startIndex within table size
* - isPlayerEligibleToAct helper for flag checks
*/
export declare function getNextEligiblePlayerIndex(game: Game, startIndex: number): number;
export declare function getCurrentEligiblePlayerIndex(game: Game, playerIndex: number): number;
/**
* @instructions
* Returns the theoretical first player to act for a given street based ONLY on positions.
* This function ignores current betting state, folded status, or all-in status.
* For preflop:
* - In heads-up: BTN/SB acts first
* - In ring game: UTG (next after BB) acts first
* For postflop streets: first position after button.
*/
export declare function findFirstToActForStreet(game: Game, street: Street): number;
/**
* Gets the index of the next player who should act
* Returns -1 if no player can act or if a dealer action should happen next
*
* @instructions
* This function ONLY determines next player to act based on:
* 1. Betting complete (no one can act)
* 2. Dealer intervention needed (no one can act)
* 3. Single player or all all-in (no one can act)
* 4. New street start (first active player after button)
* 5. After last action (next after last acted)
*
* It does NOT:
* - Reset player flags
* - Handle betting logic
* - Compare bet amounts
* - Deal with side pots
*
* The function relies on:
* - hasActed flag being properly managed by action handlers
* - bettingComplete flag being set correctly
* - Player states (hasFolded, isAllIn) being accurate
* - Last action being tracked correctly
*/
export declare function getPlayerIndex(game: Game): number;
export declare function getRemainingPlayers(game: Game): Player[];
export declare function getActivePlayers(game: Game): Player[];
/**
* Returns the index of the player with the given name
*/
export declare function getPlayerIndexFromName(game: Game, name: string): number;
/**
* Determines the button position based on blinds structure.
* In heads-up, button is SB. Otherwise, button is one position before SB.
*/
export declare function getButtonIndex(players: number, blinds: number[]): number;
//# sourceMappingURL=position.d.ts.map