@block52/poker-vm-sdk 1.12.0 → 1.14.0

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
@@ -2850,6 +2850,7 @@ function createBaseMsgCreateGame() {
2850
2850
  bettingLimit: "",
2851
2851
  startTime: Long.ZERO,
2852
2852
  blindStructure: "",
2853
+ lateRegistrationLevels: 0,
2853
2854
  };
2854
2855
  }
2855
2856
  const MsgCreateGame = {
@@ -2917,6 +2918,9 @@ const MsgCreateGame = {
2917
2918
  if (message.blindStructure !== "") {
2918
2919
  writer.uint32(178).string(message.blindStructure);
2919
2920
  }
2921
+ if (message.lateRegistrationLevels !== 0) {
2922
+ writer.uint32(184).uint32(message.lateRegistrationLevels);
2923
+ }
2920
2924
  return writer;
2921
2925
  },
2922
2926
  decode(input, length) {
@@ -3073,6 +3077,13 @@ const MsgCreateGame = {
3073
3077
  message.blindStructure = reader.string();
3074
3078
  continue;
3075
3079
  }
3080
+ case 23: {
3081
+ if (tag !== 184) {
3082
+ break;
3083
+ }
3084
+ message.lateRegistrationLevels = reader.uint32();
3085
+ continue;
3086
+ }
3076
3087
  }
3077
3088
  if ((tag & 7) === 4 || tag === 0) {
3078
3089
  break;
@@ -3104,6 +3115,7 @@ const MsgCreateGame = {
3104
3115
  bettingLimit: isSet$2b(object.bettingLimit) ? globalThis.String(object.bettingLimit) : "",
3105
3116
  startTime: isSet$2b(object.startTime) ? Long.fromValue(object.startTime) : Long.ZERO,
3106
3117
  blindStructure: isSet$2b(object.blindStructure) ? globalThis.String(object.blindStructure) : "",
3118
+ lateRegistrationLevels: isSet$2b(object.lateRegistrationLevels) ? globalThis.Number(object.lateRegistrationLevels) : 0,
3107
3119
  };
3108
3120
  },
3109
3121
  toJSON(message) {
@@ -3171,6 +3183,9 @@ const MsgCreateGame = {
3171
3183
  if (message.blindStructure !== "") {
3172
3184
  obj.blindStructure = message.blindStructure;
3173
3185
  }
3186
+ if (message.lateRegistrationLevels !== 0) {
3187
+ obj.lateRegistrationLevels = Math.round(message.lateRegistrationLevels);
3188
+ }
3174
3189
  return obj;
3175
3190
  },
3176
3191
  create(base) {
@@ -3220,6 +3235,7 @@ const MsgCreateGame = {
3220
3235
  ? Long.fromValue(object.startTime)
3221
3236
  : Long.ZERO;
3222
3237
  message.blindStructure = object.blindStructure ?? "";
3238
+ message.lateRegistrationLevels = object.lateRegistrationLevels ?? 0;
3223
3239
  message.entryFee = (object.entryFee !== undefined && object.entryFee !== null)
3224
3240
  ? Long.fromValue(object.entryFee)
3225
3241
  : Long.UZERO;
@@ -56096,6 +56112,11 @@ exports.PlayerActionType = void 0;
56096
56112
  exports.NonPlayerActionType = void 0;
56097
56113
  (function (NonPlayerActionType) {
56098
56114
  NonPlayerActionType["DEAD_SMALL_BLIND"] = "dead-small-blind";
56115
+ // Big-blind ante on a tournament-directed table (poker-vm#2613 slice 7):
56116
+ // dead money the big blind posts for the table before the blind itself,
56117
+ // from the tournament clock. Engine-recorded, never submitted; in the pot
56118
+ // but not a bet the others must match.
56119
+ NonPlayerActionType["ANTE"] = "ante";
56099
56120
  NonPlayerActionType["DEAL"] = "deal";
56100
56121
  NonPlayerActionType["FORCE_CLOSE"] = "force-close";
56101
56122
  NonPlayerActionType["JOIN"] = "join";
@@ -57064,6 +57085,47 @@ function expandBlindLevel(structure, n) {
57064
57085
  return { level: n, smallBlind: sb.toString(), bigBlind: bb.toString(), ante: ante.toString(), durationMinutes: structure.durationMinutes, isBreak: false };
57065
57086
  }
57066
57087
 
57088
+ /**
57089
+ * Late registration for a scheduled sit-and-go (poker-vm#2731), read the way
57090
+ * the engine decides it: after the start, a join is accepted while the blind
57091
+ * level at block time is below `gameOptions.lateRegistrationLevels`, until
57092
+ * anyone has finished in the money. The blind clock — and so the window —
57093
+ * runs from the first deal (`sngStartTime`).
57094
+ */
57095
+ /** When late registration closes (epoch ms): the end of the last open level.
57096
+ * Undefined when the table has no late registration, or has not dealt yet
57097
+ * (the clock has not started, so the window has no end time). */
57098
+ function lateRegistrationClosesAt(options) {
57099
+ const levels = options.lateRegistrationLevels;
57100
+ if (!levels || options.scheduledStartTime === undefined || options.sngStartTime === undefined) {
57101
+ return undefined;
57102
+ }
57103
+ let minutes = 0;
57104
+ for (let n = 0; n < levels; n++) {
57105
+ minutes += options.blindStructure ? expandBlindLevel(options.blindStructure, n).durationMinutes : levelMinutes(options);
57106
+ }
57107
+ return options.sngStartTime + minutes * 60000;
57108
+ }
57109
+ /** Whether a join after the start would be accepted at nowMs. Before the
57110
+ * first deal the window is open (level 0); it shuts at
57111
+ * lateRegistrationClosesAt, or once any result carries a payout. */
57112
+ function isLateRegistrationOpen(options, results, nowMs) {
57113
+ if (!options.lateRegistrationLevels || options.scheduledStartTime === undefined) {
57114
+ return false;
57115
+ }
57116
+ if (results.some(r => BigInt(r.payout) > 0n)) {
57117
+ return false;
57118
+ }
57119
+ const closesAt = lateRegistrationClosesAt(options);
57120
+ return closesAt === undefined || nowMs < closesAt;
57121
+ }
57122
+ function levelMinutes(options) {
57123
+ if (!options.blindLevelDuration || options.blindLevelDuration <= 0) {
57124
+ throw new Error(`a sit-and-go needs a positive blindLevelDuration or a blindStructure; got ${options.blindLevelDuration}.`);
57125
+ }
57126
+ return options.blindLevelDuration;
57127
+ }
57128
+
57067
57129
  /**
57068
57130
  * Poker hand types in order of strength (weakest to strongest)
57069
57131
  */
@@ -57116,6 +57178,10 @@ class PokerSolver {
57116
57178
  /**
57117
57179
  * Evaluate a 5-card poker hand
57118
57180
  */
57181
+ /**
57182
+ * Evaluate exactly 5 cards (a winner's best hand, WinnerDTO.cards). Use
57183
+ * findBestHand for 7.
57184
+ */
57119
57185
  static evaluateHand(cards) {
57120
57186
  if (cards.length !== 5) {
57121
57187
  throw new Error("Hand evaluation requires exactly 5 cards");
@@ -58193,37 +58259,116 @@ class PokerGameIntegration {
58193
58259
  };
58194
58260
  }
58195
58261
  /**
58196
- * Create a formatted hand description for UI display
58262
+ * The winning hand in words, from the winner's best five cards
58263
+ * (WinnerDTO.cards) and the board (communityCards): "Full House, Eights
58264
+ * over Sevens", "Diamond Flush, Six high", "Set of Sevens". The board tells
58265
+ * a set (pocket pair plus one on the board) from trips (one hole card plus a
58266
+ * board pair, or all three on the board), which the five cards alone can't.
58267
+ * @param cards The winner's five card mnemonics ("6D")
58268
+ * @param board The community cards
58269
+ * @returns The hand in words, or "" for an uncontested pot (no cards)
58270
+ */
58271
+ static describeWinningHand(cards, board) {
58272
+ if (!cards || cards.length === 0)
58273
+ return "";
58274
+ if (cards.length !== 5) {
58275
+ throw new Error(`describeWinningHand expects the winning five cards, got ${cards.length}`);
58276
+ }
58277
+ const evaluation = PokerSolver.evaluateHand(cards.map(c => Deck.fromString(c)));
58278
+ if (evaluation.handType === exports.HandType.THREE_OF_A_KIND) {
58279
+ const tripRank = evaluation.rankValues[0];
58280
+ const onBoard = board.map(c => Deck.fromString(c)).filter(c => (c.rank === 1 ? 14 : c.rank) === tripRank).length;
58281
+ if (onBoard === 1)
58282
+ return `Set of ${this.rankWord(tripRank, true)}`;
58283
+ }
58284
+ return this.formatHandDescription(evaluation);
58285
+ }
58286
+ /**
58287
+ * Fill in each winner's name and description from its cards and the board.
58288
+ * The engine no longer writes the hand's wording into chain state
58289
+ * (poker-vm#2721), so callers run game state through this as it arrives and
58290
+ * keep reading winner.name / winner.description as before.
58291
+ *
58292
+ * A winner with five cards gets "Full House, Eights over Sevens" in both
58293
+ * fields. A winner without five cards (an uncontested pot, or an older state
58294
+ * that recorded hole cards) is returned unchanged.
58295
+ *
58296
+ * Returns a new state object; the input is not modified.
58297
+ * @param state Any game state with winners and community cards
58298
+ */
58299
+ static withWinnerDescriptions(state) {
58300
+ const winners = state.winners.map(winner => {
58301
+ if (!winner.cards || winner.cards.length !== 5)
58302
+ return winner;
58303
+ const description = this.describeWinningHand(winner.cards, state.communityCards);
58304
+ return { ...winner, name: description, description };
58305
+ });
58306
+ return { ...state, winners };
58307
+ }
58308
+ /**
58309
+ * The hand description in words: "Full House, Eights over Sevens", "Quad
58310
+ * Fours", "Diamond Flush, Six high", "Ace high". A flush names its suit from
58311
+ * the best hand. The rank and suit words mirror @block52/deck's rankName /
58312
+ * suitName.
58197
58313
  * @param evaluation Hand evaluation result
58198
58314
  * @returns Human-readable hand description
58199
58315
  */
58200
58316
  static formatHandDescription(evaluation) {
58201
- const { handType, rankValues, description } = evaluation;
58317
+ const { handType, rankValues, description, bestHand } = evaluation;
58318
+ const suit = this.flushSuitWord(bestHand);
58319
+ const suited = (hand) => (suit ? `${suit} ${hand}` : hand);
58202
58320
  switch (handType) {
58203
58321
  case exports.HandType.ROYAL_FLUSH:
58204
- return "Royal Flush";
58322
+ return suit ? `Royal Flush in ${suit}s` : "Royal Flush";
58205
58323
  case exports.HandType.STRAIGHT_FLUSH:
58206
- return `Straight Flush, ${PokerSolver.formatRank(rankValues[0])} high`;
58324
+ return `${suited("Straight Flush")}, ${this.rankWord(rankValues[0])} high`;
58207
58325
  case exports.HandType.FOUR_OF_A_KIND:
58208
- return `Four ${PokerSolver.formatRank(rankValues[0])}s`;
58326
+ return `Quad ${this.rankWord(rankValues[0], true)}`;
58209
58327
  case exports.HandType.FULL_HOUSE:
58210
- return `Full House, ${PokerSolver.formatRank(rankValues[0])}s over ${PokerSolver.formatRank(rankValues[1])}s`;
58328
+ return `Full House, ${this.rankWord(rankValues[0], true)} over ${this.rankWord(rankValues[1], true)}`;
58211
58329
  case exports.HandType.FLUSH:
58212
- return `Flush, ${PokerSolver.formatRank(rankValues[0])} high`;
58330
+ return `${suited("Flush")}, ${this.rankWord(rankValues[0])} high`;
58213
58331
  case exports.HandType.STRAIGHT:
58214
- return `Straight, ${PokerSolver.formatRank(rankValues[0])} high`;
58332
+ return `Straight, ${this.rankWord(rankValues[0])} high`;
58215
58333
  case exports.HandType.THREE_OF_A_KIND:
58216
- return `Three ${PokerSolver.formatRank(rankValues[0])}s`;
58334
+ return `Trip ${this.rankWord(rankValues[0], true)}`;
58217
58335
  case exports.HandType.TWO_PAIR:
58218
- return `Two Pair, ${PokerSolver.formatRank(rankValues[0])}s and ${PokerSolver.formatRank(rankValues[1])}s`;
58336
+ return `Two Pair, ${this.rankWord(rankValues[0], true)} and ${this.rankWord(rankValues[1], true)}`;
58219
58337
  case exports.HandType.PAIR:
58220
- return `Pair of ${PokerSolver.formatRank(rankValues[0])}s`;
58338
+ return `Pair of ${this.rankWord(rankValues[0], true)}`;
58221
58339
  case exports.HandType.HIGH_CARD:
58222
- return `${PokerSolver.formatRank(rankValues[0])} high`;
58340
+ return `${this.rankWord(rankValues[0])} high`;
58223
58341
  default:
58224
58342
  return description;
58225
58343
  }
58226
58344
  }
58345
+ /** A high-ace rank spelled out ("Ace", "Ten"); plural gives "Aces", "Sixes". */
58346
+ static rankWord(rank, plural = false) {
58347
+ const words = this.RANK_WORDS[rank === 1 ? 14 : rank];
58348
+ if (!words)
58349
+ return plural ? `${PokerSolver.formatRank(rank)}s` : PokerSolver.formatRank(rank);
58350
+ return plural ? words[1] : words[0];
58351
+ }
58352
+ /** The suit word every card of a flush shares ("Diamond"), or "" when the hand is empty or mixed. */
58353
+ static flushSuitWord(cards) {
58354
+ if (!cards || cards.length === 0)
58355
+ return "";
58356
+ const suit = cards[0].suit;
58357
+ if (cards.some(c => c.suit !== suit))
58358
+ return "";
58359
+ switch (suit) {
58360
+ case exports.SUIT.CLUBS:
58361
+ return "Club";
58362
+ case exports.SUIT.DIAMONDS:
58363
+ return "Diamond";
58364
+ case exports.SUIT.HEARTS:
58365
+ return "Heart";
58366
+ case exports.SUIT.SPADES:
58367
+ return "Spade";
58368
+ default:
58369
+ return "";
58370
+ }
58371
+ }
58227
58372
  /**
58228
58373
  * Example usage with string cards (for testing/debugging)
58229
58374
  * @param playerCardStrings Array of player hands as mnemonic strings
@@ -58244,6 +58389,21 @@ class PokerGameIntegration {
58244
58389
  return { winners, results };
58245
58390
  }
58246
58391
  }
58392
+ PokerGameIntegration.RANK_WORDS = {
58393
+ 14: ["Ace", "Aces"],
58394
+ 13: ["King", "Kings"],
58395
+ 12: ["Queen", "Queens"],
58396
+ 11: ["Jack", "Jacks"],
58397
+ 10: ["Ten", "Tens"],
58398
+ 9: ["Nine", "Nines"],
58399
+ 8: ["Eight", "Eights"],
58400
+ 7: ["Seven", "Sevens"],
58401
+ 6: ["Six", "Sixes"],
58402
+ 5: ["Five", "Fives"],
58403
+ 4: ["Four", "Fours"],
58404
+ 3: ["Three", "Threes"],
58405
+ 2: ["Two", "Twos"]
58406
+ };
58247
58407
  // Example usage:
58248
58408
  /*
58249
58409
  const example = PokerGameIntegration.exampleShowdown([
@@ -71518,6 +71678,15 @@ function assertCreatableSngField(minPlayers, maxPlayers, sngConfig, nowSeconds =
71518
71678
  if (startTime !== undefined && startTime <= nowSeconds) {
71519
71679
  throw new Error(`sngConfig.startTime ${startTime} must be in the future (now ${nowSeconds}).`);
71520
71680
  }
71681
+ const levels = sngConfig?.lateRegistrationLevels;
71682
+ if (levels !== undefined) {
71683
+ if (!Number.isInteger(levels) || levels <= 0) {
71684
+ throw new Error(`sngConfig.lateRegistrationLevels must be a positive whole number of levels; got ${levels}.`);
71685
+ }
71686
+ if (!startTime) {
71687
+ throw new Error("sngConfig.lateRegistrationLevels needs sngConfig.startTime (late registration is for a scheduled sit-and-go).");
71688
+ }
71689
+ }
71521
71690
  }
71522
71691
  /**
71523
71692
  * Signing Cosmos Client that extends the read-only CosmosClient with transaction capabilities
@@ -71694,6 +71863,7 @@ class SigningCosmosClient extends CosmosClient {
71694
71863
  // Blind structure (block52/pokerchain#434) as JSON; "" = doubling, and
71695
71864
  // an empty proto3 string is not encoded at all.
71696
71865
  blindStructure: sngConfig?.blindStructure ? JSON.stringify(sngConfig.blindStructure) : "",
71866
+ lateRegistrationLevels: sngConfig?.lateRegistrationLevels ?? 0,
71697
71867
  });
71698
71868
  // Create the transaction message
71699
71869
  const msg = {
@@ -71724,7 +71894,8 @@ class SigningCosmosClient extends CosmosClient {
71724
71894
  startingStack: sngConfig.startingStack.toString(),
71725
71895
  blindLevelDuration: sngConfig.blindLevelDuration,
71726
71896
  entryFee: sngConfig.entryFee?.toString() ?? "0",
71727
- ...(sngConfig.blindStructure && { blindStructure: sngConfig.blindStructure })
71897
+ ...(sngConfig.blindStructure && { blindStructure: sngConfig.blindStructure }),
71898
+ ...(sngConfig.lateRegistrationLevels && { lateRegistrationLevels: sngConfig.lateRegistrationLevels })
71728
71899
  })
71729
71900
  });
71730
71901
  try {
@@ -72695,11 +72866,13 @@ exports.hasAction = hasAction;
72695
72866
  exports.holeCardsPerPlayer = holeCardsPerPlayer;
72696
72867
  exports.isCashFormat = isCashFormat;
72697
72868
  exports.isEmptyAddress = isEmptyAddress;
72869
+ exports.isLateRegistrationOpen = isLateRegistrationOpen;
72698
72870
  exports.isPotLimit = isPotLimit;
72699
72871
  exports.isSitAndGoFormat = isSitAndGoFormat;
72700
72872
  exports.isTournamentFormat = isTournamentFormat;
72701
72873
  exports.isValidMnemonic = isValidMnemonic;
72702
72874
  exports.isValidPlayerAddress = isValidPlayerAddress;
72875
+ exports.lateRegistrationClosesAt = lateRegistrationClosesAt;
72703
72876
  exports.parseBlindStructure = parseBlindStructure;
72704
72877
  exports.parseGameFormat = parseGameFormat;
72705
72878
  exports.parseGameVariant = parseGameVariant;