texas-poker-core 1.3.0 → 1.3.2

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/README.md CHANGED
@@ -391,4 +391,9 @@ bufix
391
391
  ## 1.2.9
392
392
  使用枚举值重构action&stage; 调整presentation的计算方式, 增加转换Int的方法, 便于以后数据库索引
393
393
 
394
- ## 1.3.0
394
+ ## 1.3.0
395
+
396
+ ## 1.3.1
397
+ 重命名不合理的变量名称, 以防后期使用使混淆
398
+ ## 1.3.2
399
+ 新增角色枚举
@@ -146,15 +146,15 @@ var Controller = /*#__PURE__*/function () {
146
146
  var _classPrivateFieldGet4;
147
147
  this.end();
148
148
  _classPrivateFieldSet(_endAt, this, this.stage);
149
- var _classPrivateFieldGet3 = _classPrivateFieldGet(_dealer, this).deck.getMaxPresentationAndPokes(),
150
- presentation = _classPrivateFieldGet3.presentation,
149
+ var _classPrivateFieldGet3 = _classPrivateFieldGet(_dealer, this).deck.getMaxRankSignatureAndPokes(),
150
+ rankSignature = _classPrivateFieldGet3.rankSignature,
151
151
  pokes = _classPrivateFieldGet3.pokes;
152
152
  (_classPrivateFieldGet4 = _classPrivateFieldGet(_callbackOfEnd, this)) === null || _classPrivateFieldGet4 === void 0 || _classPrivateFieldGet4.call(this, {
153
153
  showHandPokes: true,
154
154
  currentStage: _classPrivateFieldGet(_stage, this),
155
155
  restCommonPokes: this.getCommonPokes(_classPrivateFieldGet(_stage, this), StageEnum.RIVER),
156
156
  maxPokes: pokes,
157
- maxPresentation: presentation[0]
157
+ maxRankCategory: rankSignature[0]
158
158
  });
159
159
  console.log('游戏结束(shouldEndGame):', _classPrivateFieldGet(_endAt, this));
160
160
  return true;
@@ -8,6 +8,7 @@ exports.default = void 0;
8
8
  var _Deck = _interopRequireDefault(require("../Deck"));
9
9
  var _TexasError = _interopRequireDefault(require("../TexasError"));
10
10
  var _utils = require("../utils");
11
+ var _Player = require("../Player");
11
12
  var _constant = require("../Player/constant");
12
13
  var _core = require("../Deck/core");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -121,43 +122,55 @@ var Dealer = /*#__PURE__*/function () {
121
122
  }
122
123
  _classPrivateFieldGet(_actionsHistory, this).push(player);
123
124
  }
125
+ /**
126
+ * @description 获取场上最大的牌力签名(用于比较/展示)
127
+ */
124
128
  }, {
125
- key: "getMaxHandTypeCategory",
126
- value: function getMaxHandTypeCategory() {
127
- var _this$filter$map$sort = this.filter(function (player) {
129
+ key: "getMaxRankSignature",
130
+ value: function getMaxRankSignature() {
131
+ var _this$filter$map$filt = this.filter(function (player) {
128
132
  return player.getStatus() !== 'out';
129
133
  }).map(function (player) {
130
- return player.getPresentation();
131
- }).sort(_core.comparePresentation),
132
- _this$filter$map$sort2 = _slicedToArray(_this$filter$map$sort, 1),
133
- max = _this$filter$map$sort2[0];
134
- return max[0];
134
+ return player.rankSignature;
135
+ }).filter(Boolean).sort(function (a, b) {
136
+ return (0, _core.compareRankSignature)(a, b);
137
+ }),
138
+ _this$filter$map$filt2 = _slicedToArray(_this$filter$map$filt, 1),
139
+ max = _this$filter$map$filt2[0];
140
+ return max;
141
+ }
142
+ /**
143
+ * @description 获取最大牌型 category(首字符)
144
+ */
145
+ }, {
146
+ key: "getMaxRankCategory",
147
+ value: function getMaxRankCategory() {
148
+ var maxRankSig = this.getMaxRankSignature();
149
+ return maxRankSig[0];
135
150
  }
136
151
 
137
- // 获取所有的最大牌型
152
+ /** 获取场上最大的牌型组合(可能多玩家并列) */
138
153
  }, {
139
- key: "getMaxPokes",
140
- value: function getMaxPokes() {
141
- var _this = this;
142
- // getBestHand()
143
- var result = this.filter(function (player) {
154
+ key: "getTableBestFiveCards",
155
+ value: function getTableBestFiveCards() {
156
+ var maxRankStrength = Math.max.apply(Math, _toConsumableArray(this.map(function (player) {
157
+ return player.rankStrength;
158
+ })));
159
+ return this.filter(function (player) {
144
160
  return player.getStatus() !== 'out';
145
- }).map(function (player) {
146
- var pokes = (0, _core.getBestHand)(player.getHandPokes(), _classPrivateFieldGet(_deck, _this).getPokes().commonPokes);
161
+ }).map(function (_ref) {
162
+ var rankStrength = _ref.rankStrength,
163
+ bestFiveCards = _ref.bestFiveCards;
147
164
  return {
148
- presentation: (0, _core.getHandPresentation)(pokes),
149
- pokes: pokes
165
+ rankStrength: rankStrength,
166
+ bestFiveCards: bestFiveCards
150
167
  };
151
- });
152
- var _result$sort = result.sort(function (a, b) {
153
- return (0, _core.comparePresentation)(a.presentation, b.presentation);
154
- }),
155
- _result$sort2 = _slicedToArray(_result$sort, 1),
156
- max = _result$sort2[0];
157
- return result.filter(function (item) {
158
- return item.presentation === max.presentation;
168
+ }).filter(function (_ref2) {
169
+ var rankStrength = _ref2.rankStrength,
170
+ bestFiveCards = _ref2.bestFiveCards;
171
+ return rankStrength === maxRankStrength && !!bestFiveCards;
159
172
  }).map(function (item) {
160
- return item.pokes;
173
+ return item.bestFiveCards;
161
174
  });
162
175
  }
163
176
  }, {
@@ -180,9 +193,15 @@ var Dealer = /*#__PURE__*/function () {
180
193
  }, {
181
194
  key: "settle",
182
195
  value: function settle() {
183
- var _this2 = this;
196
+ var _this = this;
184
197
  this.forEach(function (player) {
185
- player.setPresentation((0, _core.getHandPresentation)((0, _core.getBestHand)(player.getHandPokes(), _classPrivateFieldGet(_deck, _this2).getPokes().commonPokes)));
198
+ if (_classPrivateFieldGet(_deck, _this).getPokes().commonPokes.length === 0) return;
199
+ var bestFiveCards = (0, _core.getBestFiveCards)(player.getHandPokes(), _classPrivateFieldGet(_deck, _this).getPokes().commonPokes);
200
+
201
+ // 存储最大五张牌, 防止后续重复计算
202
+ player.bestFiveCards = bestFiveCards;
203
+ player.rankSignature = (0, _core.getFiveCardsRankSignature)(bestFiveCards);
204
+ player.rankStrength = (0, _core.getStrengthFromRankSignature)(player.rankSignature);
186
205
  });
187
206
  console.log('底牌:', (0, _core.formatterPoke)(_classPrivateFieldGet(_deck, this).getPokes().commonPokes));
188
207
  }
@@ -302,9 +321,9 @@ var Dealer = /*#__PURE__*/function () {
302
321
  }, {
303
322
  key: "setButton",
304
323
  value: function setButton(player) {
305
- var _this3 = this;
324
+ var _this2 = this;
306
325
  if (player) {
307
- player.setRole('button');
326
+ player.setRole(_Player.RoleEnum.BTN);
308
327
  _classPrivateFieldSet(_button, this, player);
309
328
  return;
310
329
  }
@@ -316,8 +335,8 @@ var Dealer = /*#__PURE__*/function () {
316
335
  var random = (0, _utils.getRandomInt)(0, count - 1);
317
336
  this.forEach(function (p, i) {
318
337
  if (i === random) {
319
- p.setRole('button');
320
- _classPrivateFieldSet(_button, _this3, p);
338
+ p.setRole(_Player.RoleEnum.BTN);
339
+ _classPrivateFieldSet(_button, _this2, p);
321
340
  }
322
341
  });
323
342
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.suitsMap = exports.suits = exports.ranks = exports.rankMap = exports.handTypeCategoryMap = exports.comboIndices = void 0;
6
+ exports.suitsMap = exports.suits = exports.ranks = exports.rankMap = exports.rankCategoryMap = exports.comboIndices = void 0;
7
7
  var suits = exports.suits = ['h', 's', 'd', 'c'];
8
8
  var ranks = exports.ranks = ['2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k', 'a'];
9
9
 
@@ -21,13 +21,13 @@ var ranks = exports.ranks = ['2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', '
21
21
  */
22
22
 
23
23
  /**
24
- * 2 + 3 一共5张牌的组合
24
+ * 2张手牌
25
25
  */
26
26
 
27
- /** 牌型枚举 */
27
+ /** 牌型枚举(五张牌型的类型:高牌/一对/顺子…) */
28
28
 
29
29
  /**
30
- * 牌力展示:首字符为牌型 (handTypeCategory),后接可选数字段,如 "z" | "q14+13+12+11+9" | "w13+r7"
30
+ * 牌力签名:首字符为牌型 (RankCategory),后接可选数字段,如 "z" | "q14+13+12+11+9" | "w13+r7"
31
31
  */
32
32
 
33
33
  /**
@@ -39,7 +39,7 @@ var suitsMap = exports.suitsMap = new Map([
39
39
  */
40
40
  ['h', '♥'], ['s', '♠'], ['d', '♦️'], ['c', '♣']]);
41
41
  // 牌型枚举中文映射
42
- var handTypeCategoryMap = exports.handTypeCategoryMap = new Map([['z', '皇家同花顺'], ['y', '同花顺'], ['x', '四条'], ['w', '葫芦'], ['v', '同花'], ['u', '顺子'], ['t', '三条'], ['s', '两对'], ['r', '一对'], ['q', '高牌']]);
42
+ var rankCategoryMap = exports.rankCategoryMap = new Map([['z', '皇家同花顺'], ['y', '同花顺'], ['x', '四条'], ['w', '葫芦'], ['v', '同花'], ['u', '顺子'], ['t', '三条'], ['s', '两对'], ['r', '一对'], ['q', '高牌']]);
43
43
 
44
44
  // 牌面值的大小映射 2~A => 2~14
45
45
  var rankMap = exports.rankMap = function rankMap(input) {
package/dist/Deck/core.js CHANGED
@@ -3,14 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.formatterPoke = exports.comparePresentation = exports.compareFn = void 0;
7
- exports.getBestHand = getBestHand;
8
- exports.getBestPokesPresentation = getBestPokesPresentation;
9
- exports.getHandPresentation = getHandPresentation;
10
- exports.getHandStrengthInt = getHandStrengthInt;
11
- exports.getHandStrengthIntFromPresentation = getHandStrengthIntFromPresentation;
12
- exports.getMaxPresentationAndPokes = getMaxPresentationAndPokes;
6
+ exports.formatterPoke = exports.compareRankSignature = exports.compareFn = void 0;
7
+ exports.getBestFiveCards = getBestFiveCards;
8
+ exports.getBestPokesRankSignature = getBestPokesRankSignature;
9
+ exports.getFiveCardsRankSignature = getFiveCardsRankSignature;
10
+ exports.getFiveCardsStrength = getFiveCardsStrength;
11
+ exports.getMaxRankSignatureAndPokes = getMaxRankSignatureAndPokes;
13
12
  exports.getSortedAllHandPokesCombinations = getSortedAllHandPokesCombinations;
13
+ exports.getStrengthFromRankSignature = getStrengthFromRankSignature;
14
14
  exports.isStraight = exports.getWinners = void 0;
15
15
  var _ramda = require("ramda");
16
16
  var _constant = require("./constant");
@@ -65,9 +65,9 @@ function formatRanksDesc(ranks) {
65
65
  }).map(_constant.rankMap).join('+');
66
66
  }
67
67
 
68
- /** 从 presentation 中解析出 rank 数字数组(首段去掉类型字母,其余段为纯数字或 "r"+数字) */
69
- function parseRankNumbersFromPresentation(presentation) {
70
- var rest = presentation.slice(1);
68
+ /** 从 rankSignature 中解析出 rank 数字数组(首段去掉类型字母,其余段为纯数字或 "r"+数字) */
69
+ function parseRankNumbersFromRankSignature(rankSignature) {
70
+ var rest = rankSignature.slice(1);
71
71
  if (!rest) return [];
72
72
  return rest.split('+').map(function (segment) {
73
73
  var numPart = /^[a-z]\d*$/i.test(segment) ? segment.slice(1) : segment;
@@ -88,8 +88,8 @@ function getCombinations(pokes) {
88
88
  });
89
89
  }
90
90
  var compareFnOfSameType = function compareFnOfSameType(a, b) {
91
- var ranks1 = parseRankNumbersFromPresentation(a);
92
- var ranks2 = parseRankNumbersFromPresentation(b);
91
+ var ranks1 = parseRankNumbersFromRankSignature(a);
92
+ var ranks2 = parseRankNumbersFromRankSignature(b);
93
93
  var len = Math.max(ranks1.length, ranks2.length);
94
94
  for (var i = 0; i < len; i++) {
95
95
  var _ranks1$i, _ranks2$i;
@@ -107,13 +107,12 @@ var compareFnOfSameType = function compareFnOfSameType(a, b) {
107
107
  * @returns
108
108
  */
109
109
  var compareFn = exports.compareFn = function compareFn(a, b) {
110
- // 'q13' 'w3+r2'
111
- var _ref = [getHandPresentation(a), getHandPresentation(b)],
112
- presentationA = _ref[0],
113
- presentationB = _ref[1];
114
- return comparePresentation(presentationA, presentationB);
110
+ var _ref = [getFiveCardsRankSignature(a), getFiveCardsRankSignature(b)],
111
+ rankSigA = _ref[0],
112
+ rankSigB = _ref[1];
113
+ return compareRankSignature(rankSigA, rankSigB);
115
114
  };
116
- var comparePresentation = exports.comparePresentation = function comparePresentation(p1, p2) {
115
+ var compareRankSignature = exports.compareRankSignature = function compareRankSignature(p1, p2) {
117
116
  var _ref2 = [p1[0], p2[0]],
118
117
  typeA = _ref2[0],
119
118
  typeB = _ref2[1];
@@ -127,8 +126,8 @@ var comparePresentation = exports.comparePresentation = function comparePresenta
127
126
  return typeA > typeB ? -1 : 1;
128
127
  };
129
128
 
130
- /** 牌型字符到可排序整数的映射,与 comparePresentation 顺序一致:大即强 */
131
- var HAND_TYPE_ORDER = {
129
+ /** 牌型字符到可排序整数的映射,与 compareRankSignature 顺序一致:大即强 */
130
+ var RANK_CATEGORY_ORDER = {
132
131
  q: 0,
133
132
  r: 1,
134
133
  s: 2,
@@ -147,14 +146,14 @@ var RANK_BASE = 16;
147
146
  var TYPE_MULTIPLIER = 1000000;
148
147
 
149
148
  /**
150
- * getHandPresentation 的字符串解析为可排序的整数
151
- * 保证:comparePresentation(a, b) === -1 => getHandStrengthIntFromPresentation(a) < getHandStrengthIntFromPresentation(b)
149
+ * 将五张组合牌的 rankSignature 解析为可排序的整数
150
+ * 保证:compareRankSignature(a, b) === -1 => getStrengthFromRankSignature(a) < getStrengthFromRankSignature(b)
152
151
  */
153
- function getHandStrengthIntFromPresentation(presentation) {
154
- var _HAND_TYPE_ORDER$type;
155
- var typeChar = presentation[0];
156
- var typeIndex = (_HAND_TYPE_ORDER$type = HAND_TYPE_ORDER[typeChar]) !== null && _HAND_TYPE_ORDER$type !== void 0 ? _HAND_TYPE_ORDER$type : 0;
157
- var rankNumbers = parseRankNumbersFromPresentation(presentation);
152
+ function getStrengthFromRankSignature(rankSignature) {
153
+ var _RANK_CATEGORY_ORDER$;
154
+ var typeChar = rankSignature[0];
155
+ var typeIndex = (_RANK_CATEGORY_ORDER$ = RANK_CATEGORY_ORDER[typeChar]) !== null && _RANK_CATEGORY_ORDER$ !== void 0 ? _RANK_CATEGORY_ORDER$ : 0;
156
+ var rankNumbers = parseRankNumbersFromRankSignature(rankSignature);
158
157
  var payload = rankNumbers.reduce(function (sum, r, i) {
159
158
  return sum + r * Math.pow(RANK_BASE, rankNumbers.length - 1 - i);
160
159
  }, 0);
@@ -162,19 +161,19 @@ function getHandStrengthIntFromPresentation(presentation) {
162
161
  }
163
162
 
164
163
  /**
165
- * 5 张牌编码为可排序的整数,便于数据库存储与 ORDER BY 比较
166
- * 牌力越大数值越大,可直接用于 ORDER BY hand_strength DESC 取最强牌
164
+ * 获取五张组合牌型的强度(可排序整数),便于数据库存储与 ORDER BY 比较
165
+ * 牌力越大数值越大,可直接用于 ORDER BY 取最强牌
167
166
  */
168
- function getHandStrengthInt(input) {
169
- return getHandStrengthIntFromPresentation(getHandPresentation(input));
167
+ function getFiveCardsStrength(input) {
168
+ return getStrengthFromRankSignature(getFiveCardsRankSignature(input));
170
169
  }
171
170
 
172
171
  /**
173
- * @description 计算牌力大小
174
- * @param input
175
- * @returns
172
+ * 获取五张组合牌的唯一标识(牌力签名:类型 + 牌面细节)
173
+ * @param input 五张组合牌(5 张 Poke)
174
+ * @returns rankSignature
176
175
  */
177
- function getHandPresentation(input) {
176
+ function getFiveCardsRankSignature(input) {
178
177
  // return
179
178
  var suits = input.map(function (poke) {
180
179
  return poke[0];
@@ -269,23 +268,22 @@ function getHandPresentation(input) {
269
268
  }
270
269
 
271
270
  /**
272
- * @description 根据底牌和手牌, 计算出最大的牌力组合
273
- * @param handPokes
274
- * @param commonPokes
275
- * @returns
271
+ * 2 张手牌与 5 张底牌中,选出牌力最大的 5 张牌型;。
272
+ * @param handPokes 手牌(如 2 张)
273
+ * @param commonPokes 底牌/公共牌(如 5 张)
276
274
  */
277
- function getBestHand(pokes, commonPokes) {
278
- var _getCombinations$sort = getCombinations(pokes.concat(commonPokes)).sort(compareFn),
275
+ function getBestFiveCards(handPokes, commonPokes) {
276
+ if (commonPokes.length === 0) throw new Error('底牌数量不足, 无法组合出最大5张牌型');
277
+ var _getCombinations$sort = getCombinations(handPokes.concat(commonPokes)).sort(compareFn),
279
278
  _getCombinations$sort2 = _slicedToArray(_getCombinations$sort, 1),
280
279
  maxOne = _getCombinations$sort2[0];
281
280
  return maxOne;
282
281
  }
283
282
 
284
283
  /**
285
- * @description 获取多个手牌组合中的所有牌型组合, 按照降序排列
286
- * @param handPokes
287
- * @param commonPokes
288
- * @returns
284
+ * 获取多组手牌与公共牌组合后的所有五张牌型,按牌力降序排列
285
+ * @param handPokes 各玩家手牌(每组 2 张)
286
+ * @param commonPokes 公共牌
289
287
  */
290
288
  function getSortedAllHandPokesCombinations(handPokes, commonPokes) {
291
289
  var allCombinations = handPokes.map(function (pokes) {
@@ -294,36 +292,33 @@ function getSortedAllHandPokesCombinations(handPokes, commonPokes) {
294
292
  return allCombinations;
295
293
  }
296
294
  /**
297
- * @description 获取多个手牌组合中的最大牌力值
298
- * @param handPokes
299
- * @param commonPokes
300
- * @returns
295
+ * 获取多组手牌与公共牌组合中的最大牌型签名
296
+ * @param handPokes 各玩家手牌
297
+ * @param commonPokes 公共牌
301
298
  */
302
- function getBestPokesPresentation(handPokes, commonPokes) {
299
+ function getBestPokesRankSignature(handPokes, commonPokes) {
303
300
  var _getSortedAllHandPoke = getSortedAllHandPokesCombinations(handPokes, commonPokes),
304
301
  _getSortedAllHandPoke2 = _slicedToArray(_getSortedAllHandPoke, 1),
305
302
  maxOne = _getSortedAllHandPoke2[0];
306
- return getHandPresentation(maxOne);
303
+ return getFiveCardsRankSignature(maxOne);
307
304
  }
308
305
 
309
- // 获取最大牌型与牌力值
310
- function getMaxPresentationAndPokes(handPokes, commonPokes) {
306
+ /** 获取多组手牌与公共牌组合中的最大牌型签名及其对应的五张牌 */
307
+ function getMaxRankSignatureAndPokes(handPokes, commonPokes) {
311
308
  var allCombinations = getSortedAllHandPokesCombinations(handPokes, commonPokes);
312
- var maxPresentation = getHandPresentation(allCombinations[0]);
313
-
314
- // 以下方法可以使用reduce实现, 在目前不影响性能的情况下, 先这样实现
309
+ var maxRankSignature = getFiveCardsRankSignature(allCombinations[0]);
315
310
  var maxPokes = allCombinations.map(function (combination) {
316
311
  return {
317
- presentation: getHandPresentation(combination),
312
+ rankSignature: getFiveCardsRankSignature(combination),
318
313
  pokes: combination
319
314
  };
320
315
  }).filter(function (item) {
321
- return item.presentation === maxPresentation;
316
+ return item.rankSignature === maxRankSignature;
322
317
  }).map(function (item) {
323
318
  return item.pokes;
324
319
  });
325
320
  return {
326
- presentation: maxPresentation,
321
+ rankSignature: maxRankSignature,
327
322
  pokes: maxPokes
328
323
  };
329
324
  }
@@ -339,20 +334,18 @@ var formatterPoke = exports.formatterPoke = function formatterPoke(input) {
339
334
  };
340
335
 
341
336
  /**
342
- * @description 根据玩家presentation, 计算出赢家
337
+ * @description 根据玩家 rankStrength 计算出赢家
343
338
  */
344
339
  var getWinners = exports.getWinners = function getWinners(players) {
345
340
  if (players.some(function (p) {
346
- return !p.getPresentation();
341
+ return !p.rankSignature;
347
342
  })) throw new Error('未计算玩家手牌大小,无法比较');
348
- var _filter$sort = _toConsumableArray(players).filter(function (player) {
349
- return player.getStatus() !== 'out';
350
- }).sort(function (a, b) {
351
- return comparePresentation(a.getPresentation(), b.getPresentation());
352
- }),
353
- _filter$sort2 = _slicedToArray(_filter$sort, 1),
354
- max = _filter$sort2[0];
343
+ var maxRankStrength = Math.max.apply(Math, _toConsumableArray(players.filter(function (player) {
344
+ return player.getStatus() !== 'out';
345
+ }).map(function (player) {
346
+ return player.rankStrength;
347
+ })));
355
348
  return players.filter(function (p) {
356
- return p.getPresentation() === max.getPresentation();
349
+ return p.rankStrength === maxRankStrength;
357
350
  });
358
351
  };
@@ -37,7 +37,7 @@ var Deck = /*#__PURE__*/function () {
37
37
  _classPrivateMethodInitSpec(this, _Deck_brand);
38
38
  _classPrivateFieldInitSpec(this, _deck, []);
39
39
  /**
40
- * 玩家的手牌
40
+ * 各玩家的手牌(每人 2 张)
41
41
  */
42
42
  _classPrivateFieldInitSpec(this, _handPokes, []);
43
43
  /**
@@ -122,22 +122,20 @@ var Deck = /*#__PURE__*/function () {
122
122
  return _classPrivateFieldGet(_deck, this);
123
123
  }
124
124
  }, {
125
- key: "getMaxPresentation",
126
- value: function getMaxPresentation() {
127
- var presentation = (0, _core.getBestPokesPresentation)(_classPrivateFieldGet(_handPokes, this), _classPrivateFieldGet(_commonPokes, this));
128
- return presentation[0];
125
+ key: "getMaxRankCategory",
126
+ value: function getMaxRankCategory() {
127
+ var rankSignature = (0, _core.getBestPokesRankSignature)(_classPrivateFieldGet(_handPokes, this), _classPrivateFieldGet(_commonPokes, this));
128
+ return rankSignature[0];
129
129
  }
130
130
  }, {
131
131
  key: "getMaxPokeCombinations",
132
132
  value: function getMaxPokeCombinations() {
133
- return (0, _core.getMaxPresentationAndPokes)(_classPrivateFieldGet(_handPokes, this), _classPrivateFieldGet(_commonPokes, this)).pokes;
133
+ return (0, _core.getMaxRankSignatureAndPokes)(_classPrivateFieldGet(_handPokes, this), _classPrivateFieldGet(_commonPokes, this)).pokes;
134
134
  }
135
-
136
- // 该方法是getMaxPokeCombinations&getMaxPresentation的组合
137
135
  }, {
138
- key: "getMaxPresentationAndPokes",
139
- value: function getMaxPresentationAndPokes() {
140
- return (0, _core.getMaxPresentationAndPokes)(_classPrivateFieldGet(_handPokes, this), _classPrivateFieldGet(_commonPokes, this));
136
+ key: "getMaxRankSignatureAndPokes",
137
+ value: function getMaxRankSignatureAndPokes() {
138
+ return (0, _core.getMaxRankSignatureAndPokes)(_classPrivateFieldGet(_handPokes, this), _classPrivateFieldGet(_commonPokes, this));
141
139
  }
142
140
  }]);
143
141
  }();
@@ -3,22 +3,46 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.roleMap = exports.playerRoleSetMap = exports.ActionTypeMap = exports.ActionTypeEnum = void 0;
6
+ exports.roleMap = exports.playerRoleSetMap = exports.RoleEnum = exports.ActionTypeMap = exports.ActionTypeEnum = void 0;
7
7
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
8
8
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
9
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
10
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
11
11
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
12
12
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
- var twoPlayer = ['button', 'big-blind'];
14
- var threePlayer = ['button', 'small-blind', 'big-blind'];
15
- var fourPlayer = threePlayer.concat('under-the-gun');
16
- var fivePlayer = fourPlayer.concat('middle-position');
17
- var sixPlayer = fivePlayer.concat('cut-off');
18
- var sevenPlayer = [].concat(_toConsumableArray(sixPlayer.slice(0, -1)), ['hi-jack'], _toConsumableArray(sixPlayer.slice(-1)));
19
- var eightPlayer = [].concat(_toConsumableArray(sevenPlayer.slice(0, 5)), ['middle-position1'], _toConsumableArray(sevenPlayer.slice(5)));
20
- var ninePlayer = [].concat(_toConsumableArray(eightPlayer.slice(0, 4)), ['under-the-gun1'], _toConsumableArray(eightPlayer.slice(4)));
21
- var tenPlayer = [].concat(_toConsumableArray(ninePlayer.slice(0, 5)), ['under-the-gun2'], _toConsumableArray(ninePlayer.slice(5)));
13
+ /** 座位角色枚举 */
14
+ var RoleEnum = exports.RoleEnum = /*#__PURE__*/function (RoleEnum) {
15
+ /** 庄家/按钮 */
16
+ RoleEnum["BTN"] = "btn";
17
+ /** 小盲 */
18
+ RoleEnum["SB"] = "sb";
19
+ /** 大盲 */
20
+ RoleEnum["BB"] = "bb";
21
+ /** 枪口 */
22
+ RoleEnum["UTG"] = "utg";
23
+ /** 枪口+1 */
24
+ RoleEnum["UTG1"] = "utg1";
25
+ /** 枪口+2(10 人桌) */
26
+ RoleEnum["UTG2"] = "utg2";
27
+ /** 中位 */
28
+ RoleEnum["MP"] = "mp";
29
+ /** Lojack(10 人桌) */
30
+ RoleEnum["LJ"] = "lj";
31
+ /** 劫持位 */
32
+ RoleEnum["HJ"] = "hj";
33
+ /** 关煞位 */
34
+ RoleEnum["CO"] = "co";
35
+ return RoleEnum;
36
+ }({});
37
+ var twoPlayer = [RoleEnum.BTN, RoleEnum.BB];
38
+ var threePlayer = [RoleEnum.BTN, RoleEnum.SB, RoleEnum.BB];
39
+ var fourPlayer = threePlayer.concat(RoleEnum.UTG);
40
+ var fivePlayer = fourPlayer.concat(RoleEnum.MP);
41
+ var sixPlayer = fivePlayer.concat(RoleEnum.CO);
42
+ var sevenPlayer = [].concat(_toConsumableArray(sixPlayer.slice(0, -1)), [RoleEnum.HJ], _toConsumableArray(sixPlayer.slice(-1)));
43
+ var eightPlayer = [].concat(_toConsumableArray(sevenPlayer.slice(0, 5)), [RoleEnum.LJ], _toConsumableArray(sevenPlayer.slice(5)));
44
+ var ninePlayer = [].concat(_toConsumableArray(eightPlayer.slice(0, 4)), [RoleEnum.UTG1], _toConsumableArray(eightPlayer.slice(4)));
45
+ var tenPlayer = [].concat(_toConsumableArray(ninePlayer.slice(0, 5)), [RoleEnum.UTG2], _toConsumableArray(ninePlayer.slice(5)));
22
46
  var ActionTypeEnum = exports.ActionTypeEnum = /*#__PURE__*/function (ActionTypeEnum) {
23
47
  ActionTypeEnum["CALL"] = "call";
24
48
  ActionTypeEnum["CHECK"] = "check";
@@ -29,5 +53,5 @@ var ActionTypeEnum = exports.ActionTypeEnum = /*#__PURE__*/function (ActionTypeE
29
53
  return ActionTypeEnum;
30
54
  }({});
31
55
  var ActionTypeMap = exports.ActionTypeMap = new Map([[ActionTypeEnum.CALL, '跟注'], [ActionTypeEnum.CHECK, '过牌'], [ActionTypeEnum.FOLD, '弃牌'], [ActionTypeEnum.RAISE, '加注'], [ActionTypeEnum.ALL_IN, 'All In'], [ActionTypeEnum.BET, '下注']]);
32
- var roleMap = exports.roleMap = new Map([['button', '庄家'], ['small-blind', '小盲'], ['big-blind', '大盲'], ['middle-position', '中位'], ['middle-position1', '中位+1'], ['middle-position2', '中位+2'], ['under-the-gun', '枪口'], ['under-the-gun1', '枪口+1'], ['under-the-gun2', '枪口+2'], ['hi-jack', '高劫持'], ['cut-off', '关煞']]);
33
- var playerRoleSetMap = exports.playerRoleSetMap = new Map([[1, ['button']], [2, twoPlayer], [3, threePlayer], [4, fourPlayer], [5, fivePlayer], [6, sixPlayer], [7, sevenPlayer], [8, eightPlayer], [9, ninePlayer], [10, tenPlayer]]);
56
+ var roleMap = exports.roleMap = new Map([[RoleEnum.BTN, '庄家'], [RoleEnum.SB, '小盲'], [RoleEnum.BB, '大盲'], [RoleEnum.UTG, '枪口'], [RoleEnum.UTG1, '枪口+1'], [RoleEnum.UTG2, '枪口+2'], [RoleEnum.MP, '中位'], [RoleEnum.LJ, 'Lojack'], [RoleEnum.HJ, '劫持位'], [RoleEnum.CO, '关煞']]);
57
+ var playerRoleSetMap = exports.playerRoleSetMap = new Map([[1, [RoleEnum.BTN]], [2, twoPlayer], [3, threePlayer], [4, fourPlayer], [5, fivePlayer], [6, sixPlayer], [7, sevenPlayer], [8, eightPlayer], [9, ninePlayer], [10, tenPlayer]]);
@@ -10,7 +10,14 @@ Object.defineProperty(exports, "ActionTypeEnum", {
10
10
  return _constant.ActionTypeEnum;
11
11
  }
12
12
  });
13
- exports.default = exports.Player = void 0;
13
+ exports.Player = void 0;
14
+ Object.defineProperty(exports, "RoleEnum", {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return _constant.RoleEnum;
18
+ }
19
+ });
20
+ exports.default = void 0;
14
21
  var _TexasError = _interopRequireDefault(require("../TexasError"));
15
22
  var _utils = require("../utils");
16
23
  var _config = require("../config");
@@ -38,9 +45,11 @@ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t),
38
45
  function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
39
46
  function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
40
47
  function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
41
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
42
- // 玩家的状态
48
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } // 玩家的状态
43
49
  // 玩家回合时采取的行动(使用枚举值作为类型)
50
+ /**
51
+ * 玩家
52
+ */
44
53
  var _role = /*#__PURE__*/new WeakMap();
45
54
  var _userInfo = /*#__PURE__*/new WeakMap();
46
55
  var _pool = /*#__PURE__*/new WeakMap();
@@ -59,13 +68,12 @@ var _lastPlayer = /*#__PURE__*/new WeakMap();
59
68
  var _nextPlayer = /*#__PURE__*/new WeakMap();
60
69
  var _timer = /*#__PURE__*/new WeakMap();
61
70
  var _handPokes = /*#__PURE__*/new WeakMap();
62
- var _presentation = /*#__PURE__*/new WeakMap();
71
+ var _bestFiveCards = /*#__PURE__*/new WeakMap();
72
+ var _rankSignature = /*#__PURE__*/new WeakMap();
73
+ var _rankStrength = /*#__PURE__*/new WeakMap();
63
74
  var _callback = /*#__PURE__*/new WeakMap();
64
75
  var _callbackOfAction = /*#__PURE__*/new WeakMap();
65
76
  var _Player_brand = /*#__PURE__*/new WeakSet();
66
- /**
67
- * 玩家
68
- */
69
77
  var Player = exports.Player = /*#__PURE__*/function () {
70
78
  function Player(_ref) {
71
79
  var lowestBetAmount = _ref.lowestBetAmount,
@@ -137,10 +145,15 @@ var Player = exports.Player = /*#__PURE__*/function () {
137
145
  _classPrivateFieldInitSpec(this, _nextPlayer, null);
138
146
  _classPrivateFieldInitSpec(this, _timer, null);
139
147
  /**
140
- * 玩家的手牌
148
+ * 玩家的手牌(2 张)
141
149
  */
142
150
  _classPrivateFieldInitSpec(this, _handPokes, []);
143
- _classPrivateFieldInitSpec(this, _presentation, void 0);
151
+ /**
152
+ * 与公共牌组合后的最佳五张牌(best 5-card combination)
153
+ */
154
+ _classPrivateFieldInitSpec(this, _bestFiveCards, undefined);
155
+ _classPrivateFieldInitSpec(this, _rankSignature, void 0);
156
+ _classPrivateFieldInitSpec(this, _rankStrength, 0);
144
157
  _classPrivateFieldInitSpec(this, _callback, void 0);
145
158
  /**
146
159
  * 用户采取行动
@@ -219,20 +232,26 @@ var Player = exports.Player = /*#__PURE__*/function () {
219
232
  function getRemainThinkTime() {
220
233
  return _classPrivateFieldGet(_thinkingTime, this) - _classPrivateFieldGet(_countDownTime, this);
221
234
  }
235
+ }, {
236
+ key: "bestFiveCards",
237
+ get: function get() {
238
+ return _classPrivateFieldGet(_bestFiveCards, this);
239
+ },
240
+ set: function set(value) {
241
+ _classPrivateFieldSet(_bestFiveCards, this, value);
242
+ }
222
243
  }, {
223
244
  key: "setNextPlayer",
224
245
  value: function setNextPlayer(player) {
225
246
  _classPrivateFieldSet(_nextPlayer, this, player);
226
247
  }
227
248
  }, {
228
- key: "setPresentation",
229
- value: function setPresentation(presentation) {
230
- _classPrivateFieldSet(_presentation, this, presentation);
231
- }
232
- }, {
233
- key: "getPresentation",
234
- value: function getPresentation() {
235
- return _classPrivateFieldGet(_presentation, this);
249
+ key: "rankSignature",
250
+ get: function get() {
251
+ return _classPrivateFieldGet(_rankSignature, this);
252
+ },
253
+ set: function set(value) {
254
+ _classPrivateFieldSet(_rankSignature, this, value);
236
255
  }
237
256
  }, {
238
257
  key: "getNextPlayer",
@@ -267,6 +286,14 @@ var Player = exports.Player = /*#__PURE__*/function () {
267
286
  set: function set(value) {
268
287
  _classPrivateFieldSet(_onlineStatus, this, value);
269
288
  }
289
+ }, {
290
+ key: "rankStrength",
291
+ get: function get() {
292
+ return _classPrivateFieldGet(_rankStrength, this);
293
+ },
294
+ set: function set(value) {
295
+ _classPrivateFieldSet(_rankStrength, this, value);
296
+ }
270
297
  }, {
271
298
  key: "onPreAction",
272
299
  value: function onPreAction(callback) {
@@ -279,7 +306,8 @@ var Player = exports.Player = /*#__PURE__*/function () {
279
306
  this.resetCurrentStageTotalAmount();
280
307
  _classPrivateFieldSet(_totalBetAmount, this, 0);
281
308
  _classPrivateFieldSet(_handPokes, this, []);
282
- _classPrivateFieldSet(_presentation, this, undefined);
309
+ _classPrivateFieldSet(_rankStrength, this, 0);
310
+ _classPrivateFieldSet(_rankSignature, this, undefined);
283
311
  _classPrivateFieldSet(_status, this, 'waiting');
284
312
  if (process.env.PROJECT_ENV === 'dev') this.balance = _classPrivateFieldGet(_userInfo, this).balance;
285
313
  this.clearTimer();
@@ -843,7 +871,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
843
871
  }();
844
872
  _Player = Player;
845
873
  function _isBigBlindOptionInPreFlop() {
846
- return _classPrivateFieldGet(_controller, this).stage === _Controller.StageEnum.PRE_FLOP && _classPrivateFieldGet(_role, this) === 'big-blind' && _classPrivateFieldGet(_currentStageTotalAmount, this) >= this.getMaxBetAmountAtCurrentStage();
874
+ return _classPrivateFieldGet(_controller, this).stage === _Controller.StageEnum.PRE_FLOP && _classPrivateFieldGet(_role, this) === _constant.RoleEnum.BB && _classPrivateFieldGet(_currentStageTotalAmount, this) >= this.getMaxBetAmountAtCurrentStage();
847
875
  }
848
876
  /**
849
877
  * @description 获取玩家允许的行动列表
@@ -169,7 +169,7 @@ var Pool = /*#__PURE__*/function () {
169
169
  this.calculate();
170
170
  console.log('玩家牌力大小:');
171
171
  _classPrivateFieldGet(_players, this).forEach(function (player) {
172
- console.log(player.getUserInfo().name, player.getPresentation(), (0, _core.formatterPoke)(player.getHandPokes()));
172
+ console.log(player.getUserInfo().name, player.rankSignature, (0, _core.formatterPoke)(player.getHandPokes()));
173
173
  });
174
174
  console.log('奖池:');
175
175
  console.log(Array.from(_classPrivateFieldGet(_pots, this).entries()).map(function (_ref) {
package/dist/index.js CHANGED
@@ -9,10 +9,10 @@ var _exportNames = {
9
9
  TexasError: true,
10
10
  Deck: true,
11
11
  formatterPoke: true,
12
- getBestPokesPresentation: true,
13
- comparePresentation: true,
14
- getHandStrengthInt: true,
15
- getHandStrengthIntFromPresentation: true,
12
+ getBestPokesRankSignature: true,
13
+ compareRankSignature: true,
14
+ getFiveCardsStrength: true,
15
+ getStrengthFromRankSignature: true,
16
16
  Dealer: true,
17
17
  stageMap: true,
18
18
  roleMap: true,
@@ -27,6 +27,7 @@ var _exportNames = {
27
27
  PlayerSeatStatus: true,
28
28
  User: true,
29
29
  Role: true,
30
+ RoleEnum: true,
30
31
  Action: true,
31
32
  ActionType: true,
32
33
  OnlineStatus: true,
@@ -99,6 +100,12 @@ Object.defineProperty(exports, "Role", {
99
100
  return _Player.Role;
100
101
  }
101
102
  });
103
+ Object.defineProperty(exports, "RoleEnum", {
104
+ enumerable: true,
105
+ get: function get() {
106
+ return _Player.RoleEnum;
107
+ }
108
+ });
102
109
  Object.defineProperty(exports, "Room", {
103
110
  enumerable: true,
104
111
  get: function get() {
@@ -147,10 +154,10 @@ Object.defineProperty(exports, "User", {
147
154
  return _Player.User;
148
155
  }
149
156
  });
150
- Object.defineProperty(exports, "comparePresentation", {
157
+ Object.defineProperty(exports, "compareRankSignature", {
151
158
  enumerable: true,
152
159
  get: function get() {
153
- return _core.comparePresentation;
160
+ return _core.compareRankSignature;
154
161
  }
155
162
  });
156
163
  Object.defineProperty(exports, "formatterPoke", {
@@ -159,22 +166,22 @@ Object.defineProperty(exports, "formatterPoke", {
159
166
  return _core.formatterPoke;
160
167
  }
161
168
  });
162
- Object.defineProperty(exports, "getBestPokesPresentation", {
169
+ Object.defineProperty(exports, "getBestPokesRankSignature", {
163
170
  enumerable: true,
164
171
  get: function get() {
165
- return _core.getBestPokesPresentation;
172
+ return _core.getBestPokesRankSignature;
166
173
  }
167
174
  });
168
- Object.defineProperty(exports, "getHandStrengthInt", {
175
+ Object.defineProperty(exports, "getFiveCardsStrength", {
169
176
  enumerable: true,
170
177
  get: function get() {
171
- return _core.getHandStrengthInt;
178
+ return _core.getFiveCardsStrength;
172
179
  }
173
180
  });
174
- Object.defineProperty(exports, "getHandStrengthIntFromPresentation", {
181
+ Object.defineProperty(exports, "getStrengthFromRankSignature", {
175
182
  enumerable: true,
176
183
  get: function get() {
177
- return _core.getHandStrengthIntFromPresentation;
184
+ return _core.getStrengthFromRankSignature;
178
185
  }
179
186
  });
180
187
  Object.defineProperty(exports, "roleMap", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "texas-poker-core",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "德州扑克核心功能",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -1,6 +1,6 @@
1
1
  import Dealer from '../Dealer';
2
2
  import { Player } from '../Player';
3
- import { Poke, handTypeCategory } from '../Deck/constant';
3
+ import { Poke, RankCategory } from '../Deck/constant';
4
4
  import { GameComponent, TexasErrorCallback } from '../Texas';
5
5
  export declare enum StageEnum {
6
6
  PRE_FLOP = "pre_flop",
@@ -14,7 +14,7 @@ export type CallbackOfGameEnd = (params: {
14
14
  currentStage: Stage;
15
15
  showHandPokes: boolean;
16
16
  maxPokes?: Poke[][];
17
- maxPresentation?: handTypeCategory;
17
+ maxRankCategory?: RankCategory;
18
18
  }) => void;
19
19
  export type CallbackOnNextStage = (params: {
20
20
  commonPokes: Poke[];
@@ -1,6 +1,6 @@
1
1
  import Deck from '../Deck';
2
2
  import { Player } from '../Player';
3
- import { handTypeCategory } from '../Deck/constant';
3
+ import { RankCategory } from '../Deck/constant';
4
4
  import { GameComponent, TexasErrorCallback } from '../Texas';
5
5
  /**
6
6
  * 荷官, 控制游戏进行
@@ -18,8 +18,16 @@ declare class Dealer implements GameComponent {
18
18
  get lowestBetAmount(): number;
19
19
  dealCards(): void;
20
20
  addAction(player: Player): void;
21
- getMaxHandTypeCategory(): handTypeCategory;
22
- getMaxPokes(): ("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[][];
21
+ /**
22
+ * @description 获取场上最大的牌力签名(用于比较/展示)
23
+ */
24
+ getMaxRankSignature(): `s${string}` | `t${string}` | `q${string}` | `z${string}` | `y${string}` | `x${string}` | `w${string}` | `v${string}` | `u${string}` | `r${string}`;
25
+ /**
26
+ * @description 获取最大牌型 category(首字符)
27
+ */
28
+ getMaxRankCategory(): RankCategory;
29
+ /** 获取场上最大的牌型组合(可能多玩家并列) */
30
+ getTableBestFiveCards(): (("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[] | undefined)[];
23
31
  logPlayers(): void;
24
32
  setRoles(): void;
25
33
  /**
@@ -13,19 +13,19 @@ export type Rank = (typeof ranks)[number];
13
13
  */
14
14
  export type Poke = `${Suit}${Rank}`;
15
15
  /**
16
- * 2 + 3 一共5张牌的组合
16
+ * 2张手牌
17
17
  */
18
18
  export type HandPoke = Poke[];
19
- /** 牌型枚举 */
20
- export type handTypeCategory = 'z' | 'y' | 'x' | 'w' | 'v' | 'u' | 't' | 's' | 'r' | 'q';
19
+ /** 牌型枚举(五张牌型的类型:高牌/一对/顺子…) */
20
+ export type RankCategory = 'z' | 'y' | 'x' | 'w' | 'v' | 'u' | 't' | 's' | 'r' | 'q';
21
21
  /**
22
- * 牌力展示:首字符为牌型 (handTypeCategory),后接可选数字段,如 "z" | "q14+13+12+11+9" | "w13+r7"
22
+ * 牌力签名:首字符为牌型 (RankCategory),后接可选数字段,如 "z" | "q14+13+12+11+9" | "w13+r7"
23
23
  */
24
- export type Presentation = `${handTypeCategory}${string}`;
24
+ export type RankSignature = `${RankCategory}${string}`;
25
25
  /**
26
26
  * 花色format map
27
27
  */
28
28
  export declare const suitsMap: Map<"h" | "s" | "d" | "c", string>;
29
- export declare const handTypeCategoryMap: Map<handTypeCategory, string>;
29
+ export declare const rankCategoryMap: Map<RankCategory, string>;
30
30
  export declare const rankMap: (input: Rank) => number;
31
31
  export declare const comboIndices: number[][];
@@ -1,5 +1,5 @@
1
1
  import { Player } from '../Player';
2
- import { Poke, Rank, Presentation } from './constant';
2
+ import { Poke, Rank, RankSignature } from './constant';
3
3
  /**
4
4
  * @description 判断是否为顺子, 并且返回最大顺子的值
5
5
  * @param values
@@ -16,46 +16,44 @@ export declare const isStraight: (values: Rank[]) => {
16
16
  * @returns
17
17
  */
18
18
  export declare const compareFn: (a: Poke[], b: Poke[]) => number;
19
- export declare const comparePresentation: (p1: string, p2: string) => number;
19
+ export declare const compareRankSignature: (p1: string, p2: string) => number;
20
20
  /**
21
- * getHandPresentation 的字符串解析为可排序的整数
22
- * 保证:comparePresentation(a, b) === -1 => getHandStrengthIntFromPresentation(a) < getHandStrengthIntFromPresentation(b)
21
+ * 将五张组合牌的 rankSignature 解析为可排序的整数
22
+ * 保证:compareRankSignature(a, b) === -1 => getStrengthFromRankSignature(a) < getStrengthFromRankSignature(b)
23
23
  */
24
- export declare function getHandStrengthIntFromPresentation(presentation: Presentation): number;
24
+ export declare function getStrengthFromRankSignature(rankSignature: RankSignature): number;
25
25
  /**
26
- * 5 张牌编码为可排序的整数,便于数据库存储与 ORDER BY 比较
27
- * 牌力越大数值越大,可直接用于 ORDER BY hand_strength DESC 取最强牌
26
+ * 获取五张组合牌型的强度(可排序整数),便于数据库存储与 ORDER BY 比较
27
+ * 牌力越大数值越大,可直接用于 ORDER BY 取最强牌
28
28
  */
29
- export declare function getHandStrengthInt(input: Poke[]): number;
29
+ export declare function getFiveCardsStrength(input: Poke[]): number;
30
30
  /**
31
- * @description 计算牌力大小
32
- * @param input
33
- * @returns
31
+ * 获取五张组合牌的唯一标识(牌力签名:类型 + 牌面细节)
32
+ * @param input 五张组合牌(5 张 Poke)
33
+ * @returns rankSignature
34
34
  */
35
- export declare function getHandPresentation(input: Poke[]): Presentation;
35
+ export declare function getFiveCardsRankSignature(input: Poke[]): RankSignature;
36
36
  /**
37
- * @description 根据底牌和手牌, 计算出最大的牌力组合
38
- * @param handPokes
39
- * @param commonPokes
40
- * @returns
37
+ * 2 张手牌与 5 张底牌中,选出牌力最大的 5 张牌型;。
38
+ * @param handPokes 手牌(如 2 张)
39
+ * @param commonPokes 底牌/公共牌(如 5 张)
41
40
  */
42
- export declare function getBestHand(pokes: Poke[], commonPokes: Poke[]): Poke[];
41
+ export declare function getBestFiveCards(handPokes: Poke[], commonPokes: Poke[]): Poke[];
43
42
  /**
44
- * @description 获取多个手牌组合中的所有牌型组合, 按照降序排列
45
- * @param handPokes
46
- * @param commonPokes
47
- * @returns
43
+ * 获取多组手牌与公共牌组合后的所有五张牌型,按牌力降序排列
44
+ * @param handPokes 各玩家手牌(每组 2 张)
45
+ * @param commonPokes 公共牌
48
46
  */
49
47
  export declare function getSortedAllHandPokesCombinations(handPokes: Poke[][], commonPokes: Poke[]): ("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[][];
50
48
  /**
51
- * @description 获取多个手牌组合中的最大牌力值
52
- * @param handPokes
53
- * @param commonPokes
54
- * @returns
49
+ * 获取多组手牌与公共牌组合中的最大牌型签名
50
+ * @param handPokes 各玩家手牌
51
+ * @param commonPokes 公共牌
55
52
  */
56
- export declare function getBestPokesPresentation(handPokes: Poke[][], commonPokes: Poke[]): `s${string}` | `t${string}` | `q${string}` | `z${string}` | `y${string}` | `x${string}` | `w${string}` | `v${string}` | `u${string}` | `r${string}`;
57
- export declare function getMaxPresentationAndPokes(handPokes: Poke[][], commonPokes: Poke[]): {
58
- presentation: `s${string}` | `t${string}` | `q${string}` | `z${string}` | `y${string}` | `x${string}` | `w${string}` | `v${string}` | `u${string}` | `r${string}`;
53
+ export declare function getBestPokesRankSignature(handPokes: Poke[][], commonPokes: Poke[]): `s${string}` | `t${string}` | `q${string}` | `z${string}` | `y${string}` | `x${string}` | `w${string}` | `v${string}` | `u${string}` | `r${string}`;
54
+ /** 获取多组手牌与公共牌组合中的最大牌型签名及其对应的五张牌 */
55
+ export declare function getMaxRankSignatureAndPokes(handPokes: Poke[][], commonPokes: Poke[]): {
56
+ rankSignature: `s${string}` | `t${string}` | `q${string}` | `z${string}` | `y${string}` | `x${string}` | `w${string}` | `v${string}` | `u${string}` | `r${string}`;
59
57
  pokes: ("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[][];
60
58
  };
61
59
  /**
@@ -65,6 +63,6 @@ export declare function getMaxPresentationAndPokes(handPokes: Poke[][], commonPo
65
63
  */
66
64
  export declare const formatterPoke: (input: Poke[]) => string;
67
65
  /**
68
- * @description 根据玩家presentation, 计算出赢家
66
+ * @description 根据玩家 rankStrength 计算出赢家
69
67
  */
70
68
  export declare const getWinners: (players: Player[]) => Player[];
@@ -1,4 +1,4 @@
1
- import { handTypeCategory } from './constant';
1
+ import { RankCategory } from './constant';
2
2
  /**
3
3
  * 洗牌, 发牌
4
4
  */
@@ -21,10 +21,10 @@ declare class Deck {
21
21
  commonPokes: ("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[];
22
22
  };
23
23
  getCards(): ("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[];
24
- getMaxPresentation(): handTypeCategory;
24
+ getMaxRankCategory(): RankCategory;
25
25
  getMaxPokeCombinations(): ("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[][];
26
- getMaxPresentationAndPokes(): {
27
- presentation: `s${string}` | `t${string}` | `q${string}` | `z${string}` | `y${string}` | `x${string}` | `w${string}` | `v${string}` | `u${string}` | `r${string}`;
26
+ getMaxRankSignatureAndPokes(): {
27
+ rankSignature: `s${string}` | `t${string}` | `q${string}` | `z${string}` | `y${string}` | `x${string}` | `w${string}` | `v${string}` | `u${string}` | `r${string}`;
28
28
  pokes: ("h2" | "h3" | "h4" | "h5" | "h6" | "h7" | "h8" | "h9" | "ht" | "hj" | "hq" | "hk" | "ha" | "s2" | "s3" | "s4" | "s5" | "s6" | "s7" | "s8" | "s9" | "st" | "sj" | "sq" | "sk" | "sa" | "d2" | "d3" | "d4" | "d5" | "d6" | "d7" | "d8" | "d9" | "dt" | "dj" | "dq" | "dk" | "da" | "c2" | "c3" | "c4" | "c5" | "c6" | "c7" | "c8" | "c9" | "ct" | "cj" | "cq" | "ck" | "ca")[][];
29
29
  };
30
30
  }
@@ -1,4 +1,27 @@
1
- import { Role } from './index';
1
+ /** 座位角色枚举 */
2
+ export declare enum RoleEnum {
3
+ /** 庄家/按钮 */
4
+ BTN = "btn",
5
+ /** 小盲 */
6
+ SB = "sb",
7
+ /** 大盲 */
8
+ BB = "bb",
9
+ /** 枪口 */
10
+ UTG = "utg",
11
+ /** 枪口+1 */
12
+ UTG1 = "utg1",
13
+ /** 枪口+2(10 人桌) */
14
+ UTG2 = "utg2",
15
+ /** 中位 */
16
+ MP = "mp",
17
+ /** Lojack(10 人桌) */
18
+ LJ = "lj",
19
+ /** 劫持位 */
20
+ HJ = "hj",
21
+ /** 关煞位 */
22
+ CO = "co"
23
+ }
24
+ export type Role = RoleEnum;
2
25
  export declare enum ActionTypeEnum {
3
26
  CALL = "call",
4
27
  CHECK = "check",
@@ -8,6 +31,6 @@ export declare enum ActionTypeEnum {
8
31
  BET = "bet"
9
32
  }
10
33
  export declare const ActionTypeMap: Map<ActionTypeEnum, string>;
11
- export declare const roleMap: Map<Role, string>;
12
- declare const playerRoleSetMap: Map<number, Role[]>;
34
+ export declare const roleMap: Map<RoleEnum, string>;
35
+ declare const playerRoleSetMap: Map<number, RoleEnum[]>;
13
36
  export { playerRoleSetMap };
@@ -1,8 +1,8 @@
1
1
  import Pool from '../Pool';
2
2
  import Dealer from '../Dealer';
3
- import { Poke } from '../Deck/constant';
4
- import { ActionTypeEnum } from './constant';
3
+ import { ActionTypeEnum, RoleEnum, type Role } from './constant';
5
4
  import Controller from '../Controller';
5
+ import { Poke, RankSignature } from '../Deck/constant';
6
6
  import { PreAction, GameComponent, TexasErrorCallback } from '../Texas';
7
7
  export { ActionTypeEnum };
8
8
  type PlayerStatus = 'allIn' | 'active' | 'waiting' | 'out';
@@ -31,7 +31,8 @@ export interface User {
31
31
  avatar?: string;
32
32
  }
33
33
  export type CallbackOfAction = (player: Player, isPreFlop?: boolean) => Promise<void>;
34
- export type Role = 'button' | 'small-blind' | 'big-blind' | `under-the-gun${number | ''}` | `middle-position${number | ''}` | 'hi-jack' | 'cut-off';
34
+ export type { Role } from './constant';
35
+ export { RoleEnum } from './constant';
35
36
  /**
36
37
  * 玩家
37
38
  */
@@ -67,9 +68,11 @@ export declare class Player implements GameComponent {
67
68
  * @description 获取剩余的行动思考时间
68
69
  */
69
70
  getRemainThinkTime(): number;
71
+ get bestFiveCards(): Poke[] | undefined;
72
+ set bestFiveCards(value: Poke[] | undefined);
70
73
  setNextPlayer(player: Player | null): void;
71
- setPresentation(presentation: string): void;
72
- getPresentation(): string | undefined;
74
+ get rankSignature(): RankSignature | undefined;
75
+ set rankSignature(value: RankSignature);
73
76
  getNextPlayer(): Player | null;
74
77
  getLastPlayer(): Player | null;
75
78
  setLastPlayer(player: Player | null): void;
@@ -77,6 +80,8 @@ export declare class Player implements GameComponent {
77
80
  getStatus(): PlayerStatus;
78
81
  get onlineStatus(): OnlineStatus;
79
82
  set onlineStatus(value: OnlineStatus);
83
+ set rankStrength(value: number);
84
+ get rankStrength(): number;
80
85
  onPreAction(callback: (params: PreAction) => void): void;
81
86
  reset(): void;
82
87
  setRole(role: Role): void;
@@ -117,7 +122,7 @@ export declare class Player implements GameComponent {
117
122
  returnLatestPlayerIf(filter: (player: Player) => boolean): Player | null;
118
123
  returnNextPlayerIf(filter: (player: Player) => boolean): Player | null;
119
124
  getAction(): Action | undefined;
120
- getRole(): Role | undefined;
125
+ getRole(): RoleEnum | undefined;
121
126
  getUserInfo(): User;
122
127
  checkIfCanAct(): void;
123
128
  toString(): string;
package/types/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import { roleMap, ActionTypeMap } from './Player/constant';
8
8
  import { Stage, StageEnum, ControllerStatus } from './Controller';
9
9
  import { texasErrorMap, TexasErrorCode } from './TexasError/constant';
10
10
  import { RoomStatus, default as Room, PlayerSeatStatus } from './Room';
11
- import { User, Role, Action, ActionType, OnlineStatus, ActionTypeEnum, default as Player } from './Player';
11
+ import { User, Role, RoleEnum, Action, ActionType, OnlineStatus, ActionTypeEnum, default as Player } from './Player';
12
12
  export * from './Deck/constant';
13
- export { getBestPokesPresentation, comparePresentation, getHandStrengthInt, getHandStrengthIntFromPresentation } from './Deck/core';
14
- export { Player, User, ActionType, ActionTypeEnum, Role, Action, roleMap, ActionTypeMap, Stage, StageEnum, ControllerStatus, stageMap, Dealer, Deck, Room, RoomStatus, PlayerSeatStatus, formatterPoke, TexasError, TexasErrorCode, texasErrorMap, Texas, OnlineStatus };
13
+ export { getBestPokesRankSignature, compareRankSignature, getFiveCardsStrength, getStrengthFromRankSignature } from './Deck/core';
14
+ export { Player, User, ActionType, ActionTypeEnum, Role, RoleEnum, Action, roleMap, ActionTypeMap, Stage, StageEnum, ControllerStatus, stageMap, Dealer, Deck, Room, RoomStatus, PlayerSeatStatus, formatterPoke, TexasError, TexasErrorCode, texasErrorMap, Texas, OnlineStatus };