holdem-core 0.0.0-stage → 0.2.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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +215 -2
- package/README.zh-CN.md +81 -0
- package/dist/index.cjs +958 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +331 -0
- package/dist/index.d.ts +331 -0
- package/dist/index.js +922 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The project follows [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## 0.2.0 — hand ranges
|
|
6
|
+
|
|
7
|
+
- Ranges: `parseRange` reads standard notation — `QQ`, `AKs` / `AKo` / `AK`, `QQ+`, `ATs+`, `99-66`, `KTs-K8s`, `T9s-65s`, exact hands such as `AsKs`, and `random` — into distinct two-card combos; `comboClass` names a combo's class (`"AKs"`).
|
|
8
|
+
- Equity: `calculateRangeEquity` for 2–10 ranges with board and dead-card removal. Every non-clashing deal is equally likely; it enumerates exactly when deals × runouts fit in `exactLimit` and samples otherwise (seedable). Exact results match a deal-by-deal brute force to 12 decimal places.
|
|
9
|
+
- Errors: new code `INVALID_RANGE`.
|
|
10
|
+
- `calculateEquity` now shares its showdown tally with the range code; its results are unchanged.
|
|
11
|
+
- Releases are staged on npm from GitHub Actions (Trusted Publishing with provenance) and published only after a maintainer approves them with 2FA.
|
|
12
|
+
|
|
13
|
+
## 0.1.0 — first release
|
|
14
|
+
|
|
15
|
+
- Cards: parsing (`"As"`, `"10h"`, `"K♠"`), formatting, rank/suit helpers, duplicate checks.
|
|
16
|
+
- Randomness: secure source over `crypto.getRandomValues` with rejection sampling; seeded xoshiro128** source for tests and replays.
|
|
17
|
+
- Deck: unbiased Fisher–Yates `shuffle` / `shuffled`, `Deck` with exclusions.
|
|
18
|
+
- Evaluation: allocation-free `scoreHand` for 5–7 cards, `evaluateHand` with best five cards and descriptions, comparison helpers.
|
|
19
|
+
- Equity: exact enumeration up to 2,000,000 runouts, Monte Carlo beyond, board and dead cards, 2–10 players.
|
|
20
|
+
- Pots: main and side pots, folded chips, uncalled bets, odd-chip order; zero-sum settlement.
|
|
21
|
+
- Verification: all 133,784,560 seven-card hands; 1,000,000-hand cross-check against pokersolver; property tests for settlement.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HoldemForge
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,216 @@
|
|
|
1
|
-
#
|
|
1
|
+
# holdem-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Fast, zero-dependency Texas Hold'em toolkit for TypeScript and JavaScript.**
|
|
4
|
+
Card parsing, unbiased shuffling, 5–7 card hand evaluation, hand ranges, exact equity and side-pot settlement — verified exhaustively.
|
|
5
|
+
|
|
6
|
+
[](https://github.com/HoldemForge/holdem-core/actions/workflows/ci.yml)
|
|
7
|
+
[](https://www.npmjs.com/package/holdem-core)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
[中文说明](README.zh-CN.md)
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { parseCards, evaluateHand, calculateEquity, calculateRangeEquity, settlePots } from 'holdem-core';
|
|
16
|
+
|
|
17
|
+
evaluateHand(parseCards('Kh Kd Ks Tc Td 2s 3h')).description;
|
|
18
|
+
// → "Full House, Kings full of Tens"
|
|
19
|
+
|
|
20
|
+
calculateEquity([parseCards('As Ah'), parseCards('Kd Kc')]).players[0].equity;
|
|
21
|
+
// → 0.812555… (exact, all 1,712,304 runouts in ~80 ms)
|
|
22
|
+
|
|
23
|
+
calculateRangeEquity(['QQ+, AKs', 'JJ-99, AQs'], { board: parseCards('Kh 7d 2c') }).players[0].equity;
|
|
24
|
+
// → 0.928378… (exact, every deal of the two ranges and every turn and river)
|
|
25
|
+
|
|
26
|
+
settlePots(
|
|
27
|
+
[{ id: 'alice', amount: 50 }, { id: 'bob', amount: 100 }, { id: 'carol', amount: 100 }],
|
|
28
|
+
{ scores: { alice: 900, bob: 500, carol: 700 } },
|
|
29
|
+
).payouts;
|
|
30
|
+
// → { alice: 150, bob: 0, carol: 100 } (main pot to Alice, side pot to Carol)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Why holdem-core
|
|
34
|
+
|
|
35
|
+
- **Correct, and proven.** Every one of the **133,784,560** seven-card hands is evaluated in CI and matches the published category totals. 1,000,000 random hands and 1,000,000 showdowns agree with [pokersolver](https://www.npmjs.com/package/pokersolver) with zero mismatches.
|
|
36
|
+
- **Fast.** About **20 million** 7-card evaluations per second on one core — no 21-combination loop, no allocations, no giant lookup files (≈ 24 KB of tables built at load).
|
|
37
|
+
- **Complete for real games.** Side pots, folded chips, uncalled bets and odd-chip rules are handled; every settlement is checked to be zero-sum.
|
|
38
|
+
- **Ranges, not just hands.** Standard notation (`QQ+`, `AKs`, `T9s-65s`, `random`) with card removal; range-vs-range equity is exact whenever it can be enumerated and matches a deal-by-deal brute force.
|
|
39
|
+
- **Safe defaults.** Shuffles use `crypto.getRandomValues` with rejection sampling — no modulo bias. A seeded generator is available for tests and replays.
|
|
40
|
+
- **Small and typed.** Zero runtime dependencies, ESM + CommonJS, full `.d.ts`. Tested on Node 20, 22 and 24; uses only standard Web APIs, so it also runs in modern browsers.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm install holdem-core
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
### Cards
|
|
51
|
+
|
|
52
|
+
Cards are plain integers `0..51` (`rank * 4 + suit`) so hot loops stay allocation-free. Parse and format at the edges:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { parseCard, parseCards, formatCards, rankOf, suitOf } from 'holdem-core';
|
|
56
|
+
|
|
57
|
+
parseCards('As Kd 10h Q♠'); // accepts "T" or "10", any case, suit letters or symbols
|
|
58
|
+
formatCards(parseCards('askd')); // "As Kd"
|
|
59
|
+
rankOf(parseCard('Td')); // 8 (0 = deuce … 12 = ace)
|
|
60
|
+
suitOf(parseCard('Td')); // 1 (clubs, diamonds, hearts, spades)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Shuffling and dealing
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { Deck, createSeededRandom } from 'holdem-core';
|
|
67
|
+
|
|
68
|
+
const deck = new Deck(); // cryptographically secure shuffle
|
|
69
|
+
const [a, b] = [deck.deal(2), deck.deal(2)];
|
|
70
|
+
const flop = deck.deal(3);
|
|
71
|
+
|
|
72
|
+
const replay = new Deck(createSeededRandom('hand #1042')); // reproducible order — tests and replays only
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`shuffle(array, random?)` and `shuffled(array, random?)` work on any array.
|
|
76
|
+
|
|
77
|
+
### Evaluating hands
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { scoreHand, evaluateHand, compareHands, winners, formatCards } from 'holdem-core';
|
|
81
|
+
|
|
82
|
+
const board = parseCards('Ah Kh 7c 2d 9s');
|
|
83
|
+
const alice = scoreHand([...parseCards('Qh Jh'), ...board]); // fast path: a comparable integer
|
|
84
|
+
const bob = scoreHand([...parseCards('As 9c'), ...board]);
|
|
85
|
+
winners([alice, bob]); // [1] — Bob's two pair wins
|
|
86
|
+
|
|
87
|
+
const r = evaluateHand(parseCards('As 2s 3s 4s 5s Kd Qc'));
|
|
88
|
+
r.name; // "Straight Flush"
|
|
89
|
+
r.description; // "Straight Flush, Five-high"
|
|
90
|
+
formatCards(r.cards); // "5s 4s 3s 2s As"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
A `HandScore` is `category << 20 | five 4-bit ranks`: higher wins, equal splits, and there are exactly 7,462 distinct values.
|
|
94
|
+
|
|
95
|
+
### Equity
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { calculateEquity, parseCards, createSeededRandom } from 'holdem-core';
|
|
99
|
+
|
|
100
|
+
calculateEquity([parseCards('Ah Kh'), parseCards('Qs Qd'), parseCards('7c 8c')], {
|
|
101
|
+
board: parseCards('Qh 9h 6c'),
|
|
102
|
+
});
|
|
103
|
+
// → { exact: true, runouts: 903, players: [{ equity, win, tie }, …] }
|
|
104
|
+
|
|
105
|
+
// Too many runouts to enumerate? It switches to Monte Carlo automatically:
|
|
106
|
+
calculateEquity(hands, { iterations: 500_000, random: createSeededRandom(1) });
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Options: `board`, `dead`, `exactLimit` (default 2,000,000 runouts — heads-up and 3-way preflop are exact), `iterations`, `random`.
|
|
110
|
+
|
|
111
|
+
### Hand ranges
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { parseRange, comboClass, calculateRangeEquity, parseCards } from 'holdem-core';
|
|
115
|
+
|
|
116
|
+
parseRange('QQ+, AKs').length; // 22 two-card combos
|
|
117
|
+
parseRange('T9s-65s').map(comboClass); // ['T9s', 'T9s', 'T9s', 'T9s', '98s', …, '65s']
|
|
118
|
+
|
|
119
|
+
calculateRangeEquity(['AA', 'random']).players[0].equity;
|
|
120
|
+
// → ≈ 0.852 (sampled: 7,350 deals × 1,712,304 runouts each is too many to enumerate)
|
|
121
|
+
|
|
122
|
+
calculateRangeEquity(['QQ+, AKs', 'JJ-99, AQs'], { board: parseCards('Kh 7d 2c') });
|
|
123
|
+
// → { exact: true, runouts: 365310, combos: [18, 22], players: [{ equity: 0.928…, … }, …] }
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
| Notation | Meaning | Combos |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `QQ` | one pair | 6 |
|
|
129
|
+
| `AKs` / `AKo` / `AK` | suited / offsuit / both | 4 / 12 / 16 |
|
|
130
|
+
| `QQ+` | QQ, KK, AA | 18 |
|
|
131
|
+
| `ATs+` | ATs, AJs, AQs, AKs | 16 |
|
|
132
|
+
| `99-66` | 99, 88, 77, 66 | 24 |
|
|
133
|
+
| `KTs-K8s` | KTs, K9s, K8s | 12 |
|
|
134
|
+
| `T9s-65s` | T9s, 98s, 87s, 76s, 65s | 20 |
|
|
135
|
+
| `AsKs` | one exact hand | 1 |
|
|
136
|
+
| `random` (or `any`) | every hand | 1,326 |
|
|
137
|
+
|
|
138
|
+
Separate tokens with commas or spaces; overlapping tokens count each hand once. A range can also be an array of two-card hands, so `calculateRangeEquity` accepts `parseRange` output, your own hand lists or a single exact hand.
|
|
139
|
+
|
|
140
|
+
Every way to deal one hand to each player without a shared card is equally likely, and hands that clash with the board or dead cards are removed (`combos` reports what is left). Here `exactLimit` counts deals × runouts, so small ranges — and most ranges on the turn or river — are exact. Beyond that, random deals that share a card are redrawn; with many players on overlapping ranges this slows sampling down (nine random hands take about two seconds at the default 200,000 iterations).
|
|
141
|
+
|
|
142
|
+
### Side pots and settlement
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { buildPots, settlePots } from 'holdem-core';
|
|
146
|
+
|
|
147
|
+
buildPots([
|
|
148
|
+
{ id: 'short', amount: 30 },
|
|
149
|
+
{ id: 'mid', amount: 80 },
|
|
150
|
+
{ id: 'big', amount: 200 },
|
|
151
|
+
{ id: 'folded', amount: 20, folded: true },
|
|
152
|
+
]);
|
|
153
|
+
// → [ { amount: 110, eligible: ['short','mid','big'] },
|
|
154
|
+
// { amount: 100, eligible: ['mid','big'] },
|
|
155
|
+
// { amount: 120, eligible: ['big'] } ] ← uncalled chips go back to "big"
|
|
156
|
+
|
|
157
|
+
settlePots(contributions, {
|
|
158
|
+
scores: { short: s1, mid: s2, big: s3 }, // e.g. scoreHand(...) of each live hand
|
|
159
|
+
oddChipOrder: ['mid', 'big', 'short'], // seats starting left of the button
|
|
160
|
+
});
|
|
161
|
+
// → { pots: [...winners, shares], payouts, net } — net always sums to 0
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Amounts are integers in your smallest unit. Players alone in a pot need no score.
|
|
165
|
+
|
|
166
|
+
## Verification and benchmarks
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
npm test # unit + property tests, includes all 2,598,960 five-card hands
|
|
170
|
+
npm run verify:exhaustive # all 133,784,560 seven-card hands
|
|
171
|
+
npm run verify:crosscheck # 1,000,000 hands + 1,000,000 showdowns vs pokersolver
|
|
172
|
+
npm run bench
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Results on Node 24, Apple M5:
|
|
176
|
+
|
|
177
|
+
| | |
|
|
178
|
+
|---|---|
|
|
179
|
+
| Seven-card hands evaluated exhaustively | 133,784,560 in 2.8 s — all category totals and the 4,824 distinct values match |
|
|
180
|
+
| Cross-check vs pokersolver | 0 mismatches in 1,000,000 categories and 1,000,000 showdowns |
|
|
181
|
+
| `scoreHand`, 7 cards | ~20,000,000 hands/s (pokersolver: ~120,000 hands/s, ~166× slower) |
|
|
182
|
+
| AA vs KK preflop, exact | 1,712,304 runouts in ~80 ms — equity 81.2555%, identical to a pokersolver brute force |
|
|
183
|
+
| Range vs range | exact results equal a deal-by-deal brute force to 12 decimal places; AA vs a random hand 85.22% over 4,000,000 samples (published: 85.20%) |
|
|
184
|
+
| Test coverage | 100% lines and functions |
|
|
185
|
+
|
|
186
|
+
## API
|
|
187
|
+
|
|
188
|
+
| Area | Exports |
|
|
189
|
+
|---|---|
|
|
190
|
+
| Cards | `Card`, `parseCard`, `parseCards`, `formatCard`, `formatCards`, `makeCard`, `rankOf`, `suitOf`, `rankName`, `isCard`, `assertDistinctCards`, `RANKS`, `SUITS` |
|
|
191
|
+
| Randomness | `RandomSource`, `secureRandom`, `createSecureRandom`, `createSeededRandom` |
|
|
192
|
+
| Deck | `Deck`, `createDeck`, `shuffle`, `shuffled` |
|
|
193
|
+
| Evaluation | `scoreHand`, `evaluateHand`, `compareHands`, `compareScores`, `winners`, `categoryOf`, `handName`, `describeScore`, `HandCategory`, `HandScore`, `HandResult` |
|
|
194
|
+
| Equity | `calculateEquity`, `calculateRangeEquity`, `EquityOptions`, `EquityResult`, `RangeEquityResult`, `PlayerEquity` |
|
|
195
|
+
| Ranges | `parseRange`, `comboClass`, `Combo` |
|
|
196
|
+
| Pots | `buildPots`, `settlePots`, `Contribution`, `Pot`, `SettledPot`, `Settlement`, `SettleOptions` |
|
|
197
|
+
| Errors | `HoldemError` with a `code` (`INVALID_CARD`, `DUPLICATE_CARD`, `INVALID_HAND_SIZE`, `INVALID_RANGE`, …) |
|
|
198
|
+
|
|
199
|
+
Exports carry TSDoc comments, so your editor shows the details inline.
|
|
200
|
+
|
|
201
|
+
## Roadmap
|
|
202
|
+
|
|
203
|
+
- Omaha (4 and 5 cards) evaluation
|
|
204
|
+
- Run-it-twice settlement helpers
|
|
205
|
+
|
|
206
|
+
Ideas and pull requests are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
207
|
+
|
|
208
|
+
## Need a complete poker platform?
|
|
209
|
+
|
|
210
|
+
holdem-core is maintained by **HoldemForge**. We also build a complete, self-hosted Texas Hold'em club platform — multiplayer tables, clubs, admin panels and one-command Docker deployment — for entertainment play only, with no real-money features. See [holdemforge.com](https://holdemforge.com).
|
|
211
|
+
|
|
212
|
+
Contact: [hello@holdemforge.com](mailto:hello@holdemforge.com) · Telegram [@holdemforge](https://t.me/holdemforge)
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
[MIT](LICENSE) © HoldemForge
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# holdem-core
|
|
2
|
+
|
|
3
|
+
**快速、零依赖的德州扑克工具库(TypeScript / JavaScript)。**
|
|
4
|
+
提供牌面解析、无偏洗牌、5–7 张牌型判断、手牌范围、精确胜率和边池结算,全部经过穷举验证。
|
|
5
|
+
|
|
6
|
+
[English](README.md)
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { parseCards, evaluateHand, calculateEquity, calculateRangeEquity, settlePots } from 'holdem-core';
|
|
10
|
+
|
|
11
|
+
evaluateHand(parseCards('Kh Kd Ks Tc Td 2s 3h')).description;
|
|
12
|
+
// → "Full House, Kings full of Tens"(葫芦,三条 K 带一对 10)
|
|
13
|
+
|
|
14
|
+
calculateEquity([parseCards('As Ah'), parseCards('Kd Kc')]).players[0].equity;
|
|
15
|
+
// → 0.812555…(精确值,穷举全部 1,712,304 种公共牌,约 80 毫秒)
|
|
16
|
+
|
|
17
|
+
calculateRangeEquity(['QQ+, AKs', 'JJ-99, AQs'], { board: parseCards('Kh 7d 2c') }).players[0].equity;
|
|
18
|
+
// → 0.928378…(精确值,两个范围的每种发法、每种转牌河牌都算到)
|
|
19
|
+
|
|
20
|
+
settlePots(
|
|
21
|
+
[{ id: 'alice', amount: 50 }, { id: 'bob', amount: 100 }, { id: 'carol', amount: 100 }],
|
|
22
|
+
{ scores: { alice: 900, bob: 500, carol: 700 } },
|
|
23
|
+
).payouts;
|
|
24
|
+
// → { alice: 150, bob: 0, carol: 100 }(主池归 Alice,边池归 Carol)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 特点
|
|
28
|
+
|
|
29
|
+
- **结果可验证。** 持续集成中穷举全部 **133,784,560** 种七张牌组合,各牌型数量与理论值完全一致;随机抽取 100 万手牌和 100 万次摊牌,与 [pokersolver](https://www.npmjs.com/package/pokersolver) 对比,结果零差异。
|
|
30
|
+
- **速度快。** 单核每秒约 **2000 万** 次七张牌判断:无需枚举 21 种组合,计算过程零内存分配,也不依赖几十 MB 的查找表(启动时仅生成约 24 KB)。
|
|
31
|
+
- **覆盖真实牌局。** 边池、弃牌玩家已投入的筹码、无人跟注时的退还、平分时的零头分配都已处理;每次结算都会校验所有人输赢合计为零。
|
|
32
|
+
- **支持手牌范围。** 通用写法(`QQ+`、`AKs`、`T9s-65s`、`random`),自动扣除撞牌;范围对范围的胜率能穷举时给精确值,并与逐个发法硬算的结果核对一致。
|
|
33
|
+
- **默认安全。** 洗牌使用 `crypto.getRandomValues` 加拒绝采样,没有取模偏差;另提供可固定种子的随机源,供测试和回放使用。
|
|
34
|
+
- **轻量,自带类型。** 零运行时依赖,同时提供 ESM 和 CommonJS 两种格式,附完整类型声明;已在 Node 20 / 22 / 24 上测试,只用标准 Web API,在现代浏览器中也能直接运行。
|
|
35
|
+
|
|
36
|
+
## 安装
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npm install holdem-core
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 用法
|
|
43
|
+
|
|
44
|
+
完整示例见 [英文说明](README.md#usage),要点:
|
|
45
|
+
|
|
46
|
+
- **牌**:`0..51` 的整数(`点数 * 4 + 花色`)。`parseCards('As Kd 10h Q♠')` 解析,`formatCards` 显示。
|
|
47
|
+
- **洗牌发牌**:`new Deck()` 用安全随机数洗牌,`deck.deal(n)` 发牌;`new Deck(createSeededRandom('种子'))` 每次顺序相同,只用于测试和回放。
|
|
48
|
+
- **比牌**:`scoreHand(cards)` 返回可直接比较的整数(越大越强,相等即平分);`evaluateHand` 额外给出牌型名称、描述和组成的五张牌。
|
|
49
|
+
- **胜率**:`calculateEquity(hands, { board, dead })`,能穷举时给精确值,否则自动蒙特卡洛。
|
|
50
|
+
- **手牌范围**:`parseRange('QQ+, AKs')` 展开成具体手牌(22 手);写法有 `QQ`、`AKs` / `AKo` / `AK`、`QQ+`、`ATs+`、`99-66`、`KTs-K8s`、`T9s-65s`、`AsKs`、`random`。`calculateRangeEquity(['QQ+, AKs', 'JJ-99, AQs'], { board })` 算范围对范围的胜率:每种不撞牌的发法等概率,与公共牌、死牌撞的手牌自动去掉;能穷举时给精确值(`exactLimit` 按「发法数 × 公共牌种数」算),否则随机抽样。人多且范围重叠多时抽样会变慢(9 人全随机手牌、默认 20 万次约 2 秒)。
|
|
51
|
+
- **结算**:`settlePots(contributions, { scores, oddChipOrder })` 算出主池、边池、每池赢家和每人净输赢。
|
|
52
|
+
|
|
53
|
+
## 验证与性能
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
npm test # 单元测试 + 性质测试,含全部 2,598,960 种五张牌
|
|
57
|
+
npm run verify:exhaustive # 全部 133,784,560 种七张牌
|
|
58
|
+
npm run verify:crosscheck # 与 pokersolver 对比 100 万手 + 100 万次摊牌
|
|
59
|
+
npm run bench
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Node 24、Apple M5 上的结果:
|
|
63
|
+
|
|
64
|
+
| | |
|
|
65
|
+
|---|---|
|
|
66
|
+
| 七张牌穷举 | 133,784,560 种,2.8 秒;各牌型数量和 4,824 种不同牌力全部吻合 |
|
|
67
|
+
| 与 pokersolver 对比 | 100 万手牌型、100 万次摊牌,0 处不一致 |
|
|
68
|
+
| `scoreHand`(七张) | 约每秒 2000 万手(pokersolver 约每秒 12 万手,慢约 166 倍) |
|
|
69
|
+
| AA 对 KK 翻前精确胜率 | 1,712,304 种公共牌,约 80 毫秒;81.2555%,与 pokersolver 穷举结果完全相同 |
|
|
70
|
+
| 范围对范围 | 精确结果与逐个发法硬算一致到小数点后 12 位;AA 对随机手牌抽样 400 万次 85.22%(公认值 85.20%) |
|
|
71
|
+
| 测试覆盖率 | 代码行、函数 100% |
|
|
72
|
+
|
|
73
|
+
## 需要完整的德州扑克平台?
|
|
74
|
+
|
|
75
|
+
holdem-core 由 **HoldemForge** 维护。我们还提供可自主部署的德州扑克俱乐部平台,包含多人牌桌、俱乐部、管理后台和 Docker 一键部署,仅限娱乐玩法,不含任何真钱功能。详见 [holdemforge.com](https://holdemforge.com)。
|
|
76
|
+
|
|
77
|
+
联系:[hello@holdemforge.com](mailto:hello@holdemforge.com) · Telegram [@holdemforge](https://t.me/holdemforge)
|
|
78
|
+
|
|
79
|
+
## 许可
|
|
80
|
+
|
|
81
|
+
[MIT](LICENSE) © HoldemForge
|