@block52/poker-vm-sdk 1.2.15 → 1.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -57319,6 +57319,109 @@ Deck.SUIT_MAP = {
57319
57319
  [exports.SUIT.SPADES]: "S"
57320
57320
  };
57321
57321
 
57322
+ /**
57323
+ * The community board for a Texas Hold'em hand.
57324
+ *
57325
+ * Encapsulates the two community-card arrays the engine currently keeps — the
57326
+ * cards dealt street-by-street (`street`, persisted to the DTO) and the five
57327
+ * pre-dealt up front at `deal()` (`preDealt`) — behind one type. This is a pure
57328
+ * refactor: every accessor returns exactly what the inline engine logic did, so
57329
+ * behaviour is unchanged. Collapsing the two arrays into a single canonical
57330
+ * board is a separate, consensus-affecting change (issue #2299).
57331
+ */
57332
+ class Board {
57333
+ constructor() {
57334
+ // Dealt one street at a time via dealCommunityCards() (was `_communityCards`).
57335
+ // This is the board persisted to the game DTO and rehydrated from JSON.
57336
+ this.street = [];
57337
+ // All five dealt up front at deal() (was `_communityCards2`).
57338
+ this.preDealt = [];
57339
+ }
57340
+ /**
57341
+ * Append cards dealt for the current street (was `_communityCards.push`).
57342
+ */
57343
+ addStreet(cards) {
57344
+ this.street.push(...cards);
57345
+ }
57346
+ /**
57347
+ * Record the five cards pre-dealt at deal() (was `_communityCards2.push`).
57348
+ */
57349
+ setPreDealt(cards) {
57350
+ this.preDealt.push(...cards);
57351
+ }
57352
+ /**
57353
+ * Number of street-dealt cards (was `_communityCards.length`).
57354
+ */
57355
+ get streetLength() {
57356
+ return this.street.length;
57357
+ }
57358
+ /**
57359
+ * Number of pre-dealt cards (was `_communityCards2.length`).
57360
+ */
57361
+ get preDealtLength() {
57362
+ return this.preDealt.length;
57363
+ }
57364
+ /**
57365
+ * The street-dealt community cards (was `[...this._communityCards]`).
57366
+ */
57367
+ get cards() {
57368
+ return [...this.street];
57369
+ }
57370
+ /**
57371
+ * The community cards visible at a given round, taken from the pre-dealt
57372
+ * board — matching the previous `getCommunityCards()` exactly:
57373
+ * FLOP -> preDealt[0..3], TURN -> preDealt[0..4], RIVER -> preDealt[0..5].
57374
+ */
57375
+ forRound(round) {
57376
+ const cards = [];
57377
+ if (round === exports.TexasHoldemRound.FLOP) {
57378
+ cards.push(...this.preDealt.slice(0, 3));
57379
+ }
57380
+ if (round === exports.TexasHoldemRound.TURN) {
57381
+ cards.push(...this.preDealt.slice(0, 4));
57382
+ }
57383
+ if (round === exports.TexasHoldemRound.RIVER) {
57384
+ cards.push(...this.preDealt.slice(0, 5));
57385
+ }
57386
+ return cards;
57387
+ }
57388
+ /**
57389
+ * The board `findWinners` falls back to when `forRound` is short: the
57390
+ * pre-dealt board for live games, else the street board rehydrated from JSON.
57391
+ * Preserves the previous inline selection verbatim.
57392
+ */
57393
+ forEvaluation(count) {
57394
+ return this.preDealt.length >= count
57395
+ ? this.preDealt.slice(0, count)
57396
+ : this.street.slice(0, count);
57397
+ }
57398
+ /**
57399
+ * The board `calculateWinner` falls back to at an early showdown: the fully
57400
+ * dealt street board if available, else the pre-dealt board. Preserves the
57401
+ * previous inline selection verbatim.
57402
+ */
57403
+ forShowdown() {
57404
+ return this.street.length >= Board.MAX_COMMUNITY_CARDS
57405
+ ? this.street.slice(0, Board.MAX_COMMUNITY_CARDS)
57406
+ : this.preDealt.slice(0, Board.MAX_COMMUNITY_CARDS);
57407
+ }
57408
+ /**
57409
+ * Clear both boards for a new hand (was two `.length = 0` assignments).
57410
+ */
57411
+ clear() {
57412
+ this.street.length = 0;
57413
+ this.preDealt.length = 0;
57414
+ }
57415
+ /**
57416
+ * Serialize the street board to mnemonics, matching
57417
+ * `TexasHoldemStateDTO.communityCards` (was `_communityCards.map(...)`).
57418
+ */
57419
+ toJson() {
57420
+ return this.street.map(card => card.mnemonic);
57421
+ }
57422
+ }
57423
+ Board.MAX_COMMUNITY_CARDS = 5;
57424
+
57322
57425
  /**
57323
57426
  * Example integration of custom poker solver with game engine
57324
57427
  * Demonstrates how to replace pokersolver with our custom implementation
@@ -61055,19 +61158,33 @@ class SigningCosmosClient extends CosmosClient {
61055
61158
  }
61056
61159
  }
61057
61160
  /**
61058
- * Leave a poker game
61161
+ * Leave a poker game (signs AND broadcasts MsgLeaveGame directly).
61162
+ *
61163
+ * @param gameId the game to leave / claim from.
61164
+ * @param finishingOrder place-1-first player addresses for an SNG that
61165
+ * finalized off-chain (WS-first) — lets the chain recompute payouts when
61166
+ * its Results are empty. Defaults to `[]` (cash games / already-finalized
61167
+ * SNGs, where the chain settles from its own state). Broadcast counterpart
61168
+ * of {@link signLeaveGame}.
61059
61169
  */
61060
- async leaveGame(gameId) {
61170
+ async leaveGame(gameId, finishingOrder = []) {
61061
61171
  await this.initializeSigningClient();
61062
61172
  if (!this.signingClient || !this.wallet) {
61063
61173
  throw new Error("Signing client not initialized");
61064
61174
  }
61065
61175
  const [account] = await this.wallet.getAccounts();
61066
61176
  const creator = account.address;
61067
- // Create the message object
61177
+ // Create the message object.
61178
+ //
61179
+ // finishingOrder (place-1-first player addresses) is for an SNG that
61180
+ // finalized off-chain (WS-first): the chain's Results may be empty, so
61181
+ // the message supplies the ORDER and the chain recomputes payouts from
61182
+ // its own prize-pool math — never an amount. Empty for cash games and
61183
+ // for SNGs the chain already finalized. Mirrors signLeaveGame. (pokerchain#229)
61068
61184
  const msgLeaveGame = {
61069
61185
  creator,
61070
- gameId
61186
+ gameId,
61187
+ finishingOrder
61071
61188
  };
61072
61189
  // Create the transaction message
61073
61190
  const msg = {
@@ -61851,6 +61968,7 @@ const registry = new protoSigning.Registry([
61851
61968
 
61852
61969
  exports.AllPlayerActions = AllPlayerActions;
61853
61970
  exports.BLOCK52_HD_PATH = BLOCK52_HD_PATH;
61971
+ exports.Board = Board;
61854
61972
  exports.COSMOS_CONSTANTS = COSMOS_CONSTANTS;
61855
61973
  exports.Client = Client;
61856
61974
  exports.CosmosClient = CosmosClient;