gigachess 0.2.1
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 +183 -0
- package/dist/attacks.d.ts +40 -0
- package/dist/attacks.d.ts.map +1 -0
- package/dist/attacks.js +389 -0
- package/dist/bishopMagicBlob.d.ts +2 -0
- package/dist/bishopMagicBlob.d.ts.map +1 -0
- package/dist/bishopMagicBlob.js +11 -0
- package/dist/board.d.ts +73 -0
- package/dist/board.d.ts.map +1 -0
- package/dist/board.js +237 -0
- package/dist/chess.d.ts +215 -0
- package/dist/chess.d.ts.map +1 -0
- package/dist/chess.js +1453 -0
- package/dist/chess960.d.ts +10 -0
- package/dist/chess960.d.ts.map +1 -0
- package/dist/chess960.js +18 -0
- package/dist/chessops/board.d.ts +49 -0
- package/dist/chessops/board.d.ts.map +1 -0
- package/dist/chessops/board.js +138 -0
- package/dist/chessops/chess.d.ts +104 -0
- package/dist/chessops/chess.d.ts.map +1 -0
- package/dist/chessops/chess.js +435 -0
- package/dist/chessops/compat.d.ts +19 -0
- package/dist/chessops/compat.d.ts.map +1 -0
- package/dist/chessops/compat.js +25 -0
- package/dist/chessops/convert.d.ts +42 -0
- package/dist/chessops/convert.d.ts.map +1 -0
- package/dist/chessops/convert.js +114 -0
- package/dist/chessops/debug.d.ts +17 -0
- package/dist/chessops/debug.d.ts.map +1 -0
- package/dist/chessops/debug.js +67 -0
- package/dist/chessops/fen.d.ts +28 -0
- package/dist/chessops/fen.d.ts.map +1 -0
- package/dist/chessops/fen.js +74 -0
- package/dist/chessops/fenInternal.d.ts +15 -0
- package/dist/chessops/fenInternal.d.ts.map +1 -0
- package/dist/chessops/fenInternal.js +42 -0
- package/dist/chessops/index.d.ts +12 -0
- package/dist/chessops/index.d.ts.map +1 -0
- package/dist/chessops/index.js +17 -0
- package/dist/chessops/san.d.ts +7 -0
- package/dist/chessops/san.d.ts.map +1 -0
- package/dist/chessops/san.js +33 -0
- package/dist/chessops/setup.d.ts +64 -0
- package/dist/chessops/setup.d.ts.map +1 -0
- package/dist/chessops/setup.js +158 -0
- package/dist/chessops/squareSet.d.ts +48 -0
- package/dist/chessops/squareSet.d.ts.map +1 -0
- package/dist/chessops/squareSet.js +192 -0
- package/dist/chessops/transform.d.ts +12 -0
- package/dist/chessops/transform.d.ts.map +1 -0
- package/dist/chessops/transform.js +53 -0
- package/dist/chessops/types.d.ts +47 -0
- package/dist/chessops/types.d.ts.map +1 -0
- package/dist/chessops/types.js +12 -0
- package/dist/chessops/util.d.ts +19 -0
- package/dist/chessops/util.d.ts.map +1 -0
- package/dist/chessops/util.js +52 -0
- package/dist/chesstree.d.ts +143 -0
- package/dist/chesstree.d.ts.map +1 -0
- package/dist/chesstree.js +514 -0
- package/dist/core.d.ts +10 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +11 -0
- package/dist/fen.d.ts +10 -0
- package/dist/fen.d.ts.map +1 -0
- package/dist/fen.js +600 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/packedMove.d.ts +31 -0
- package/dist/packedMove.d.ts.map +1 -0
- package/dist/packedMove.js +88 -0
- package/dist/pgn.d.ts +24 -0
- package/dist/pgn.d.ts.map +1 -0
- package/dist/pgn.js +361 -0
- package/dist/rookMagicBlob.d.ts +2 -0
- package/dist/rookMagicBlob.d.ts.map +1 -0
- package/dist/rookMagicBlob.js +11 -0
- package/dist/san.d.ts +6 -0
- package/dist/san.d.ts.map +1 -0
- package/dist/san.js +484 -0
- package/dist/squareSet.d.ts +48 -0
- package/dist/squareSet.d.ts.map +1 -0
- package/dist/squareSet.js +154 -0
- package/dist/types.d.ts +147 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +88 -0
- package/dist/util.d.ts +11 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +59 -0
- package/dist/zobrist.d.ts +45 -0
- package/dist/zobrist.d.ts.map +1 -0
- package/dist/zobrist.js +271 -0
- package/dist/zobristBlob.d.ts +2 -0
- package/dist/zobristBlob.d.ts.map +1 -0
- package/dist/zobristBlob.js +11 -0
- package/package.json +135 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// src/squareSet.ts — {lo,hi} pair, pure ops, target ES2020
|
|
2
|
+
// Language-neutral spec: lo bits 0..31 -> A1..H4, hi bits 0..31 -> A5..H8
|
|
3
|
+
// MIT turbochess, clean-room from specs + FIDE notes + magic-bits/RecklessMagics JSON (no G P L)
|
|
4
|
+
// Constants — note >>>0 ensures unsigned 32
|
|
5
|
+
export const EMPTY = { lo: 0, hi: 0 };
|
|
6
|
+
export const FULL = { lo: 0xffffffff >>> 0, hi: 0xffffffff >>> 0 };
|
|
7
|
+
export function empty() {
|
|
8
|
+
return { lo: 0, hi: 0 };
|
|
9
|
+
}
|
|
10
|
+
export function full() {
|
|
11
|
+
return { lo: 0xffffffff >>> 0, hi: 0xffffffff >>> 0 };
|
|
12
|
+
}
|
|
13
|
+
export function singleton(sq) {
|
|
14
|
+
if (sq < 32)
|
|
15
|
+
return { lo: (1 << sq) >>> 0, hi: 0 };
|
|
16
|
+
return { lo: 0, hi: (1 << (sq - 32)) >>> 0 };
|
|
17
|
+
}
|
|
18
|
+
export function has(set, sq) {
|
|
19
|
+
if (sq < 32)
|
|
20
|
+
return (set.lo & (1 << sq)) !== 0;
|
|
21
|
+
return (set.hi & (1 << (sq - 32))) !== 0;
|
|
22
|
+
}
|
|
23
|
+
export function and(a, b) {
|
|
24
|
+
return { lo: (a.lo & b.lo) >>> 0, hi: (a.hi & b.hi) >>> 0 };
|
|
25
|
+
}
|
|
26
|
+
export function or(a, b) {
|
|
27
|
+
return { lo: (a.lo | b.lo) >>> 0, hi: (a.hi | b.hi) >>> 0 };
|
|
28
|
+
}
|
|
29
|
+
export function xor(a, b) {
|
|
30
|
+
return { lo: (a.lo ^ b.lo) >>> 0, hi: (a.hi ^ b.hi) >>> 0 };
|
|
31
|
+
}
|
|
32
|
+
export function not(a) {
|
|
33
|
+
return { lo: (~a.lo) >>> 0, hi: (~a.hi) >>> 0 };
|
|
34
|
+
}
|
|
35
|
+
export function complement(a) {
|
|
36
|
+
return not(a);
|
|
37
|
+
}
|
|
38
|
+
export function minus(a, b) {
|
|
39
|
+
return and(a, not(b));
|
|
40
|
+
}
|
|
41
|
+
export function shl(set, n) {
|
|
42
|
+
if (n === 0)
|
|
43
|
+
return { lo: set.lo >>> 0, hi: set.hi >>> 0 };
|
|
44
|
+
if (n < 0 || n >= 64)
|
|
45
|
+
return empty();
|
|
46
|
+
if (n < 32) {
|
|
47
|
+
const lo = (set.lo << n) >>> 0;
|
|
48
|
+
const hi = (((set.hi << n) >>> 0) | (set.lo >>> (32 - n))) >>> 0;
|
|
49
|
+
return { lo, hi };
|
|
50
|
+
}
|
|
51
|
+
// 32 <= n < 64
|
|
52
|
+
const hi = (set.lo << (n - 32)) >>> 0;
|
|
53
|
+
return { lo: 0, hi };
|
|
54
|
+
}
|
|
55
|
+
export function shr(set, n) {
|
|
56
|
+
if (n === 0)
|
|
57
|
+
return { lo: set.lo >>> 0, hi: set.hi >>> 0 };
|
|
58
|
+
if (n < 0 || n >= 64)
|
|
59
|
+
return empty();
|
|
60
|
+
if (n < 32) {
|
|
61
|
+
const hi = set.hi >>> n;
|
|
62
|
+
const lo = (((set.lo >>> n) | (set.hi << (32 - n))) >>> 0);
|
|
63
|
+
return { lo: lo >>> 0, hi: hi >>> 0 };
|
|
64
|
+
}
|
|
65
|
+
const lo = set.hi >>> (n - 32);
|
|
66
|
+
return { lo: lo >>> 0, hi: 0 };
|
|
67
|
+
}
|
|
68
|
+
function popcnt32(x) {
|
|
69
|
+
x = x - ((x >>> 1) & 0x55555555);
|
|
70
|
+
x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
|
|
71
|
+
// Math.imul keeps the multiply in exact int32 domain (the old `*` went
|
|
72
|
+
// through double-precision and cost a ToNumber round-trip in V8).
|
|
73
|
+
return Math.imul((x + (x >>> 4)) & 0x0f0f0f0f, 0x01010101) >>> 24;
|
|
74
|
+
}
|
|
75
|
+
export function popcount(set) {
|
|
76
|
+
return popcnt32(set.lo >>> 0) + popcnt32(set.hi >>> 0);
|
|
77
|
+
}
|
|
78
|
+
// alias per spec table
|
|
79
|
+
export const popcnt = popcount;
|
|
80
|
+
export function first(set) {
|
|
81
|
+
if (set.lo !== 0) {
|
|
82
|
+
const lo = set.lo >>> 0;
|
|
83
|
+
// isolate lowest bit
|
|
84
|
+
const lsb = (lo & -lo) >>> 0;
|
|
85
|
+
return 31 - Math.clz32(lsb);
|
|
86
|
+
}
|
|
87
|
+
if (set.hi !== 0) {
|
|
88
|
+
const hi = set.hi >>> 0;
|
|
89
|
+
const lsb = (hi & -hi) >>> 0;
|
|
90
|
+
return 32 + (31 - Math.clz32(lsb));
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
export function moreThanOne(set) {
|
|
95
|
+
// fast path without full popcnt
|
|
96
|
+
const lo = set.lo >>> 0;
|
|
97
|
+
const hi = set.hi >>> 0;
|
|
98
|
+
// if both halves have bits -> at least 2?
|
|
99
|
+
// but need precisely >1
|
|
100
|
+
// check if lo has >1 or hi has >1 or both have >=1
|
|
101
|
+
if (lo !== 0 && hi !== 0)
|
|
102
|
+
return true;
|
|
103
|
+
const v = lo !== 0 ? lo : hi;
|
|
104
|
+
return (v & (v - 1)) !== 0;
|
|
105
|
+
}
|
|
106
|
+
export function isEmpty(set) {
|
|
107
|
+
return set.lo === 0 && set.hi === 0;
|
|
108
|
+
}
|
|
109
|
+
export function isNonEmpty(set) {
|
|
110
|
+
return !isEmpty(set);
|
|
111
|
+
}
|
|
112
|
+
export function equals(a, b) {
|
|
113
|
+
return (a.lo >>> 0) === (b.lo >>> 0) && (a.hi >>> 0) === (b.hi >>> 0);
|
|
114
|
+
}
|
|
115
|
+
export function* iter(set) {
|
|
116
|
+
let cur = { lo: set.lo >>> 0, hi: set.hi >>> 0 };
|
|
117
|
+
let sq;
|
|
118
|
+
while ((sq = first(cur)) !== undefined) {
|
|
119
|
+
yield sq;
|
|
120
|
+
cur = minus(cur, singleton(sq));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Non-generator square iteration for hot loops. `iter` allocates 2 objects per
|
|
125
|
+
* square (minus + singleton) plus the generator machinery; this allocates
|
|
126
|
+
* nothing. Prefer `forEachSquare` over `for...of sq.iter(...)` wherever the
|
|
127
|
+
* callback can be a plain statement (see board.ts FP policy).
|
|
128
|
+
*/
|
|
129
|
+
export function forEachSquare(set, fn) {
|
|
130
|
+
let lo = set.lo >>> 0;
|
|
131
|
+
while (lo !== 0) {
|
|
132
|
+
const lsb = (lo & -lo) >>> 0;
|
|
133
|
+
fn(31 - Math.clz32(lsb));
|
|
134
|
+
lo ^= lsb;
|
|
135
|
+
}
|
|
136
|
+
let hi = set.hi >>> 0;
|
|
137
|
+
while (hi !== 0) {
|
|
138
|
+
const lsb = (hi & -hi) >>> 0;
|
|
139
|
+
fn(32 + (31 - Math.clz32(lsb)));
|
|
140
|
+
hi ^= lsb;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// convenience for between/ray
|
|
144
|
+
export function size(set) {
|
|
145
|
+
return popcount(set);
|
|
146
|
+
}
|
|
147
|
+
// diff / without helpers
|
|
148
|
+
export function diff(a, b) {
|
|
149
|
+
return minus(a, b);
|
|
150
|
+
}
|
|
151
|
+
// for debugging / compat
|
|
152
|
+
export function toString(set) {
|
|
153
|
+
return `{ lo: 0x${(set.lo >>> 0).toString(16).padStart(8, "0")}, hi: 0x${(set.hi >>> 0).toString(16).padStart(8, "0")} }`;
|
|
154
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export declare const enum Color {
|
|
2
|
+
White = 0,
|
|
3
|
+
Black = 1
|
|
4
|
+
}
|
|
5
|
+
export declare const enum Role {
|
|
6
|
+
Pawn = 0,
|
|
7
|
+
Knight = 1,
|
|
8
|
+
Bishop = 2,
|
|
9
|
+
Rook = 3,
|
|
10
|
+
Queen = 4,
|
|
11
|
+
King = 5
|
|
12
|
+
}
|
|
13
|
+
export declare const enum Square {
|
|
14
|
+
A1 = 0,
|
|
15
|
+
B1 = 1,
|
|
16
|
+
C1 = 2,
|
|
17
|
+
D1 = 3,
|
|
18
|
+
E1 = 4,
|
|
19
|
+
F1 = 5,
|
|
20
|
+
G1 = 6,
|
|
21
|
+
H1 = 7,
|
|
22
|
+
A2 = 8,
|
|
23
|
+
B2 = 9,
|
|
24
|
+
C2 = 10,
|
|
25
|
+
D2 = 11,
|
|
26
|
+
E2 = 12,
|
|
27
|
+
F2 = 13,
|
|
28
|
+
G2 = 14,
|
|
29
|
+
H2 = 15,
|
|
30
|
+
A3 = 16,
|
|
31
|
+
B3 = 17,
|
|
32
|
+
C3 = 18,
|
|
33
|
+
D3 = 19,
|
|
34
|
+
E3 = 20,
|
|
35
|
+
F3 = 21,
|
|
36
|
+
G3 = 22,
|
|
37
|
+
H3 = 23,
|
|
38
|
+
A4 = 24,
|
|
39
|
+
B4 = 25,
|
|
40
|
+
C4 = 26,
|
|
41
|
+
D4 = 27,
|
|
42
|
+
E4 = 28,
|
|
43
|
+
F4 = 29,
|
|
44
|
+
G4 = 30,
|
|
45
|
+
H4 = 31,
|
|
46
|
+
A5 = 32,
|
|
47
|
+
B5 = 33,
|
|
48
|
+
C5 = 34,
|
|
49
|
+
D5 = 35,
|
|
50
|
+
E5 = 36,
|
|
51
|
+
F5 = 37,
|
|
52
|
+
G5 = 38,
|
|
53
|
+
H5 = 39,
|
|
54
|
+
A6 = 40,
|
|
55
|
+
B6 = 41,
|
|
56
|
+
C6 = 42,
|
|
57
|
+
D6 = 43,
|
|
58
|
+
E6 = 44,
|
|
59
|
+
F6 = 45,
|
|
60
|
+
G6 = 46,
|
|
61
|
+
H6 = 47,
|
|
62
|
+
A7 = 48,
|
|
63
|
+
B7 = 49,
|
|
64
|
+
C7 = 50,
|
|
65
|
+
D7 = 51,
|
|
66
|
+
E7 = 52,
|
|
67
|
+
F7 = 53,
|
|
68
|
+
G7 = 54,
|
|
69
|
+
H7 = 55,
|
|
70
|
+
A8 = 56,
|
|
71
|
+
B8 = 57,
|
|
72
|
+
C8 = 58,
|
|
73
|
+
D8 = 59,
|
|
74
|
+
E8 = 60,
|
|
75
|
+
F8 = 61,
|
|
76
|
+
G8 = 62,
|
|
77
|
+
H8 = 63
|
|
78
|
+
}
|
|
79
|
+
export type Piece = {
|
|
80
|
+
readonly color: Color;
|
|
81
|
+
readonly role: Role;
|
|
82
|
+
};
|
|
83
|
+
export type CastlingSide = "king" | "queen";
|
|
84
|
+
export type CastlingRights = {
|
|
85
|
+
readonly white: ReadonlySet<number>;
|
|
86
|
+
readonly black: ReadonlySet<number>;
|
|
87
|
+
readonly whiteKing: boolean;
|
|
88
|
+
readonly whiteQueen: boolean;
|
|
89
|
+
readonly blackKing: boolean;
|
|
90
|
+
readonly blackQueen: boolean;
|
|
91
|
+
};
|
|
92
|
+
export type Setup = {
|
|
93
|
+
readonly board: import("./board.js").Board;
|
|
94
|
+
readonly turn: Color;
|
|
95
|
+
readonly castling: CastlingRights;
|
|
96
|
+
readonly epSquare: number | null;
|
|
97
|
+
readonly halfmoves: number;
|
|
98
|
+
readonly fullmoves: number;
|
|
99
|
+
readonly halfmove?: number;
|
|
100
|
+
readonly fullmove?: number;
|
|
101
|
+
readonly zobristLo?: number;
|
|
102
|
+
readonly zobristHi?: number;
|
|
103
|
+
};
|
|
104
|
+
export type Position = Setup;
|
|
105
|
+
export type NormalMove = {
|
|
106
|
+
from: number;
|
|
107
|
+
to: number;
|
|
108
|
+
capture?: number | null;
|
|
109
|
+
promotion?: Role | null;
|
|
110
|
+
};
|
|
111
|
+
export type DropMove = NormalMove;
|
|
112
|
+
export type Move = NormalMove & {
|
|
113
|
+
isEnPassant?: boolean;
|
|
114
|
+
isCastling?: boolean;
|
|
115
|
+
isPromotion?: boolean;
|
|
116
|
+
};
|
|
117
|
+
export type Outcome = "white" | "black" | "draw" | "*";
|
|
118
|
+
export type Result<T, E> = {
|
|
119
|
+
ok: true;
|
|
120
|
+
value: T;
|
|
121
|
+
} | {
|
|
122
|
+
ok: false;
|
|
123
|
+
error: E;
|
|
124
|
+
};
|
|
125
|
+
export declare function Ok<T, E>(value: T): Result<T, E>;
|
|
126
|
+
export declare function Err<T, E>(error: E): Result<T, E>;
|
|
127
|
+
export type FenError = {
|
|
128
|
+
code: string;
|
|
129
|
+
message?: string;
|
|
130
|
+
};
|
|
131
|
+
export type SanError = {
|
|
132
|
+
code: string;
|
|
133
|
+
message?: string;
|
|
134
|
+
};
|
|
135
|
+
export type UciError = {
|
|
136
|
+
code: string;
|
|
137
|
+
message?: string;
|
|
138
|
+
};
|
|
139
|
+
export type PgnError = {
|
|
140
|
+
code: string;
|
|
141
|
+
message?: string;
|
|
142
|
+
};
|
|
143
|
+
export type MoveError = {
|
|
144
|
+
code: string;
|
|
145
|
+
message?: string;
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,0BAAkB,KAAK;IACrB,KAAK,IAAI;IACT,KAAK,IAAI;CACV;AAED,0BAAkB,IAAI;IACpB,IAAI,IAAI;IACR,MAAM,IAAI;IACV,MAAM,IAAI;IACV,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;CACT;AAED,0BAAkB,MAAM;IACtB,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAC9D,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE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GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;AAEvD,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE5E,wBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAE/C;AACD,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAEhD;AAGD,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/types.ts — language-neutral chess types, const enum inlined per ADR-012
|
|
2
|
+
export var Color;
|
|
3
|
+
(function (Color) {
|
|
4
|
+
Color[Color["White"] = 0] = "White";
|
|
5
|
+
Color[Color["Black"] = 1] = "Black";
|
|
6
|
+
})(Color || (Color = {}));
|
|
7
|
+
export var Role;
|
|
8
|
+
(function (Role) {
|
|
9
|
+
Role[Role["Pawn"] = 0] = "Pawn";
|
|
10
|
+
Role[Role["Knight"] = 1] = "Knight";
|
|
11
|
+
Role[Role["Bishop"] = 2] = "Bishop";
|
|
12
|
+
Role[Role["Rook"] = 3] = "Rook";
|
|
13
|
+
Role[Role["Queen"] = 4] = "Queen";
|
|
14
|
+
Role[Role["King"] = 5] = "King";
|
|
15
|
+
})(Role || (Role = {}));
|
|
16
|
+
export var Square;
|
|
17
|
+
(function (Square) {
|
|
18
|
+
Square[Square["A1"] = 0] = "A1";
|
|
19
|
+
Square[Square["B1"] = 1] = "B1";
|
|
20
|
+
Square[Square["C1"] = 2] = "C1";
|
|
21
|
+
Square[Square["D1"] = 3] = "D1";
|
|
22
|
+
Square[Square["E1"] = 4] = "E1";
|
|
23
|
+
Square[Square["F1"] = 5] = "F1";
|
|
24
|
+
Square[Square["G1"] = 6] = "G1";
|
|
25
|
+
Square[Square["H1"] = 7] = "H1";
|
|
26
|
+
Square[Square["A2"] = 8] = "A2";
|
|
27
|
+
Square[Square["B2"] = 9] = "B2";
|
|
28
|
+
Square[Square["C2"] = 10] = "C2";
|
|
29
|
+
Square[Square["D2"] = 11] = "D2";
|
|
30
|
+
Square[Square["E2"] = 12] = "E2";
|
|
31
|
+
Square[Square["F2"] = 13] = "F2";
|
|
32
|
+
Square[Square["G2"] = 14] = "G2";
|
|
33
|
+
Square[Square["H2"] = 15] = "H2";
|
|
34
|
+
Square[Square["A3"] = 16] = "A3";
|
|
35
|
+
Square[Square["B3"] = 17] = "B3";
|
|
36
|
+
Square[Square["C3"] = 18] = "C3";
|
|
37
|
+
Square[Square["D3"] = 19] = "D3";
|
|
38
|
+
Square[Square["E3"] = 20] = "E3";
|
|
39
|
+
Square[Square["F3"] = 21] = "F3";
|
|
40
|
+
Square[Square["G3"] = 22] = "G3";
|
|
41
|
+
Square[Square["H3"] = 23] = "H3";
|
|
42
|
+
Square[Square["A4"] = 24] = "A4";
|
|
43
|
+
Square[Square["B4"] = 25] = "B4";
|
|
44
|
+
Square[Square["C4"] = 26] = "C4";
|
|
45
|
+
Square[Square["D4"] = 27] = "D4";
|
|
46
|
+
Square[Square["E4"] = 28] = "E4";
|
|
47
|
+
Square[Square["F4"] = 29] = "F4";
|
|
48
|
+
Square[Square["G4"] = 30] = "G4";
|
|
49
|
+
Square[Square["H4"] = 31] = "H4";
|
|
50
|
+
Square[Square["A5"] = 32] = "A5";
|
|
51
|
+
Square[Square["B5"] = 33] = "B5";
|
|
52
|
+
Square[Square["C5"] = 34] = "C5";
|
|
53
|
+
Square[Square["D5"] = 35] = "D5";
|
|
54
|
+
Square[Square["E5"] = 36] = "E5";
|
|
55
|
+
Square[Square["F5"] = 37] = "F5";
|
|
56
|
+
Square[Square["G5"] = 38] = "G5";
|
|
57
|
+
Square[Square["H5"] = 39] = "H5";
|
|
58
|
+
Square[Square["A6"] = 40] = "A6";
|
|
59
|
+
Square[Square["B6"] = 41] = "B6";
|
|
60
|
+
Square[Square["C6"] = 42] = "C6";
|
|
61
|
+
Square[Square["D6"] = 43] = "D6";
|
|
62
|
+
Square[Square["E6"] = 44] = "E6";
|
|
63
|
+
Square[Square["F6"] = 45] = "F6";
|
|
64
|
+
Square[Square["G6"] = 46] = "G6";
|
|
65
|
+
Square[Square["H6"] = 47] = "H6";
|
|
66
|
+
Square[Square["A7"] = 48] = "A7";
|
|
67
|
+
Square[Square["B7"] = 49] = "B7";
|
|
68
|
+
Square[Square["C7"] = 50] = "C7";
|
|
69
|
+
Square[Square["D7"] = 51] = "D7";
|
|
70
|
+
Square[Square["E7"] = 52] = "E7";
|
|
71
|
+
Square[Square["F7"] = 53] = "F7";
|
|
72
|
+
Square[Square["G7"] = 54] = "G7";
|
|
73
|
+
Square[Square["H7"] = 55] = "H7";
|
|
74
|
+
Square[Square["A8"] = 56] = "A8";
|
|
75
|
+
Square[Square["B8"] = 57] = "B8";
|
|
76
|
+
Square[Square["C8"] = 58] = "C8";
|
|
77
|
+
Square[Square["D8"] = 59] = "D8";
|
|
78
|
+
Square[Square["E8"] = 60] = "E8";
|
|
79
|
+
Square[Square["F8"] = 61] = "F8";
|
|
80
|
+
Square[Square["G8"] = 62] = "G8";
|
|
81
|
+
Square[Square["H8"] = 63] = "H8";
|
|
82
|
+
})(Square || (Square = {}));
|
|
83
|
+
export function Ok(value) {
|
|
84
|
+
return { ok: true, value };
|
|
85
|
+
}
|
|
86
|
+
export function Err(error) {
|
|
87
|
+
return { ok: false, error };
|
|
88
|
+
}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Color } from "./types.js";
|
|
2
|
+
export declare function opposite(c: Color): Color;
|
|
3
|
+
export declare function squareFile(sq: number): number;
|
|
4
|
+
export declare function squareRank(sq: number): number;
|
|
5
|
+
export declare function squareFromCoords(file: number, rank: number): number;
|
|
6
|
+
export declare function squareName(sq: number): string;
|
|
7
|
+
export declare function parseSquare(name: string): number | undefined;
|
|
8
|
+
export declare function roleToChar(role: number): string;
|
|
9
|
+
export declare function charToRole(ch: string): number | undefined;
|
|
10
|
+
export declare function colorToChar(c: Color): string;
|
|
11
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAExC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM5D;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW/C;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASzD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAE5C"}
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/util.ts — pure helpers for square/file/rank/color, no G P L
|
|
2
|
+
import { Color } from "./types.js";
|
|
3
|
+
export function opposite(c) {
|
|
4
|
+
return c === Color.White ? Color.Black : Color.White;
|
|
5
|
+
}
|
|
6
|
+
export function squareFile(sq) {
|
|
7
|
+
return sq & 7;
|
|
8
|
+
}
|
|
9
|
+
export function squareRank(sq) {
|
|
10
|
+
return sq >> 3;
|
|
11
|
+
}
|
|
12
|
+
export function squareFromCoords(file, rank) {
|
|
13
|
+
return (rank << 3) | file;
|
|
14
|
+
}
|
|
15
|
+
export function squareName(sq) {
|
|
16
|
+
const f = String.fromCharCode(97 + (sq & 7));
|
|
17
|
+
const r = String.fromCharCode(49 + (sq >> 3));
|
|
18
|
+
return f + r;
|
|
19
|
+
}
|
|
20
|
+
export function parseSquare(name) {
|
|
21
|
+
if (name.length !== 2)
|
|
22
|
+
return undefined;
|
|
23
|
+
const f = name.charCodeAt(0) - 97;
|
|
24
|
+
const r = name.charCodeAt(1) - 49;
|
|
25
|
+
if (f < 0 || f > 7 || r < 0 || r > 7)
|
|
26
|
+
return undefined;
|
|
27
|
+
return (r << 3) | f;
|
|
28
|
+
}
|
|
29
|
+
export function roleToChar(role) {
|
|
30
|
+
// Role enum order Pawn=0 etc
|
|
31
|
+
switch (role) {
|
|
32
|
+
case 0: return "p";
|
|
33
|
+
case 1: return "n";
|
|
34
|
+
case 2: return "b";
|
|
35
|
+
case 3: return "r";
|
|
36
|
+
case 4: return "q";
|
|
37
|
+
case 5: return "k";
|
|
38
|
+
default: return "?";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function charToRole(ch) {
|
|
42
|
+
const c = ch.toLowerCase();
|
|
43
|
+
if (c === "p")
|
|
44
|
+
return 0;
|
|
45
|
+
if (c === "n")
|
|
46
|
+
return 1;
|
|
47
|
+
if (c === "b")
|
|
48
|
+
return 2;
|
|
49
|
+
if (c === "r")
|
|
50
|
+
return 3;
|
|
51
|
+
if (c === "q")
|
|
52
|
+
return 4;
|
|
53
|
+
if (c === "k")
|
|
54
|
+
return 5;
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
export function colorToChar(c) {
|
|
58
|
+
return c === Color.White ? "w" : "b";
|
|
59
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Color, Role } from "./types.js";
|
|
2
|
+
import type { Position } from "./types.js";
|
|
3
|
+
export type ZobristKey = {
|
|
4
|
+
readonly lo: number;
|
|
5
|
+
readonly hi: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Loads the Polyglot key blob (idempotent). Safe to call repeatedly; the
|
|
9
|
+
* returned promise resolves once the tables are available. Failures propagate
|
|
10
|
+
* to awaiting callers but never become unhandled rejections.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureZobristLoaded(): Promise<void>;
|
|
13
|
+
/** Whether the Zobrist tables are loaded (false ⇒ hashing is skipped). */
|
|
14
|
+
export declare function zobristTablesLoaded(): boolean;
|
|
15
|
+
/** Computes the Zobrist key from scratch (O(pieces)). Tables must be loaded. */
|
|
16
|
+
export declare function calculateZobrist(pos: Position): ZobristKey;
|
|
17
|
+
/**
|
|
18
|
+
* Incremental O(1) Zobrist update for a move (design D2). Given the OLD
|
|
19
|
+
* position (which must either carry a zobrist key or be hashable from
|
|
20
|
+
* scratch), the move details as resolved by makeMove (castling plan,
|
|
21
|
+
* en-passant flag, captured piece) and the NEW position (turn / castling /
|
|
22
|
+
* ep / board already updated), returns the key for the new position.
|
|
23
|
+
* Tables must be loaded.
|
|
24
|
+
*
|
|
25
|
+
* - `plan` non-null => castling: king to plan.kingTo, rook rookFrom -> rookTo
|
|
26
|
+
* - `isEnPassant` => the captured pawn sits behind the ep target square
|
|
27
|
+
* - `captured` non-null => ordinary capture ON the `to` square
|
|
28
|
+
*/
|
|
29
|
+
export declare function zobristAfterMove(pos: Position, move: {
|
|
30
|
+
from: number;
|
|
31
|
+
to: number;
|
|
32
|
+
promotion?: Role | null;
|
|
33
|
+
}, plan: {
|
|
34
|
+
side: "king" | "queen";
|
|
35
|
+
kingFrom: number;
|
|
36
|
+
kingTo: number;
|
|
37
|
+
rookFrom: number;
|
|
38
|
+
rookTo: number;
|
|
39
|
+
} | null, isEnPassant: boolean, captured: {
|
|
40
|
+
color: Color;
|
|
41
|
+
role: Role;
|
|
42
|
+
} | undefined, newPos: Position): ZobristKey;
|
|
43
|
+
/** 16-hex-digit rendering of a {lo,hi} key (hi first, zero-padded). */
|
|
44
|
+
export declare function zobristHex(key: ZobristKey): string;
|
|
45
|
+
//# sourceMappingURL=zobrist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zobrist.d.ts","sourceRoot":"","sources":["../src/zobrist.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAWtE;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAoBnD;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,IAAI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