Skip to main content

decideAction guide

Rule-based action from serialized table state, Monte Carlo equity (or strength fallback when sim count is 0), pot odds, and call EV.

State shape

See NativePokerState. You may pass PKST Uint8Array from encodePokerState or packPokerState instead of a live object—see Packed poker state.

FieldRequiredNotes
players[]yesEach player needs holeCards: CardInput (string[] or packed Uint8Array)
communityCardsyesBoard cards (CardInput)
phaseyespreflop, flop, turn, river, showdown, handcomplete (case variants accepted)
actedThisStreetyesOne boolean per player
pot, currentBet, blinds, seatsoptionalTable geometry

Hero seat: pass heroSeat explicitly, or the engine uses the acting player's seat, or seat 0.

Config

See NativeBotConfig and optional NativeOpponentModel.

normalizeBotConfig fills missing fields and clamps values before you call policy exports.

When monteCarloSimulations is 0, strategy falls back to encoded hand strength instead of simulated equity.

Example

const poker = require('poker-calculations');

const state = {
players: [
{
name: 'Hero',
holeCards: ['Ah', 'Kh'],
stack: 200,
committedThisStreet: 0,
seat: 0,
},
{
name: 'Villain',
holeCards: ['Qc', 'Qd'],
stack: 180,
committedThisStreet: 10,
seat: 1,
},
],
communityCards: ['Qh', 'Jh', '2c'],
phase: 'flop',
pot: 30,
currentBet: 10,
smallBlind: 1,
bigBlind: 2,
buttonSeat: 0,
actingIndex: 0,
actedThisStreet: [false, true],
};

const config = {
monteCarloSimulations: 2000,
monteCarloVillains: 1,
rngSeed: 42,
};

const decision = poker.decideAction(state, config, null, 0);
console.log(decision.action, decision.raiseBy);

Non-blocking and cancellation

decideActionAsync runs the same logic on the libuv thread pool. When monteCarloSimulations > 0, pass AsyncOptions to abort in-flight Monte Carlo:

const ac = new AbortController();
const pending = poker.decideActionAsync(state, config, null, 0, { signal: ac.signal });
// ac.abort(); // Promise rejects with AbortError
const decision = await pending;

Diagnostics and EV breakdown

ExportUse when
decideActionWithDiagnosticsYou need the chosen action plus legal actions, EV breakdown, and a reason string in one call. Returns DecisionDiagnosticResult.
actionEvBreakdownYou want fold/check/call/raise EV and equity without committing to a single action. Returns ActionEvBreakdownResult.
explainDecisionFactorsYou need ranked human-readable factors behind a policy choice. Returns DecisionFactor rows.
ExportUse when
validatePokerStatePre-flight a snapshot before simulation or policy runs. Returns PokerStateValidationResult.
legalActionSummaryYou need raise bounds and which actions are legal. Returns LegalActionSummaryResult.
candidateActionSetBuild a discrete action menu with raise sizes. Returns CandidateAction rows.
actionMaskFromStateEncode legality as a compact bitmask for ML or fast filters.

Batch policy and features

ExportUse when
runBotPolicyBatchEvaluate many table snapshots in one native crossing.
stateToFeatureVectorFeed a fixed-length numeric vector into custom models or clustering.

PKST binary snapshots

encodePokerState and decodePokerState round-trip NativePokerState through PKST bytes. Pure-JS helpers also ship on poker-calculations/encode.

API reference

Full Import / When / How for every export in the Strategy category.