Skip to main content

Packed poker state (PKST)

decideAction and decideActionAsync accept either a NativePokerState object or Uint8Array PKST bytes from encodePokerState. The async export also accepts optional AsyncOptions to cancel in-flight Monte Carlo.

Why pack state

Object snapshots repeat UTF-8 parsing and property walks on every bot tick. PKST bytes are a fixed layout the native layer decodes once per call.

Encode / decode

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

const bytes = poker.encodePokerState(state);
const roundTrip = poker.decodePokerState(bytes);

const decision = poker.decideAction(bytes, { monteCarloSimulations: 2000 });

encode.js helpers

const { packPokerState, unpackPokerState } = require('poker-calculations/encode');

const bytes = packPokerState(state);
const obj = unpackPokerState(bytes);

Layout (summary)

FieldNotes
MagicPKST (4 bytes)
Layout version byteSingle byte after magic (wire format revision; not an npm release version)
PlayersUp to 10; per player: hole cards as deck ids, stack/commit flags
CommunityUp to 5 cards
Pot / blinds / phaseLittle-endian int32 fields

Full layout is documented in the npm package (include/poker/state_codec.hpp).

See also

decideAction guide · NativePokerState