@pokertools/evaluator 1.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.
- package/LICENSE +21 -0
- package/README.md +159 -0
- package/dist/core/evaluator.d.ts +3 -0
- package/dist/core/evaluator.js +164 -0
- package/dist/core/hash.d.ts +8 -0
- package/dist/core/hash.js +22 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +69 -0
- package/dist/models/hand-rank.d.ts +21 -0
- package/dist/models/hand-rank.js +54 -0
- package/dist/tables/bit-masks.d.ts +2 -0
- package/dist/tables/bit-masks.js +15 -0
- package/dist/tables/dp.d.ts +3 -0
- package/dist/tables/dp.js +267 -0
- package/dist/tables/flush.d.ts +1 -0
- package/dist/tables/flush.js +363 -0
- package/dist/tables/no-flush-5.d.ts +1 -0
- package/dist/tables/no-flush-5.js +388 -0
- package/dist/tables/no-flush-6.d.ts +1 -0
- package/dist/tables/no-flush-6.js +1121 -0
- package/dist/tables/no-flush-7.d.ts +1 -0
- package/dist/tables/no-flush-7.js +2895 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/card.d.ts +19 -0
- package/dist/utils/card.js +79 -0
- package/package.json +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/core/evaluator.ts","../src/core/hash.ts","../src/models/hand-rank.ts","../src/tables/bit-masks.ts","../src/tables/dp.ts","../src/tables/flush.ts","../src/tables/no-flush-5.ts","../src/tables/no-flush-6.ts","../src/tables/no-flush-7.ts","../src/utils/card.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a card string (e.g. "Ah", "Td") into the integer format
|
|
3
|
+
* expected by the evaluator.
|
|
4
|
+
*
|
|
5
|
+
* Format: (RankIndex << 2) | SuitIndex
|
|
6
|
+
*/
|
|
7
|
+
export declare function getCardCode(cardStr: string): number;
|
|
8
|
+
/**
|
|
9
|
+
* Converts an array of card strings into an array of integers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCardCodes(cards: string[]): number[];
|
|
12
|
+
/**
|
|
13
|
+
* Parses a board string (e.g. "Ah Ks Qd") into integers.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getBoardCodes(board: string): number[];
|
|
16
|
+
/**
|
|
17
|
+
* Converts an integer code back to a string (e.g. 49 -> "Ah").
|
|
18
|
+
*/
|
|
19
|
+
export declare function stringifyCardCode(code: number): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCardCode = getCardCode;
|
|
4
|
+
exports.getCardCodes = getCardCodes;
|
|
5
|
+
exports.getBoardCodes = getBoardCodes;
|
|
6
|
+
exports.stringifyCardCode = stringifyCardCode;
|
|
7
|
+
/**
|
|
8
|
+
* Maps rank characters to their integer index (2=0 ... A=12)
|
|
9
|
+
*/
|
|
10
|
+
const RANK_MAP = {
|
|
11
|
+
"2": 0,
|
|
12
|
+
"3": 1,
|
|
13
|
+
"4": 2,
|
|
14
|
+
"5": 3,
|
|
15
|
+
"6": 4,
|
|
16
|
+
"7": 5,
|
|
17
|
+
"8": 6,
|
|
18
|
+
"9": 7,
|
|
19
|
+
T: 8,
|
|
20
|
+
J: 9,
|
|
21
|
+
Q: 10,
|
|
22
|
+
K: 11,
|
|
23
|
+
A: 12,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Maps suit characters to their integer index (s=0, h=1, d=2, c=3)
|
|
27
|
+
*/
|
|
28
|
+
const SUIT_MAP = {
|
|
29
|
+
s: 0,
|
|
30
|
+
h: 1,
|
|
31
|
+
d: 2,
|
|
32
|
+
c: 3,
|
|
33
|
+
};
|
|
34
|
+
const RANK_CHARS = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"];
|
|
35
|
+
const SUIT_CHARS = ["s", "h", "d", "c"];
|
|
36
|
+
/**
|
|
37
|
+
* Converts a card string (e.g. "Ah", "Td") into the integer format
|
|
38
|
+
* expected by the evaluator.
|
|
39
|
+
*
|
|
40
|
+
* Format: (RankIndex << 2) | SuitIndex
|
|
41
|
+
*/
|
|
42
|
+
function getCardCode(cardStr) {
|
|
43
|
+
if (cardStr.length !== 2) {
|
|
44
|
+
throw new Error(`Invalid card string length: "${cardStr}"`);
|
|
45
|
+
}
|
|
46
|
+
const r = RANK_MAP[cardStr[0]];
|
|
47
|
+
const s = SUIT_MAP[cardStr[1]];
|
|
48
|
+
if (r === undefined || s === undefined) {
|
|
49
|
+
throw new Error(`Invalid card characters: "${cardStr}"`);
|
|
50
|
+
}
|
|
51
|
+
return (r << 2) | s;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Converts an array of card strings into an array of integers.
|
|
55
|
+
*/
|
|
56
|
+
function getCardCodes(cards) {
|
|
57
|
+
const len = cards.length;
|
|
58
|
+
const out = new Array(len);
|
|
59
|
+
for (let i = 0; i < len; i++) {
|
|
60
|
+
out[i] = getCardCode(cards[i]);
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Parses a board string (e.g. "Ah Ks Qd") into integers.
|
|
66
|
+
*/
|
|
67
|
+
function getBoardCodes(board) {
|
|
68
|
+
if (!board)
|
|
69
|
+
return [];
|
|
70
|
+
return getCardCodes(board.trim().split(/\s+/));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Converts an integer code back to a string (e.g. 49 -> "Ah").
|
|
74
|
+
*/
|
|
75
|
+
function stringifyCardCode(code) {
|
|
76
|
+
const rank = code >> 2;
|
|
77
|
+
const suit = code & 0b11;
|
|
78
|
+
return (RANK_CHARS[rank] || "?") + (SUIT_CHARS[suit] || "?");
|
|
79
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pokertools/evaluator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "High-performance Poker Hand Evaluator (5, 6, and 7 cards)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "NODE_OPTIONS='--no-warnings' jest"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"poker",
|
|
26
|
+
"hand",
|
|
27
|
+
"evaluator",
|
|
28
|
+
"texas",
|
|
29
|
+
"holdem",
|
|
30
|
+
"typescript",
|
|
31
|
+
"poker-hand",
|
|
32
|
+
"poker-evaluator",
|
|
33
|
+
"card-game",
|
|
34
|
+
"performance"
|
|
35
|
+
],
|
|
36
|
+
"author": "A.Aurelius",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/aaurelions/pokertools.git",
|
|
41
|
+
"directory": "packages/evaluator"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/aaurelions/pokertools/tree/main/packages/evaluator#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/aaurelions/pokertools/issues"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/jest": "^30.0.0",
|
|
52
|
+
"@types/node": "^24.10.1",
|
|
53
|
+
"jest": "^30.2.0",
|
|
54
|
+
"ts-jest": "^29.4.5",
|
|
55
|
+
"typescript": "^5.9.3"
|
|
56
|
+
},
|
|
57
|
+
"overrides": {
|
|
58
|
+
"glob": "^10.3.10",
|
|
59
|
+
"inflight": "^1.0.6",
|
|
60
|
+
"rimraf": "^5.0.5"
|
|
61
|
+
}
|
|
62
|
+
}
|