poker-bitvaljs 1.0.0 → 1.1.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/README.md +67 -6
- package/bitval.js +964 -254
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,9 +8,10 @@ High-performance poker hand evaluator optimized for browser environments, using
|
|
|
8
8
|
|
|
9
9
|
- **Fast hand evaluation** using bitwise operations
|
|
10
10
|
- **Range vs range equity calculations** with canonical key caching optimization
|
|
11
|
+
- **Web Workers support** for parallel processing across multiple CPU cores (3-7x speedup)
|
|
11
12
|
- **Monte Carlo simulation** for preflop and postflop scenarios
|
|
12
13
|
- **Exhaustive enumeration** for flop/turn scenarios (2 or fewer cards to come)
|
|
13
|
-
- **Progress callbacks**
|
|
14
|
+
- **Progress callbacks** with configurable update intervals
|
|
14
15
|
- **Browser and Node.js compatible**
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
@@ -53,7 +54,9 @@ const result = await bitval.compareRange(
|
|
|
53
54
|
5, // number of board cards
|
|
54
55
|
10000, // iterations
|
|
55
56
|
true, // optimize (use canonical caching)
|
|
56
|
-
null // progress callback (optional)
|
|
57
|
+
null, // progress callback (optional)
|
|
58
|
+
100, // progress interval (optional, default: 100)
|
|
59
|
+
true // use workers (optional, default: true)
|
|
57
60
|
);
|
|
58
61
|
|
|
59
62
|
// Result: { win: 8120, tie: 30, lose: 1850 }
|
|
@@ -73,7 +76,27 @@ const result = await bitval.compareRange(
|
|
|
73
76
|
true,
|
|
74
77
|
(current, total, message) => {
|
|
75
78
|
console.log(`${Math.round((current/total)*100)}% - ${message}`);
|
|
76
|
-
}
|
|
79
|
+
},
|
|
80
|
+
100, // Update progress every 100 matchups
|
|
81
|
+
true // Use Web Workers for parallelization
|
|
82
|
+
);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### With Web Workers Disabled
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
// Disable Web Workers (useful for debugging or when workers aren't supported)
|
|
89
|
+
const result = await bitval.compareRange(
|
|
90
|
+
heroHands,
|
|
91
|
+
villainHands,
|
|
92
|
+
[],
|
|
93
|
+
[],
|
|
94
|
+
5,
|
|
95
|
+
10000,
|
|
96
|
+
true,
|
|
97
|
+
null,
|
|
98
|
+
100,
|
|
99
|
+
false // Disable Web Workers, use sequential execution
|
|
77
100
|
);
|
|
78
101
|
```
|
|
79
102
|
|
|
@@ -134,9 +157,9 @@ Simulates a single hand vs hand matchup.
|
|
|
134
157
|
**Returns:**
|
|
135
158
|
- `{ win, tie, lose }`: Results object
|
|
136
159
|
|
|
137
|
-
### `compareRange(heroHands, villainHands, boardCards, deadCards, numberOfBoardCards, iterations, optimize, progressCallback)`
|
|
160
|
+
### `compareRange(heroHands, villainHands, boardCards, deadCards, numberOfBoardCards, iterations, optimize, progressCallback, progressInterval, useWorkers)`
|
|
138
161
|
|
|
139
|
-
Compares two ranges of hands with optional optimization.
|
|
162
|
+
Compares two ranges of hands with optional optimization and Web Workers parallelization.
|
|
140
163
|
|
|
141
164
|
**Parameters:**
|
|
142
165
|
- `heroHands` (Array): Array of hero hand strings (e.g., `['AsAh', 'AsAd']`)
|
|
@@ -146,20 +169,58 @@ Compares two ranges of hands with optional optimization.
|
|
|
146
169
|
- `numberOfBoardCards` (Number): Total board cards (default: `5`)
|
|
147
170
|
- `iterations` (Number): Number of simulations per matchup (default: `10000`)
|
|
148
171
|
- `optimize` (Boolean): Use canonical key caching for performance (default: `true`). **Note:** Optimizations may result in a ±0.5% margin of error compared to unoptimized calculations.
|
|
149
|
-
- `progressCallback` (Function): Optional callback `(current, total, message) => {}`
|
|
172
|
+
- `progressCallback` (Function): Optional callback `(current, total, message) => {}` (default: `null`)
|
|
173
|
+
- `progressInterval` (Number): Update progress callback every N matchups (default: `100`)
|
|
174
|
+
- `useWorkers` (Boolean): Use Web Workers for parallelization across CPU cores (default: `true`). Automatically falls back to sequential execution if workers are unavailable or workload is too small (< 4 matchups).
|
|
150
175
|
|
|
151
176
|
**Returns:**
|
|
152
177
|
- `Promise<{ win, tie, lose }>`: Results object
|
|
153
178
|
|
|
179
|
+
**Web Workers Notes:**
|
|
180
|
+
- Web Workers provide 3-7x speedup on multi-core systems by parallelizing matchup evaluations
|
|
181
|
+
- Workers are automatically disabled when:
|
|
182
|
+
- `useWorkers` is `false`
|
|
183
|
+
- Workers are not supported by the browser
|
|
184
|
+
- There are fewer than 4 matchups (overhead not worth it)
|
|
185
|
+
- For local testing with `file://` protocol, use a local web server (see [Testing Locally](#testing-locally))
|
|
186
|
+
|
|
154
187
|
## Performance
|
|
155
188
|
|
|
156
189
|
- **Optimized for browser environments** with efficient bitwise operations
|
|
190
|
+
- **Web Workers parallelization** provides 3-7x speedup on multi-core systems
|
|
157
191
|
- Canonical key caching reduces redundant evaluations (may introduce ±0.5% margin of error)
|
|
158
192
|
- Exhaustive enumeration for flop/turn (2 or fewer cards to come)
|
|
159
193
|
- Monte Carlo simulation for preflop and river scenarios
|
|
194
|
+
- Adaptive progress reporting to minimize UI blocking
|
|
160
195
|
|
|
161
196
|
**Test performance and benchmark online:** [https://darraghgeo.github.io/poker-bitvaljs/](https://darraghgeo.github.io/poker-bitvaljs/)
|
|
162
197
|
|
|
198
|
+
### Performance Tips
|
|
199
|
+
|
|
200
|
+
- Enable Web Workers (default) for best performance on multi-core systems
|
|
201
|
+
- Use canonical caching (`optimize: true`) for large range comparisons
|
|
202
|
+
- Adjust `progressInterval` to balance UI responsiveness vs. performance
|
|
203
|
+
- For very small workloads (< 4 matchups), workers are automatically disabled to avoid overhead
|
|
204
|
+
|
|
205
|
+
## Testing Locally
|
|
206
|
+
|
|
207
|
+
When testing locally, Web Workers require a proper HTTP origin. If you open `index.html` directly from the file system (`file://` protocol), workers will fail with a `SecurityError`.
|
|
208
|
+
|
|
209
|
+
**Solution: Use a local web server**
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Python 3
|
|
213
|
+
python3 -m http.server 8000
|
|
214
|
+
|
|
215
|
+
# Node.js (if you have npx)
|
|
216
|
+
npx http-server -p 8000
|
|
217
|
+
|
|
218
|
+
# PHP (if installed)
|
|
219
|
+
php -S localhost:8000
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Then open `http://localhost:8000` in your browser. The application will automatically fall back to sequential execution if workers are unavailable.
|
|
223
|
+
|
|
163
224
|
## License
|
|
164
225
|
|
|
165
226
|
MIT
|