### Simulate Full Hand Lifecycle in Poker TS Source: https://context7.com/claudijo/poker-ts/llms.txt This example demonstrates setting up a table, seating players, and running through a complete hand, including betting rounds and showdown. It uses a simple strategy to always call or check. Ensure the 'poker-ts' library is installed. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }, 9); // Seat three players table.sitDown(0, 1000); table.sitDown(2, 1500); table.sitDown(5, 1700); table.startHand(); // Game loop while (table.isHandInProgress()) { while (table.isBettingRoundInProgress()) { const seat = table.playerToAct(); const { actions, chipRange } = table.legalActions(); // Simple strategy: always call or check if (actions.includes('check')) { table.actionTaken('check'); } else if (actions.includes('call')) { table.actionTaken('call'); } else { table.actionTaken('fold'); } } if (table.areBettingRoundsCompleted()) { // Check if only one eligible player remains (no need for showdown eval) const pots = table.pots(); const singleWinner = pots.length === 1 && pots[0].eligiblePlayers.length === 1; table.showdown(); if (singleWinner) { console.log('Winner by default:', pots[0].eligiblePlayers[0]); } else { table.winners().forEach((potWinners, i) => { potWinners.forEach(([seat, hand, holeCards]) => { console.log(`Pot ${i} — Seat ${seat} wins with ranking ${hand.ranking}`); console.log(` Board+Hole: ${hand.cards.map(c => `${c.rank}${c.suit[0]}`).join(' ')}`); }); }); } break; } else { table.endBettingRound(); } } // Start next hand — button advances automatically table.startHand(); console.log('New hand, button at seat:', table.button()); ``` -------------------------------- ### Start New Hand Source: https://context7.com/claudijo/poker-ts/llms.txt Initiates a new hand, dealing hole cards and posting blinds/antes. Requires at least two seated players. Optionally set the dealer button position. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1500); table.sitDown(5, 2000); table.startHand(); // button advances automatically // table.startHand(5); // force button to seat 5 console.log(table.isHandInProgress()); // true console.log(table.isBettingRoundInProgress()); // true console.log(table.roundOfBetting()); // 'preflop' console.log(table.button()); // seat index of dealer button ``` -------------------------------- ### legalActions Source: https://github.com/claudijo/poker-ts/blob/main/README.md Gets the list of legal actions a player can take during the current betting round. Requires the betting round to be in progress. ```APIDOC ## legalActions() ### Description Returns the legal actions available for the player whose turn it is to act. This is applicable when a betting round is in progress. ### Method GET ### Endpoint `Poker.Table.prototype.legalActions()` ### Returns - **object**: An object containing: - **actions** (Action[]): An array of legal actions. - **chipRange** (ChipRange, optional): The range of possible chip amounts for betting or raising. ``` -------------------------------- ### Get Player to Act Source: https://context7.com/claudijo/poker-ts/llms.txt Identifies the seat index of the player whose turn it is to act. This is only relevant when a betting round is active. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1500); table.sitDown(2, 2000); table.startHand(); const seat = table.playerToAct(); // e.g. 0 console.log(`Player at seat ${seat} must act`); ``` -------------------------------- ### handPlayers() — Players in the current hand Source: https://context7.com/claudijo/poker-ts/llms.txt Returns player state for only those who are participating in the active hand (seated at hand start). This differs from `seats()` as players who joined mid-hand are excluded. ```APIDOC ## handPlayers() ### Description Returns player state for only those who are participating in the active hand (seated at hand start). Differs from `seats()` in that players who joined mid-hand are excluded. ### Method ```ts table.handPlayers(); ``` ### Response Example ```json { "example": "[ playerState, ... ]" } ``` ``` -------------------------------- ### Get Player Hole Cards with poker-ts Source: https://context7.com/claudijo/poker-ts/llms.txt Retrieves the hole cards for each player. Returns null for empty seats or folded players. Cards are available during or after a hand. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); const holeCards = table.holeCards(); // holeCards[0] => [{ rank: 'A', suit: 'spades' }, { rank: 'K', suit: 'hearts' }] // holeCards[3] => null (empty seat) for (let seat = 0; seat < holeCards.length; seat++) { if (holeCards[seat]) { const [c1, c2] = holeCards[seat]; console.log(`Seat ${seat}: ${c1.rank}${c1.suit[0]} ${c2.rank}${c2.suit[0]}`); } } ``` -------------------------------- ### Get players in current hand with `handPlayers()` Source: https://context7.com/claudijo/poker-ts/llms.txt Retrieve player state only for those actively participating in the current hand, excluding players who joined mid-hand. This differs from `seats()` which includes all seated players. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); // Player joins after hand started table.sitDown(3, 1000); const handPlayers = table.handPlayers(); console.log(handPlayers[3]); // null — seat 3 joined mid-hand, not in this hand const allSeats = table.seats(); console.log(allSeats[3]); // { totalChips: 1000, stack: 1000, betSize: 0 } ``` -------------------------------- ### Get Community Cards with poker-ts Source: https://context7.com/claudijo/poker-ts/llms.txt Retrieves the community cards dealt on the board. The array is empty before the first call to endBettingRound(), containing 3 cards for the flop, 4 for the turn, and 5 for the river. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.startHand(); // Complete preflop betting table.actionTaken('call'); table.actionTaken('check'); table.endBettingRound(); const flop = table.communityCards(); console.log(flop.length); // 3 console.log(flop[0]); // { rank: 'T', suit: 'diamonds' } ``` -------------------------------- ### Initialize and Play a Poker Hand Source: https://github.com/claudijo/poker-ts/blob/main/README.md Demonstrates setting up a poker table, seating players, and managing the game flow through betting rounds and showdown. Requires manual player action input. ```javascript const Poker = require('poker-ts'); table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }) table.sitDown(0, 1000); // seat a player at seat 0 with 1000 chips buy-in table.sitDown(2, 1500); // seat a player at seat 2 with 1500 chips buy-in table.sitDown(5, 1700); // seat a player at seat 5 with 1700 chips buy-in table.startHand(); while (table.isHandInProgress()) { while (table.isBettingRoundInProgress()) { const seatIndex = table.playerToAct(); // Get `action` and possibly `betSize` in some way const [action, betSize] = getPlayerActionSomehow(seatIndex); table.actionTaken(action, betSize); } table.endBettingRound() if (table.areBettingRoundsCompleted()) { table.showdown() } } // 🎉 🎉 🎉 Congrats to the `table.winners()` 🎉 🎉 🎉 ``` -------------------------------- ### startHand(seat?) Source: https://github.com/claudijo/poker-ts/blob/main/README.md Initiates a new hand. This involves collecting antes, placing blinds, and dealing cards. The hand must not be in progress, and at least two players must be seated. An optional seat index can be provided to set the dealer button; otherwise, it defaults to the first active player. ```APIDOC ## startHand(seat?) ### Description Start a new hand by collecting ante, placing blinds and dealing cards. (Hand must not be in progress and there must be at least two players seated at the table.) Optionally set dealer button seat. If seat is invalid, button will be placed at the first hand player. ### Method `Poker.Table.prototype.startHand(seat?: number)): void` ``` -------------------------------- ### Create Poker Table Instance Source: https://context7.com/claudijo/poker-ts/llms.txt Instantiate a new Poker.Table with specified blind and ante values. Supports up to 23 seats; defaults to 9. Chip amounts are integer-based (e.g., cents). ```typescript const Poker = require('poker-ts'); // 9-seat table with 50/100 blinds, no ante const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); // 6-seat table with ante const table6 = new Poker.Table({ smallBlind: 50, bigBlind: 100, ante: 25 }, 6); console.log(table.numSeats()); // 9 console.log(table6.numSeats()); // 6 ``` -------------------------------- ### actionTaken(action, betSize?) Source: https://context7.com/claudijo/poker-ts/llms.txt Records the current player's action. Valid actions are 'fold', 'check', 'call', 'bet', and 'raise'. betSize (integer, in chips) is required for 'bet' and 'raise' and must fall within the chipRange returned by legalActions(). ```APIDOC ## actionTaken(action, betSize?) ### Description Records the current player's action. Valid actions are 'fold', 'check', 'call', 'bet', and 'raise'. `betSize` (integer, in chips) is required for 'bet' and 'raise' and must fall within the `chipRange` returned by `legalActions()`. ### Parameters - **action** (string) - Required - One of 'fold', 'check', 'call', 'bet', 'raise'. - **betSize** (integer) - Optional - Required for 'bet' and 'raise' actions. Must be within the legal chip range. ### Request Example ```javascript // Example usage within a poker-ts game context // Assuming 'table' is an instance of Poker.Table table.actionTaken('call'); // player 0 calls table.actionTaken('fold'); // player 1 folds table.actionTaken('raise', 400); // player 2 raises to 400 table.actionTaken('call'); // player 0 calls the raise ``` ### Response This method does not return a value, but modifies the game state. ``` -------------------------------- ### new Poker.Table(forcedBets, numSeats?) Source: https://context7.com/claudijo/poker-ts/llms.txt Creates a new poker table instance with a specified blind/ante structure and optional seat count. The default number of seats is 9, with a maximum of 23. ```APIDOC ## new Poker.Table(forcedBets, numSeats?) ### Description Creates a new poker table instance with a specified blind/ante structure and optional seat count (default: 9, max: 23). `bigBlind` and `smallBlind` are required; `ante` is optional. ### Method Constructor ### Parameters #### Path Parameters - **forcedBets** (object) - Required - An object containing `smallBlind`, `bigBlind`, and optional `ante`. - **numSeats** (number) - Optional - The number of seats at the table (default: 9, max: 23). ### Request Example ```javascript const Poker = require('poker-ts'); // 9-seat table with 50/100 blinds, no ante const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); // 6-seat table with ante const table6 = new Poker.Table({ smallBlind: 50, bigBlind: 100, ante: 25 }, 6); console.log(table.numSeats()); // 9 console.log(table6.numSeats()); // 6 ``` ``` -------------------------------- ### Poker.Table Constructor Source: https://github.com/claudijo/poker-ts/blob/main/README.md Creates a new instance of the poker table. You can optionally specify forced bets like ante, big blind, and small blind, as well as the total number of seats at the table. ```APIDOC ## Poker.Table Constructor ### Description Creates an instance of the poker table object. The ante (a forced bet in which all players put an equal amount of money or chips into the pot before the deal begins) and specifying the dealer button seat are optional. ### Parameters #### Path Parameters - **forcedBets** (object) - Required - An object containing the forced bet amounts. It can include `ante` (number), `bigBlind` (number), and `smallBlind` (number). - **numSeats** (number) - Optional - The total number of seats at the table. ``` -------------------------------- ### pots() Source: https://context7.com/claudijo/poker-ts/llms.txt Inspects the current pot state, returning an array of pot objects, each detailing its size and the players eligible to win it. ```APIDOC ## pots() ### Description Returns an array of pot objects. Each object contains the `size` of the pot (in chips) and an array of `eligiblePlayers` (seat indices) who can win that pot. Side pots are automatically created when players go all-in. ### Parameters None ### Response - **Array** - An array of pot objects. - **Pot object** `{ size: number, eligiblePlayers: number[] }` ### Response Example ```javascript // Assuming 'table' is an instance of Poker.Table and pots have been formed const pots = table.pots(); pots.forEach((pot, i) => { console.log(`Pot ${i}: ${pot.size} chips, players: [${pot.eligiblePlayers}]`); }); // Example output for a scenario with a main pot and a side pot: // Pot 0: 600 chips, players: [0, 1, 2] // Pot 1: 1400 chips, players: [1, 2] ``` ``` -------------------------------- ### actionTaken Source: https://github.com/claudijo/poker-ts/blob/main/README.md Records a player's action during the current betting round. Requires the betting round to be in progress. ```APIDOC ## actionTaken(action, betSize) ### Description Indicates that the player currently to act has performed a specific action. This method should be called when a betting round is in progress. ### Method POST ### Endpoint `Poker.Table.prototype.actionTaken(action: Action, betSize?: number)` ### Parameters #### Path Parameters - **action** (Action) - Required - The action taken by the player (e.g., 'fold', 'check', 'bet', 'raise'). - **betSize** (number, optional) - The amount of chips bet or raised, if applicable. ``` -------------------------------- ### legalActions() Source: https://context7.com/claudijo/poker-ts/llms.txt Queries the available actions for the current player and the valid chip range for betting or raising. ```APIDOC ## legalActions() ### Description Returns an object with `actions` (string array) and an optional `chipRange` (`{ min, max }`) for bet/raise sizing. Only valid while a betting round is in progress. ### Method `legalActions` ### Parameters None ### Response #### Success Response (200) - **actions** (string[]) - An array of legal actions (e.g., 'fold', 'call', 'raise'). - **chipRange** (object | undefined) - An object with `min` and `max` properties defining the valid bet/raise size, or undefined if no bet/raise is possible. ### Request Example ```javascript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); const { actions, chipRange } = table.legalActions(); console.log(actions); // ['fold', 'call', 'raise'] console.log(chipRange); // { min: 200, max: 1000 } // Check-only situation (big blind option, no raises): // actions: ['fold', 'check'] // chipRange: undefined ``` ``` -------------------------------- ### Evaluate hands and pay winners with `showdown()` Source: https://context7.com/claudijo/poker-ts/llms.txt Call `showdown()` after all betting rounds are complete to evaluate hands, distribute pots, and remove busted players. Use `winners()` to access the results. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); // ... play through all streets (call/check) ... // [assume all betting rounds completed] table.showdown(); const results = table.winners(); // results is an array per pot; each pot has an array of winners: // [ [ [seatIndex, handInfo, holeCards], ... ], ... ] results.forEach((potWinners, potIndex) => { potWinners.forEach(([seat, hand, holeCards]) => { console.log(`Pot ${potIndex} winner: seat ${seat}`); console.log(` Hand ranking: ${hand.ranking}`); // e.g. 5 = FLUSH console.log(` Best 5 cards: ${hand.cards.map(c => c.rank + c.suit[0]).join(' ')}`); console.log(` Hole cards: ${holeCards.map(c => c.rank + c.suit[0]).join(' ')}`); }); }); ``` -------------------------------- ### Manage pre-actions with `canSetAutomaticActions()`, `legalAutomaticActions()`, `setAutomaticAction()` Source: https://context7.com/claudijo/poker-ts/llms.txt Allow players to pre-select their next action. `canSetAutomaticActions` checks eligibility, `legalAutomaticActions` returns available actions, and `setAutomaticAction` sets or clears a pre-action. Pre-actions are automatically processed when the current player acts. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); // Complete preflop table.actionTaken('call'); table.actionTaken('call'); table.actionTaken('check'); table.endBettingRound(); // now on the flop // Player 2 pre-selects 'check' while player 0 is to act if (table.canSetAutomaticActions(2)) { const available = table.legalAutomaticActions(2); console.log(available); // ['fold', 'check/fold', 'check', 'call any', 'all-in'] table.setAutomaticAction(2, 'check'); } // When player 0 acts, player 2's automatic action fires automatically table.actionTaken('check'); // player 0 checks; engine auto-checks player 2 if applicable // Reset a pre-action table.setAutomaticAction(2, null); console.log(table.automaticActions()[2]); // null ``` -------------------------------- ### sitDown(seatIndex, buyIn) Source: https://context7.com/claudijo/poker-ts/llms.txt Seats a player at a specified seat index with a given chip buy-in. The seat must be available. ```APIDOC ## sitDown(seatIndex, buyIn) ### Description Seats a player at a given index (0-based) with a chip buy-in. The seat must be unoccupied. ### Method `sitDown` ### Parameters #### Path Parameters - **seatIndex** (number) - Required - The 0-based index of the seat to occupy. - **buyIn** (number) - Required - The number of chips the player buys in with. ### Request Example ```javascript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); // seat 0: 1000 chips table.sitDown(2, 1500); // seat 2: 1500 chips table.sitDown(5, 2000); // seat 5: 2000 chips // seats() returns full array with nulls for empty seats console.log(table.seats()); // [ // { totalChips: 1000, stack: 1000, betSize: 0 }, // null, // { totalChips: 1500, stack: 1500, betSize: 0 }, // null, null, // { totalChips: 2000, stack: 2000, betSize: 0 }, // null, null, null // ] ``` ``` -------------------------------- ### Query Legal Player Actions Source: https://context7.com/claudijo/poker-ts/llms.txt Retrieves the available actions for the current player and the valid chip range for betting or raising. Returns an object with 'actions' and 'chipRange'. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); const { actions, chipRange } = table.legalActions(); console.log(actions); // ['fold', 'call', 'raise'] console.log(chipRange); // { min: 200, max: 1000 } // Check-only situation (big blind option, no raises): // actions: ['fold', 'check'] // chipRange: undefined ``` -------------------------------- ### numSeats() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Returns the total number of seats available at the poker table. ```APIDOC ## numSeats() ### Description Returns the number of seats at the table. ### Method `Poker.Table.prototype.numSeats(): number` ``` -------------------------------- ### sitDown Source: https://github.com/claudijo/poker-ts/blob/main/README.md Records a player taking a seat at the table with a specified buy-in amount. The target seat must be unoccupied. ```APIDOC ## sitDown(seatIndex, buyIn) ### Description Indicates that a player has chosen to sit down at a specific seat with a given buy-in amount. The specified seat must be available (not occupied). ### Method POST ### Endpoint `Poker.Table.prototype.sitDown(seatIndex: number, buyIn: number)` ### Parameters #### Path Parameters - **seatIndex** (number) - Required - The index of the seat the player is taking. - **buyIn** (number) - Required - The amount of chips the player buys in with. ``` -------------------------------- ### Inspect Pot State with poker-ts Source: https://context7.com/claudijo/poker-ts/llms.txt Returns an array of pot objects, detailing the size and eligible players for each pot. Side pots are automatically created when players go all-in. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 200); // short stack table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); // Preflop all-in by short stack table.actionTaken('raise', 200); // player 0 goes all-in table.actionTaken('call'); table.actionTaken('call'); table.endBettingRound(); const pots = table.pots(); // Main pot: { size: 600, eligiblePlayers: [0, 1, 2] } // Side pot: { size: ..., eligiblePlayers: [1, 2] } (if further betting occurred) pots.forEach((pot, i) => { console.log(`Pot ${i}: ${pot.size} chips, players: [${pot.eligiblePlayers}]`); }); ``` -------------------------------- ### pots() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Retrieves the state of all pots in the current hand, including their size and the indices of eligible players. This can be used before calling `showdown()` to determine if a single player remains eligible to win the pot. ```APIDOC ## pots() ### Description Returns the state of all pots in the active hand. This endpoint can be used prior to calling `showdown()` to check if all but one last eligible player has folded. A single eligible player will win the pot, even though the `winnders()` endpoints returns an empty array under that circumstance. ### Method `Poker.Table.prototype.pots(): { size: number, eligiblePlayers: number[] }[]` ``` -------------------------------- ### Submit Player Action with poker-ts Source: https://context7.com/claudijo/poker-ts/llms.txt Records a player's action in the current betting round. 'betSize' is required for 'bet' and 'raise' actions and must be within the legal chip range. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.startHand(); // Preflop action loop table.actionTaken('call'); // player 0 calls table.actionTaken('fold'); // player 1 folds table.actionTaken('raise', 400); // player 2 raises to 400 table.actionTaken('call'); // player 0 calls the raise console.log(table.isBettingRoundInProgress()); // false (round over after last call) ``` -------------------------------- ### showdown() — Evaluate hands and pay winners Source: https://context7.com/claudijo/poker-ts/llms.txt Evaluates all remaining players' best hands from their hole cards and community cards, distributes pot(s) to winner(s), and removes busted players. This method should be called when `areBettingRoundsCompleted()` is true. ```APIDOC ## showdown() ### Description Evaluates all remaining players' 5-card best hands from their 2 hole cards and 5 community cards, distributes pot(s) to winner(s), and removes busted players (zero chips) from the table. Must be called when `areBettingRoundsCompleted()` is `true`. ### Method ```ts table.showdown(); ``` ### Response Example ```json { "example": "results is an array per pot; each pot has an array of winners: [ [ [seatIndex, handInfo, holeCards], ... ], ... ]" } ``` ``` -------------------------------- ### areBettingRoundsCompleted() / isHandInProgress() Source: https://context7.com/claudijo/poker-ts/llms.txt Provides state checks for the game. `areBettingRoundsCompleted()` indicates if the river betting is finished, while `isHandInProgress()` checks if the hand is currently active. ```APIDOC ## areBettingRoundsCompleted() / isHandInProgress() ### Description These methods provide crucial state checks for the poker hand. `areBettingRoundsCompleted()` returns `true` after the final betting round (river) has concluded, indicating that a `showdown()` should occur. `isHandInProgress()` returns `true` from the moment `startHand()` is called until the `showdown()` process is complete. ### Parameters None ### Response - **areBettingRoundsCompleted()**: `boolean` - `true` if all betting rounds are completed, `false` otherwise. - **isHandInProgress()**: `boolean` - `true` if a hand is currently being played, `false` otherwise. ### Response Example ```javascript // Assuming 'table' is an instance of Poker.Table // Example loop to play out a hand until completion while (table.isHandInProgress()) { while (table.isBettingRoundInProgress()) { table.actionTaken('call'); // Simplified action for example } table.endBettingRound(); if (table.areBettingRoundsCompleted()) { table.showdown(); break; } } console.log(table.isHandInProgress()); // Output: false (after hand completion) ``` ``` -------------------------------- ### Access showdown results with `winners()` Source: https://context7.com/claudijo/poker-ts/llms.txt Retrieve per-pot winner data after `showdown()` is called and `isHandInProgress()` is false. Handles cases where a winner is determined by default due to only one player remaining. ```typescript // HandRanking enum values: // 0=HIGH_CARD, 1=PAIR, 2=TWO_PAIR, 3=THREE_OF_A_KIND // 4=STRAIGHT, 5=FLUSH, 6=FULL_HOUSE, 7=FOUR_OF_A_KIND // 8=STRAIGHT_FLUSH, 9=ROYAL_FLUSH const results = table.winners(); if (results.length === 0) { // Only one player remained; use pots() to identify them const lastPot = table.pots(); console.log('Winner by default, seat:', lastPot[0].eligiblePlayers[0]); } else { const [[seat, hand, holeCards]] = results[0]; // first pot, first winner console.log('Seat:', seat); console.log('Ranking:', hand.ranking); // 0–9 console.log('Strength:', hand.strength); // numeric tiebreaker console.log('Cards:', hand.cards); } ``` -------------------------------- ### endBettingRound() Source: https://context7.com/claudijo/poker-ts/llms.txt Advances the game to the next street by collecting bets and dealing community cards. This should be called when a betting round is complete. ```APIDOC ## endBettingRound() ### Description Advances the game to the next street. This method collects all bets into pots and deals the next community cards (flop, turn, river). It should be called when `isBettingRoundInProgress()` returns `false` and `areBettingRoundsCompleted()` is still `false`. ### Parameters None ### Response This method does not return a value, but advances the game state to the next betting round or concludes the hand if all rounds are completed. ``` -------------------------------- ### winners() — Access showdown results Source: https://context7.com/claudijo/poker-ts/llms.txt Returns per-pot winner data after `showdown()` has been called and `isHandInProgress()` is `false`. Each entry contains the seat index, a hand object, and the player's hole cards. Returns an empty array if only one eligible player remained. ```APIDOC ## winners() ### Description Returns per-pot winner data after `showdown()` has been called and `isHandInProgress()` is `false`. Each entry contains the seat index, a hand object (`cards`, `ranking`, `strength`), and the player's hole cards. Returns an empty array if only one eligible player remained (winner by default, no evaluation needed). ### Method ```ts table.winners(); ``` ### Response Example ```json { "example": "[ [ [seatIndex, handInfo, holeCards], ... ], ... ]" } ``` ``` -------------------------------- ### Check Game State with poker-ts Source: https://context7.com/claudijo/poker-ts/llms.txt Provides methods to check if betting rounds are completed or if the hand is currently in progress. `areBettingRoundsCompleted()` signals readiness for `showdown()`, while `isHandInProgress()` tracks the hand's active state. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.startHand(); while (table.isHandInProgress()) { while (table.isBettingRoundInProgress()) { table.actionTaken('call'); // simplified: all players just call } table.endBettingRound(); if (table.areBettingRoundsCompleted()) { table.showdown(); break; } } console.log(table.isHandInProgress()); // false ``` -------------------------------- ### forcedBets() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Returns the current bet structure of the table, including ante, big blind, and small blind amounts. ```APIDOC ## forcedBets() ### Description Returns the current bet structure at the table. ### Method `Poker.Table.prototype.forcedBets(): { ante: number, bigBlind: number, smallBlind: number }` ``` -------------------------------- ### standUp Source: https://github.com/claudijo/poker-ts/blob/main/README.md Records a player leaving their seat at the table. The specified seat must be occupied by a player. ```APIDOC ## standUp(seatIndex) ### Description Indicates that a player has decided to stand up and leave the table from the specified seat. The seat must currently be occupied. ### Method POST ### Endpoint `Poker.Table.prototype.standUp(seatIndex: number)` ### Parameters #### Path Parameters - **seatIndex** (number) - Required - The index of the seat the player is leaving. ``` -------------------------------- ### Seat Player at Table Source: https://context7.com/claudijo/poker-ts/llms.txt Add a player to a specific seat with a given buy-in amount. The seat must be empty. The seats() method returns the current state of all seats. ```typescript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); // seat 0: 1000 chips table.sitDown(2, 1500); // seat 2: 1500 chips table.sitDown(5, 2000); // seat 5: 2000 chips // seats() returns full array with nulls for empty seats console.log(table.seats()); // [ // { totalChips: 1000, stack: 1000, betSize: 0 }, // null, // { totalChips: 1500, stack: 1500, betSize: 0 }, // null, null, // { totalChips: 2000, stack: 2000, betSize: 0 }, // null, null, null // ] ``` -------------------------------- ### seats() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Provides the current state of all players seated at the table, including their total chips, stack size, and current bet size. Returns an array of player states or null for empty seats. ```APIDOC ## seats() ### Description Returns the state of the players seated at the table. ### Method `Poker.Table.prototype.seats(): ({ totalChips: number, stack: number, betSize: number } | null)[]` ``` -------------------------------- ### isHandInProgress() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Checks if a poker hand is currently in progress. Returns `true` if a hand is active, `false` otherwise. ```APIDOC ## isHandInProgress() ### Description Returns `true` if hand is in progress. ### Method `Poker.Table.prototype.isHandInProgress(): boolean` ``` -------------------------------- ### showdown Source: https://github.com/claudijo/poker-ts/blob/main/README.md Initiates the showdown phase of the hand, evaluating player hands and distributing winnings. This method is called when betting rounds are completed and no betting round is in progress. ```APIDOC ## showdown() ### Description Performs the showdown, evaluating players' hands and awarding winnings to the victors. This method should be called when no betting round is in progress and all betting rounds are completed. Note: If there's only one eligible player left, the result might be empty; consider accessing `pots()` beforehand for explicit winner retrieval in such cases. ### Method POST ### Endpoint `Poker.Table.prototype.showdown()` ### Returns - **void** ``` -------------------------------- ### canSetAutomaticActions(seatIndex) / legalAutomaticActions(seatIndex) / setAutomaticAction(seatIndex, action) — Pre-actions Source: https://context7.com/claudijo/poker-ts/llms.txt Allows players other than the current player to pre-select their next action. `canSetAutomaticActions` checks eligibility, `legalAutomaticActions` returns allowed pre-actions, and `setAutomaticAction` sets or clears a pre-action. ```APIDOC ## canSetAutomaticActions(seatIndex) / legalAutomaticActions(seatIndex) / setAutomaticAction(seatIndex, action) ### Description Allows players other than the current player to act to pre-select their next action. `canSetAutomaticActions` checks eligibility (player must have been in the hand from the start and still be seated). `legalAutomaticActions` returns the allowed pre-actions: `'fold'`, `'check/fold'`, `'check'`, `'call'`, `'call any'`, `'all-in'`. `setAutomaticAction(seat, null)` clears a previously set pre-action. ### Methods - **canSetAutomaticActions(seatIndex)**: Checks if a player can set an automatic action. - **legalAutomaticActions(seatIndex)**: Returns a list of legal automatic actions for a given seat. - **setAutomaticAction(seatIndex, action)**: Sets or clears an automatic action for a given seat. ### Parameters #### `canSetAutomaticActions` & `legalAutomaticActions` - **seatIndex** (number) - Required - The index of the player's seat. #### `setAutomaticAction` - **seatIndex** (number) - Required - The index of the player's seat. - **action** (string | null) - Required - The pre-selected action (e.g., 'check', 'call') or `null` to clear. ### Response Example #### `legalAutomaticActions` Response ```json { "example": "['fold', 'check/fold', 'check', 'call any', 'all-in']" } ``` ``` -------------------------------- ### automaticActions Source: https://github.com/claudijo/poker-ts/blob/main/README.md Fetches the currently toggled automatic actions for players at the table. This method is relevant when a hand is in progress. ```APIDOC ## automaticActions() ### Description Returns the toggled automatic actions set by players at the table. This method is applicable when a hand is in progress. ### Method GET ### Endpoint `Poker.Table.prototype.automaticActions()` ### Returns - **(AutomaticAction | null)[]**: An array of automatic actions, where each element can be an `AutomaticAction` object or `null`. ``` -------------------------------- ### setAutomaticAction Source: https://github.com/claudijo/poker-ts/blob/main/README.md Configures the automatic action for a specified player. This is permissible if the player is allowed to set automatic actions and is not the current player to act. ```APIDOC ## setAutomaticAction(seatIndex, action) ### Description Sets or clears the automatic action for a player at the given `seatIndex`. This operation is valid if the player is allowed to set automatic actions and is not the player whose turn it is. ### Method POST ### Endpoint `Poker.Table.prototype.setAutomaticAction(seatIndex: number, action: AutomaticAction | null)` ### Parameters #### Path Parameters - **seatIndex** (number) - Required - The index of the seat for which to set the automatic action. - **action** (AutomaticAction | null) - Required - The automatic action to set, or `null` to clear any existing automatic action. ``` -------------------------------- ### standUp(seatIndex) Source: https://context7.com/claudijo/poker-ts/llms.txt Removes a player from the table. If a hand is in progress, the player is automatically folded if they have not yet acted. ```APIDOC ## standUp(seatIndex) ### Description Removes a player from the table. If a hand is in progress and the player has not yet acted, they are automatically folded. If they are the current player to act, the fold is immediate. ### Method `standUp` ### Parameters #### Path Parameters - **seatIndex** (number) - Required - The 0-based index of the seat to vacate. ### Request Example ```javascript const Poker = require('poker-ts'); const table = new Poker.Table({ smallBlind: 50, bigBlind: 100 }); table.sitDown(0, 1000); table.sitDown(1, 1000); table.sitDown(2, 1000); table.standUp(2); // remove player before hand starts console.log(table.seats()[2]); // null // Stand up mid-hand: player is auto-folded table.sitDown(2, 1000); table.startHand(); table.standUp(2); // player 2 will be auto-folded on their turn ``` ``` -------------------------------- ### button() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Returns the seat index of the dealer button. This method can only be called when a hand is in progress. ```APIDOC ## button() ### Description Returns the seat index of the dealer button. (Hand must be in progress.) ### Method `Poker.Table.prototype.button(): number` ``` -------------------------------- ### endBettingRound Source: https://github.com/claudijo/poker-ts/blob/main/README.md Concludes the current betting round, collects bets, and forms pots. This method is used when a betting round is no longer in progress but betting rounds are not yet completed. ```APIDOC ## endBettingRound() ### Description Ends the current betting round, which must not be in progress. This action collects bets and forms the pots. It is used when betting rounds are not yet completed. ### Method POST ### Endpoint `Poker.Table.prototype.endBettingRound()` ### Returns - **void** ``` -------------------------------- ### legalAutomaticActions Source: https://github.com/claudijo/poker-ts/blob/main/README.md Retrieves the available automatic actions for a player at a given seat index. Requires that the player is allowed to set automatic actions. ```APIDOC ## legalAutomaticActions(seatIndex) ### Description Returns an array of all legal automatic actions that a player at the specified `seatIndex` can choose. This method is applicable when the player is permitted to set automatic actions. ### Method GET ### Endpoint `Poker.Table.prototype.legalAutomaticActions(seatIndex: number)` ### Parameters #### Path Parameters - **seatIndex** (number) - Required - The index of the seat whose legal automatic actions are to be retrieved. ### Returns - **AutomaticAction[]**: An array of `AutomaticAction` objects representing the legal choices. ``` -------------------------------- ### playerToAct() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Retrieves the seat index of the player whose turn it is to act during a betting round. This method requires that a betting round is currently in progress. ```APIDOC ## playerToAct() ### Description Returns the seat index of the player to act. (Betting round must be in progress.) ### Method `Poker.Table.prototype.playerToAct(): number` ``` -------------------------------- ### holeCards() Source: https://context7.com/claudijo/poker-ts/llms.txt Returns an array representing the hole cards for each seat at the table. Each element is either null or an array of two Card objects. ```APIDOC ## holeCards() ### Description Returns an array of length `numSeats`. Each element is either `null` (empty seat or folded) or an array of two `Card` objects `{ rank, suit }`. Available during or after a hand. ### Parameters None ### Response - **Array** - An array where each index corresponds to a seat. Elements are either `null` or an array of two `Card` objects. - **Card object** `{ rank: string, suit: string }` ### Response Example ```javascript // Assuming 'table' is an instance of Poker.Table const holeCards = table.holeCards(); // Example output for a 3-seat table where seat 0 has cards: // holeCards[0] => [{ rank: 'A', suit: 'spades' }, { rank: 'K', suit: 'hearts' }] // holeCards[1] => null // holeCards[2] => [{ rank: '7', suit: 'clubs' }, { rank: '2', suit: 'diamonds' }] // Iterating through hole cards: for (let seat = 0; seat < holeCards.length; seat++) { if (holeCards[seat]) { const [c1, c2] = holeCards[seat]; console.log(`Seat ${seat}: ${c1.rank}${c1.suit[0]} ${c2.rank}${c2.suit[0]}`); } } ``` ``` -------------------------------- ### communityCards() Source: https://context7.com/claudijo/poker-ts/llms.txt Returns an array of Card objects representing the community cards dealt on the board so far. ```APIDOC ## communityCards() ### Description Returns an array of `Card` objects dealt to the board so far. This array is empty before the first betting round concludes and populates as the hand progresses (flop, turn, river). ### Parameters None ### Response - **Array** - An array of `Card` objects representing the community cards. - **Card object** `{ rank: string, suit: string }` ### Response Example ```javascript // Assuming 'table' is an instance of Poker.Table and the flop has been dealt const flop = table.communityCards(); console.log(flop.length); // Output: 3 console.log(flop[0]); // Example output: { rank: 'T', suit: 'diamonds' } ``` ``` -------------------------------- ### handPlayers() Source: https://github.com/claudijo/poker-ts/blob/main/README.md Returns the state of players actively participating in the current hand. This includes their total chips, stack size, and current bet size. This method requires a hand to be in progress. ```APIDOC ## handPlayers() ### Description Returns the state of the players currently in the hand. (Hand must be in progress.) ### Method `Poker.Table.prototype.handPlayers(): ({ totalChips: number, stack: number, betSize: number } | null)[]` ``` -------------------------------- ### winners Source: https://github.com/claudijo/poker-ts/blob/main/README.md Retrieves the winner(s) for each pot after a showdown has occurred. This method is used when the hand is not in progress. ```APIDOC ## winners() ### Description Returns the winner(s) for each pot after the showdown. This method is applicable when the hand is not in progress. For each pot, it details the winner's seat index, their hand (including five winning cards, ranking, and strength), and their hole cards. The result may be an empty array if there's a single eligible player in one pot. ### Method GET ### Endpoint `Poker.Table.prototype.winners()` ### Returns - **[SeatIndex, { cards: Card[], ranking: HandRanking, strength: number }, Card[]][][]**: A multi-dimensional array detailing winners for each pot. ```