poker-extval 1.1.0 → 3.0.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.
Files changed (3) hide show
  1. package/README.md +95 -15
  2. package/evaluator.js +549 -294
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -49,12 +49,6 @@ const evaluator = new HandEvaluator(['As', 'Ks', 'Qs', 'Js', 'Ts', '9s']);
49
49
  // Access evaluation results
50
50
  const evaluation = evaluator.evaluation;
51
51
  // Object with keys for each 5-card combination
52
-
53
- // Use utility methods
54
- evaluator.sort(); // Sort cards by rank
55
- evaluator.getDistance(); // Get distance between highest and lowest card
56
- evaluator.countSuits(); // Count suits in hand
57
- evaluator.countRanks(); // Count ranks in hand
58
52
  ```
59
53
 
60
54
  ### Evaluating Multiple Card Hands
@@ -126,12 +120,19 @@ The `evaluateHand()` function returns an object where:
126
120
  - `isBackdoorFlushDraw` - Three cards of the same suit (two away from flush)
127
121
  - `isOpenEndedStraightDraw` - One card away from straight on either end
128
122
  - `isInsideStraightDraw` - One card away from straight (needed card in middle)
123
+ - `isStraightDraw` - Any type of straight draw (open-ended or inside, standard or wheel)
129
124
 
130
125
  #### Wheel Straight Support
131
126
  - `isStraightWheel` - Wheel straight (A-2-3-4-5)
132
127
  - `isOpenEndedStraightDrawWheel` - Open-ended draw using wheel ranking
133
128
  - `isInsideStraightDrawWheel` - Inside draw using wheel ranking
134
129
 
130
+ #### Card Arrays
131
+ - `keyCards` - Object with keys for each hand type/draw, values are arrays of cards (sorted) that constitute that specific hand type or draw. False hand types have empty arrays `[]`.
132
+ - `kickerCards` - Object with keys for each hand type/draw, values are arrays of cards (sorted) that don't constitute that specific hand type or draw. False hand types have empty arrays `[]`, except `isHighCard` which contains all 5 cards when true.
133
+
134
+ **Note**: Each hand type has its own `keyCards` and `kickerCards` entries. For example, a hand with both a pair and a flush draw will have separate entries in `keyCards.isPair`, `keyCards.isFlushDraw`, `kickerCards.isPair`, and `kickerCards.isFlushDraw`.
135
+
135
136
  ### Example Response
136
137
 
137
138
  ```javascript
@@ -159,7 +160,88 @@ The `evaluateHand()` function returns an object where:
159
160
  "isBackdoorFlushDraw": false,
160
161
  "isOpenEndedStraightDraw": false,
161
162
  "isInsideStraightDraw": false,
162
- "isHighCard": false
163
+ "isStraightDraw": false,
164
+ "isHighCard": false,
165
+ "keyCards": {
166
+ "isRoyalFlush": ["As", "Ks", "Qs", "Js", "Ts"],
167
+ "isStraightFlush": [],
168
+ "isFourOfAKind": [],
169
+ "isFullHouse": [],
170
+ "isFlush": ["As", "Ks", "Qs", "Js", "Ts"],
171
+ "isStraight": ["As", "Ks", "Qs", "Js", "Ts"],
172
+ "isThreeOfAKind": [],
173
+ "isTwoPair": [],
174
+ "isPair": [],
175
+ "isTopPair": [],
176
+ "isMiddlePair": [],
177
+ "isBottomPair": [],
178
+ "isTopAndMiddlePair": [],
179
+ "isTopAndBottomPair": [],
180
+ "isMiddleAndBottomPair": [],
181
+ "isTopThreeOfAKind": [],
182
+ "isMiddleThreeOfAKind": [],
183
+ "isBottomThreeOfAKind": [],
184
+ "isFlushDraw": [],
185
+ "isBackdoorFlushDraw": [],
186
+ "isOpenEndedStraightDraw": [],
187
+ "isInsideStraightDraw": [],
188
+ "isStraightDraw": [],
189
+ "isStraightWheel": [],
190
+ "isOpenEndedStraightDrawWheel": [],
191
+ "isInsideStraightDrawWheel": [],
192
+ "isHighCard": []
193
+ },
194
+ "kickerCards": {
195
+ "isRoyalFlush": [],
196
+ "isStraightFlush": [],
197
+ "isFourOfAKind": [],
198
+ "isFullHouse": [],
199
+ "isFlush": [],
200
+ "isStraight": [],
201
+ "isThreeOfAKind": [],
202
+ "isTwoPair": [],
203
+ "isPair": [],
204
+ "isTopPair": [],
205
+ "isMiddlePair": [],
206
+ "isBottomPair": [],
207
+ "isTopAndMiddlePair": [],
208
+ "isTopAndBottomPair": [],
209
+ "isMiddleAndBottomPair": [],
210
+ "isTopThreeOfAKind": [],
211
+ "isMiddleThreeOfAKind": [],
212
+ "isBottomThreeOfAKind": [],
213
+ "isFlushDraw": [],
214
+ "isBackdoorFlushDraw": [],
215
+ "isOpenEndedStraightDraw": [],
216
+ "isInsideStraightDraw": [],
217
+ "isStraightDraw": [],
218
+ "isStraightWheel": [],
219
+ "isOpenEndedStraightDrawWheel": [],
220
+ "isInsideStraightDrawWheel": [],
221
+ "isHighCard": []
222
+ }
223
+ }
224
+ }
225
+ ```
226
+
227
+ **Example 2: Pair with Flush Draw**
228
+
229
+ ```javascript
230
+ {
231
+ "As, Ah, Ks, Qs, Js": {
232
+ "isPair": true,
233
+ "isFlushDraw": true,
234
+ // ... other boolean properties ...
235
+ "keyCards": {
236
+ "isPair": ["As", "Ah"],
237
+ "isFlushDraw": ["As", "Ks", "Qs", "Js"],
238
+ // ... other hand types with empty arrays ...
239
+ },
240
+ "kickerCards": {
241
+ "isPair": ["Ks", "Qs", "Js"],
242
+ "isFlushDraw": ["Ah"],
243
+ // ... other hand types with empty arrays ...
244
+ }
163
245
  }
164
246
  }
165
247
  ```
@@ -265,16 +347,14 @@ new HandEvaluator(cards)
265
347
 
266
348
  Creates a new HandEvaluator instance.
267
349
 
268
- #### Methods
350
+ **Parameters:**
351
+ - `cards` (string[]): Array of 5 or more card strings
269
352
 
270
- - `sort(cards?)` - Sort cards by rank (highest to lowest)
271
- - `sortWheel(cards?)` - Sort cards using wheel ranking (Ace low)
272
- - `getDistance(cards?)` - Calculate distance between highest and lowest card
273
- - `getDistanceWheel(cards?)` - Calculate distance using wheel ranking
274
- - `countSuits()` - Count occurrences of each suit
275
- - `countRanks()` - Count occurrences of each rank (sorted)
353
+ **Properties:**
354
+ - `evaluation` - Object mapping sorted hand strings to evaluation objects (same format as `evaluateHand()` return value)
355
+ - `cards` - Array of input cards
276
356
 
277
- All evaluation methods (e.g., `isPair()`, `isFlush()`, etc.) are available but typically accessed through the `evaluation` property.
357
+ **Note**: All internal methods are private. Use the `evaluation` property to access evaluation results.
278
358
 
279
359
  ## License
280
360