tg-poker-engine
v0.0.1
Published
Shared types and Texas Hold'em engine (cards, hand evaluation, NL betting) for Telegram poker apps.
Maintainers
Readme
tg-poker-engine
Shared TypeScript types for a Telegram poker product plus a small Texas Hold’em engine (deck, hand evaluation, and no-limit betting state machine).
Install
npm install tg-poker-enginePackage entry points
| Subpath | Contents |
|--------|----------|
| tg-poker-engine | Domain types (UserRole, TableStatus, …) and everything from ./tg-poker-engine (re-exported). |
| tg-poker-engine/tg-poker-engine | Poker engine only (cards, evaluation, Hold’em). |
Both paths resolve to the same compiled modules under dist/.
Card notation
Cards are strings: rank + suit.
- Ranks:
2–9,T(ten),J,Q,K,A(ace high = 14 internally). - Suits:
cclubs,ddiamonds,hhearts,sspades.
Example: "Ah" is ace of hearts.
Poker engine API (high level)
Cards
fullDeck()— 52 cards in rank/suit order.shuffle(items, rng?)— Fisher–Yates; optionalrng(defaults toMath.random).rankOf(card),suitOf(card)— parse a card string.
Hand evaluation
scoreFiveCards(cards)— score vector for exactly five cards (straight wheel A–5 handled).bestScoreFrom7(cards)— best five from seven (Hold’em).compareScores(a, b)— lexicographic compare; positive ifawins.describeScore(score)— human-readable label.
Hold’em
startHoldemHand({ seats, buttonSeat, smallBlind, bigBlind, handSeq, rng? })— new hand: blinds, deal,toActSeatset.applyHoldemAction(state, seatIndex, action)— fold / check / call /bet/raise_to; mutatesstate.holdemPublicSnapshot(state)— table-safe view (optionallyrevealedHoles,awardedPotwhen complete).viewerHoleCards(state, seatIndex)— hole cards for one seat.forceFoldPlayer(state, seatIndex)— fold out of turn (e.g. disconnect).nextButtonSeat(occupiedSorted, currentButton)— rotate button among occupied seats.
Client actions (HoldemClientAction):
{ type: "fold" }{ type: "check" }— only when not facing a bet.{ type: "call" }{ type: "bet", amount }— first aggression on a street (minimum = big blind whenmaxStreetBet === 0).{ type: "raise_to", amount }— total street commitment after the action; must beat current max and satisfyminRaiseunless shoving.
Build from source
npm install
npm run buildOutput is written to dist/ (CommonJS require / exports, with .d.ts types).
Publishing checklist
- Set
nameinpackage.jsonto the scoped name you own on npm (or unscope it). - Set
license(default in this repo isUNLICENSED; useMITor another SPDX id and add aLICENSEfile if you open-source it). - Bump
version, then runnpm publish. Scoped packages default to private on npm; this repo setspublishConfig.access="public"so a plainnpm publishis enough (or usenpm publish --access publiconce if you remove that field).prepublishOnlyrunsnpm run buildautomatically sodist/matches sources. - The
"files"field limits the tarball todist/; npm still shipsREADME.mdandpackage.jsonautomatically.
Review notes (correctness & limits)
The public functions are internally consistent: five-card scoring, wheel straight, seven-card best hand, and Hold’em blind / deal order (including heads-up) match usual rules.
Limits you should know before production use:
- Single main pot only — there are no side pots. If multiple players are all-in for different amounts, chip accounting is not split into side pots.
- No card validation —
rankOf/ evaluation assume valid"[23456789TJQKA][cdhs]"strings; garbage input can yieldNaNor nonsense scores. - Mutating state —
applyHoldemActionand related helpers mutate the passedHoldemState. Clone first if you need time-travel or optimistic UI rollback. - Module format — compiled output is CommonJS; modern bundlers and recent Node versions still consume this fine via the
exportsmap; if you need pure ESM-only publishing, adjusttsconfig/package.json"type"separately.
There is no single “incorrect method” in the sense of a wrong signature; the important caveat is side-pot absence for real-money or full tournament logic.
License
See package.json field "license" (set by the package maintainer).
