@maxr0ssi/chaos-chess 0.2.0 → 0.2.2
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 +32 -0
- package/THIRD_PARTY_NOTICES.md +36 -0
- package/dist/chaos-chess.css +1 -1
- package/dist/chaos-chess.js +649 -607
- package/dist/chaos-chess.js.map +1 -1
- package/package.json +3 -2
package/dist/chaos-chess.js
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
1
|
-
import { jsx as l, jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { Chess as
|
|
4
|
-
|
|
1
|
+
import { jsx as l, jsxs as L } from "react/jsx-runtime";
|
|
2
|
+
import Nt, { useState as k, useRef as w, useCallback as S, useEffect as B, useLayoutEffect as ot } from "react";
|
|
3
|
+
import { Chess as de } from "chess.js";
|
|
4
|
+
/*! @maxr0ssi/chaos-chess. Piece artwork: "Cburnett" set (c) Colin M.L. Burnett, BSD-3-Clause; full text in THIRD_PARTY_NOTICES.md. */
|
|
5
|
+
const At = {
|
|
5
6
|
p: 1,
|
|
6
7
|
n: 3,
|
|
7
8
|
b: 3,
|
|
8
9
|
r: 5,
|
|
9
10
|
q: 9,
|
|
10
11
|
k: 0
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
wq: "♛︎",
|
|
14
|
-
wr: "♜︎",
|
|
15
|
-
wb: "♝︎",
|
|
16
|
-
wn: "♞︎",
|
|
17
|
-
wp: "♟︎",
|
|
18
|
-
bk: "♔︎",
|
|
19
|
-
bq: "♕︎",
|
|
20
|
-
br: "♖︎",
|
|
21
|
-
bb: "♗︎",
|
|
22
|
-
bn: "♘︎",
|
|
23
|
-
bp: "♙︎"
|
|
24
|
-
}, Te = "abcdefgh";
|
|
25
|
-
function K(t) {
|
|
12
|
+
}, Le = "abcdefgh";
|
|
13
|
+
function Y(t) {
|
|
26
14
|
const e = t.trim().split(/\s+/);
|
|
27
15
|
return {
|
|
28
16
|
position: e[0],
|
|
@@ -33,233 +21,233 @@ function K(t) {
|
|
|
33
21
|
fullmove: e[5] ?? "1"
|
|
34
22
|
};
|
|
35
23
|
}
|
|
36
|
-
function
|
|
24
|
+
function K(t) {
|
|
37
25
|
const e = [], n = t.split("/");
|
|
38
26
|
for (const r of n) {
|
|
39
|
-
const
|
|
40
|
-
for (const
|
|
41
|
-
const a = parseInt(
|
|
27
|
+
const i = [];
|
|
28
|
+
for (const s of r) {
|
|
29
|
+
const a = parseInt(s);
|
|
42
30
|
if (isNaN(a)) {
|
|
43
|
-
const o =
|
|
44
|
-
|
|
31
|
+
const o = s === s.toUpperCase() ? "w" : "b", c = s.toLowerCase();
|
|
32
|
+
i.push({ type: c, color: o });
|
|
45
33
|
} else
|
|
46
|
-
for (let o = 0; o < a; o++)
|
|
34
|
+
for (let o = 0; o < a; o++) i.push(null);
|
|
47
35
|
}
|
|
48
|
-
e.push(
|
|
36
|
+
e.push(i);
|
|
49
37
|
}
|
|
50
38
|
return e;
|
|
51
39
|
}
|
|
52
40
|
function at(t) {
|
|
53
41
|
return t.map((e) => {
|
|
54
42
|
let n = "", r = 0;
|
|
55
|
-
for (const
|
|
56
|
-
if (
|
|
43
|
+
for (const i of e)
|
|
44
|
+
if (i === null)
|
|
57
45
|
r++;
|
|
58
46
|
else {
|
|
59
47
|
r > 0 && (n += r, r = 0);
|
|
60
|
-
const
|
|
61
|
-
n +=
|
|
48
|
+
const s = i.color === "w" ? i.type.toUpperCase() : i.type;
|
|
49
|
+
n += s;
|
|
62
50
|
}
|
|
63
51
|
return r > 0 && (n += r), n;
|
|
64
52
|
}).join("/");
|
|
65
53
|
}
|
|
66
|
-
function
|
|
54
|
+
function Ee(t) {
|
|
67
55
|
return `${t.position} ${t.activeColor} ${t.castling} ${t.enPassant} ${t.halfmove} ${t.fullmove}`;
|
|
68
56
|
}
|
|
69
|
-
function
|
|
70
|
-
const { position: e } =
|
|
71
|
-
let r = 0,
|
|
72
|
-
for (const
|
|
73
|
-
for (const a of
|
|
57
|
+
function Et(t) {
|
|
58
|
+
const { position: e } = Y(t), n = K(e);
|
|
59
|
+
let r = 0, i = 0;
|
|
60
|
+
for (const s of n)
|
|
61
|
+
for (const a of s)
|
|
74
62
|
if (a) {
|
|
75
|
-
const o =
|
|
76
|
-
a.color === "w" ? r += o :
|
|
63
|
+
const o = At[a.type];
|
|
64
|
+
a.color === "w" ? r += o : i += o;
|
|
77
65
|
}
|
|
78
|
-
return { white: r, black:
|
|
66
|
+
return { white: r, black: i };
|
|
79
67
|
}
|
|
80
|
-
function
|
|
81
|
-
const { position: e } =
|
|
82
|
-
for (let
|
|
83
|
-
for (let
|
|
84
|
-
n[
|
|
68
|
+
function It(t) {
|
|
69
|
+
const { position: e } = Y(t), n = K(e), r = [];
|
|
70
|
+
for (let i = 0; i < 8; i++)
|
|
71
|
+
for (let s = 0; s < 8; s++)
|
|
72
|
+
n[i][s] === null && r.push(`${Le[s]}${8 - i}`);
|
|
85
73
|
return r;
|
|
86
74
|
}
|
|
87
|
-
function
|
|
88
|
-
const { position: r } =
|
|
75
|
+
function Ft(t, e, n = !0) {
|
|
76
|
+
const { position: r } = Y(t), i = K(r), s = [];
|
|
89
77
|
for (let a = 0; a < 8; a++)
|
|
90
78
|
for (let o = 0; o < 8; o++) {
|
|
91
|
-
const c =
|
|
79
|
+
const c = i[a][o];
|
|
92
80
|
if (c && c.color === e) {
|
|
93
81
|
if (n && c.type === "k") continue;
|
|
94
|
-
|
|
82
|
+
s.push(`${Le[o]}${8 - a}`);
|
|
95
83
|
}
|
|
96
84
|
}
|
|
97
|
-
return
|
|
85
|
+
return s;
|
|
98
86
|
}
|
|
99
|
-
function
|
|
100
|
-
const e =
|
|
87
|
+
function Ie(t) {
|
|
88
|
+
const e = Le.indexOf(t[0]);
|
|
101
89
|
return [8 - parseInt(t[1]), e];
|
|
102
90
|
}
|
|
103
|
-
function
|
|
104
|
-
const
|
|
105
|
-
return
|
|
91
|
+
function xt(t, e, n, r) {
|
|
92
|
+
const i = Y(t), s = K(i.position), [a, o] = Ie(e);
|
|
93
|
+
return s[a][o] = { type: n, color: r }, i.position = at(s), W(Ee(i));
|
|
106
94
|
}
|
|
107
|
-
function
|
|
108
|
-
const n =
|
|
109
|
-
return r[
|
|
95
|
+
function $t(t, e) {
|
|
96
|
+
const n = Y(t), r = K(n.position), [i, s] = Ie(e);
|
|
97
|
+
return r[i][s] = null, n.position = at(r), W(Ee(n));
|
|
110
98
|
}
|
|
111
|
-
const
|
|
99
|
+
const Dt = {
|
|
112
100
|
K: ["e1", "h1", "w"],
|
|
113
101
|
Q: ["e1", "a1", "w"],
|
|
114
102
|
k: ["e8", "h8", "b"],
|
|
115
103
|
q: ["e8", "a8", "b"]
|
|
116
104
|
};
|
|
117
105
|
function le(t, e) {
|
|
118
|
-
const [n, r] =
|
|
106
|
+
const [n, r] = Ie(e);
|
|
119
107
|
return t[n]?.[r] ?? null;
|
|
120
108
|
}
|
|
121
109
|
function ct(t, e) {
|
|
122
110
|
return !t || t === "-" ? "-" : ["K", "Q", "k", "q"].filter((r) => {
|
|
123
111
|
if (!t.includes(r)) return !1;
|
|
124
|
-
const
|
|
125
|
-
return c?.type === "k" && c.color === o &&
|
|
112
|
+
const i = Dt[r], [s, a, o] = i, c = le(e, s), m = le(e, a);
|
|
113
|
+
return c?.type === "k" && c.color === o && m?.type === "r" && m.color === o;
|
|
126
114
|
}).join("") || "-";
|
|
127
115
|
}
|
|
128
116
|
function lt(t, e, n) {
|
|
129
117
|
if (!t || t === "-") return "-";
|
|
130
|
-
const r = t[0],
|
|
131
|
-
if (!
|
|
132
|
-
const a = e === "w" ? 5 : 4, o = e === "w" ? 7 : 2, c = le(n, `${r}${a}`),
|
|
133
|
-
return c?.type !== "p" || c.color !==
|
|
118
|
+
const r = t[0], i = parseInt(t[1]), s = e === "w" ? 6 : 3;
|
|
119
|
+
if (!Le.includes(r) || i !== s) return "-";
|
|
120
|
+
const a = e === "w" ? 5 : 4, o = e === "w" ? 7 : 2, c = le(n, `${r}${a}`), m = e === "w" ? "b" : "w";
|
|
121
|
+
return c?.type !== "p" || c.color !== m || le(n, t) !== null || le(n, `${r}${o}`) !== null ? "-" : t;
|
|
134
122
|
}
|
|
135
|
-
function
|
|
136
|
-
const e =
|
|
137
|
-
return e.castling = ct(e.castling, n), e.enPassant = lt(e.enPassant, e.activeColor, n),
|
|
123
|
+
function W(t) {
|
|
124
|
+
const e = Y(t), n = K(e.position);
|
|
125
|
+
return e.castling = ct(e.castling, n), e.enPassant = lt(e.enPassant, e.activeColor, n), Ee(e);
|
|
138
126
|
}
|
|
139
127
|
function ue(t) {
|
|
140
128
|
const e = t.findPiece({ type: "k", color: "w" }).length > 0, n = t.findPiece({ type: "k", color: "b" }).length > 0;
|
|
141
129
|
return !e || !n ? { isGameOver: !0, result: "king-captured", winner: e ? "w" : n ? "b" : null, inCheck: null } : t.isGameOver() ? t.isCheckmate() ? { isGameOver: !0, result: "checkmate", winner: t.turn() === "w" ? "b" : "w", inCheck: t.turn() } : t.isStalemate() ? { isGameOver: !0, result: "stalemate", winner: null, inCheck: null } : t.isInsufficientMaterial() ? { isGameOver: !0, result: "insufficient", winner: null, inCheck: null } : t.isThreefoldRepetition() ? { isGameOver: !0, result: "threefold", winner: null, inCheck: null } : t.isDrawByFiftyMoves() ? { isGameOver: !0, result: "fifty-move", winner: null, inCheck: null } : { isGameOver: !0, result: "draw", winner: null, inCheck: null } : { isGameOver: !1, result: null, winner: null, inCheck: t.inCheck() ? t.turn() : null };
|
|
142
130
|
}
|
|
143
|
-
function
|
|
131
|
+
function Gt(t) {
|
|
144
132
|
if (t)
|
|
145
133
|
try {
|
|
146
|
-
return new
|
|
134
|
+
return new de(W(t));
|
|
147
135
|
} catch {
|
|
148
136
|
}
|
|
149
|
-
return new
|
|
137
|
+
return new de();
|
|
150
138
|
}
|
|
151
|
-
function
|
|
152
|
-
const [e] =
|
|
153
|
-
c(null),
|
|
154
|
-
}, []),
|
|
155
|
-
|
|
156
|
-
}, []),
|
|
157
|
-
|
|
158
|
-
...
|
|
159
|
-
{ san:
|
|
139
|
+
function jt(t) {
|
|
140
|
+
const [e] = k(() => Gt(t)), n = w(e), [r, i] = k(() => e.fen()), [s, a] = k(() => e.turn()), [o, c] = k(null), [m, y] = k([]), [g, _] = k(() => ue(e)), [d, v] = k(null), [C, $] = k([]), [O, I] = k(null), [j, P] = k(null), [D, ne] = k(() => e.board()), p = S(() => {
|
|
141
|
+
c(null), y([]);
|
|
142
|
+
}, []), M = S(() => {
|
|
143
|
+
i(n.current.fen()), a(n.current.turn()), ne(n.current.board()), _(ue(n.current));
|
|
144
|
+
}, []), F = S((f) => {
|
|
145
|
+
I({ from: f.from, to: f.to }), P({ captured: !!f.captured, check: f.san.includes("+") || f.san.includes("#") }), $((b) => [
|
|
146
|
+
...b,
|
|
147
|
+
{ san: f.san, fen: n.current.fen(), color: f.color }
|
|
160
148
|
]);
|
|
161
|
-
}, []), re =
|
|
162
|
-
const
|
|
163
|
-
if (
|
|
149
|
+
}, []), re = S((f) => {
|
|
150
|
+
const b = n.current, z = b.turn();
|
|
151
|
+
if (d || ue(b).isGameOver)
|
|
164
152
|
return;
|
|
165
|
-
if (o &&
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
|
|
153
|
+
if (o && m.includes(f)) {
|
|
154
|
+
const T = b.get(o);
|
|
155
|
+
if (T?.type === "p" && (T.color === "w" && f[1] === "8" || T.color === "b" && f[1] === "1")) {
|
|
156
|
+
v({ from: o, to: f }), p();
|
|
169
157
|
return;
|
|
170
158
|
}
|
|
171
159
|
try {
|
|
172
|
-
const X =
|
|
173
|
-
X &&
|
|
160
|
+
const X = b.move({ from: o, to: f });
|
|
161
|
+
X && F(X);
|
|
174
162
|
} catch {
|
|
175
163
|
}
|
|
176
|
-
|
|
164
|
+
p(), M();
|
|
177
165
|
return;
|
|
178
166
|
}
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
181
|
-
if (
|
|
182
|
-
|
|
167
|
+
const q = b.get(f);
|
|
168
|
+
if (q && q.color === z) {
|
|
169
|
+
if (f === o) {
|
|
170
|
+
p();
|
|
183
171
|
return;
|
|
184
172
|
}
|
|
185
|
-
c(
|
|
186
|
-
const
|
|
187
|
-
|
|
173
|
+
c(f);
|
|
174
|
+
const T = b.moves({ square: f, verbose: !0 });
|
|
175
|
+
y(T.map((X) => X.to));
|
|
188
176
|
return;
|
|
189
177
|
}
|
|
190
|
-
|
|
191
|
-
}, [o,
|
|
192
|
-
if (!
|
|
193
|
-
const
|
|
178
|
+
p();
|
|
179
|
+
}, [o, m, d, p, M, F]), E = S((f) => {
|
|
180
|
+
if (!d) return;
|
|
181
|
+
const b = n.current;
|
|
194
182
|
try {
|
|
195
|
-
const
|
|
196
|
-
from:
|
|
197
|
-
to:
|
|
198
|
-
promotion:
|
|
183
|
+
const z = b.move({
|
|
184
|
+
from: d.from,
|
|
185
|
+
to: d.to,
|
|
186
|
+
promotion: f
|
|
199
187
|
});
|
|
200
|
-
|
|
188
|
+
z && F(z);
|
|
201
189
|
} catch {
|
|
202
190
|
}
|
|
203
|
-
|
|
204
|
-
}, [
|
|
205
|
-
const
|
|
191
|
+
v(null), p(), M();
|
|
192
|
+
}, [d, p, M, F]), fe = S((f) => {
|
|
193
|
+
const b = n.current;
|
|
206
194
|
try {
|
|
207
|
-
|
|
195
|
+
b.load(W(f)), p(), M();
|
|
208
196
|
} catch {
|
|
209
197
|
}
|
|
210
|
-
}, [
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
let
|
|
198
|
+
}, [p, M]), Me = S((f, b) => {
|
|
199
|
+
const z = n.current;
|
|
200
|
+
if (b !== void 0 && z.fen() !== b) return !1;
|
|
201
|
+
let q;
|
|
214
202
|
try {
|
|
215
|
-
|
|
203
|
+
q = z.move(f);
|
|
216
204
|
} catch {
|
|
217
205
|
return !1;
|
|
218
206
|
}
|
|
219
|
-
return
|
|
220
|
-
}, [
|
|
221
|
-
n.current.reset(),
|
|
222
|
-
}, [
|
|
207
|
+
return F(q), p(), M(), !0;
|
|
208
|
+
}, [F, p, M]), Se = S(() => {
|
|
209
|
+
n.current.reset(), p(), $([]), I(null), P(null), v(null), M();
|
|
210
|
+
}, [p, M]);
|
|
223
211
|
return {
|
|
224
212
|
fen: r,
|
|
225
|
-
turn:
|
|
213
|
+
turn: s,
|
|
226
214
|
selectedSquare: o,
|
|
227
|
-
legalMoves:
|
|
228
|
-
gameStatus:
|
|
229
|
-
promotionPending:
|
|
230
|
-
moveHistory:
|
|
231
|
-
lastMove:
|
|
232
|
-
lastMoveDetail:
|
|
233
|
-
board:
|
|
215
|
+
legalMoves: m,
|
|
216
|
+
gameStatus: g,
|
|
217
|
+
promotionPending: d,
|
|
218
|
+
moveHistory: C,
|
|
219
|
+
lastMove: O,
|
|
220
|
+
lastMoveDetail: j,
|
|
221
|
+
board: D,
|
|
234
222
|
handleSquareClick: re,
|
|
235
|
-
handlePromotion:
|
|
236
|
-
applyFen:
|
|
237
|
-
applyMove:
|
|
238
|
-
handleRestart:
|
|
223
|
+
handlePromotion: E,
|
|
224
|
+
applyFen: fe,
|
|
225
|
+
applyMove: Me,
|
|
226
|
+
handleRestart: Se
|
|
239
227
|
};
|
|
240
228
|
}
|
|
241
|
-
const
|
|
229
|
+
const zt = 2e4, Ut = 8e3, ut = 3, Vt = 5e3, Ht = 1e4, Ze = 2e3;
|
|
242
230
|
class ae extends Error {
|
|
243
231
|
constructor() {
|
|
244
232
|
super("Search cancelled"), this.name = "StockfishCancelledError";
|
|
245
233
|
}
|
|
246
234
|
}
|
|
247
|
-
class
|
|
235
|
+
class Re extends Error {
|
|
248
236
|
constructor() {
|
|
249
237
|
super("Stockfish worker restarted"), this.name = "StockfishRestartedError";
|
|
250
238
|
}
|
|
251
239
|
}
|
|
252
|
-
class
|
|
240
|
+
class Ne extends Error {
|
|
253
241
|
constructor() {
|
|
254
242
|
super("Stockfish is unavailable"), this.name = "StockfishUnavailableError";
|
|
255
243
|
}
|
|
256
244
|
}
|
|
257
|
-
class
|
|
245
|
+
class Oe extends Error {
|
|
258
246
|
constructor(e) {
|
|
259
247
|
super(`Stockfish timed out during ${e}`), this.name = "StockfishTimeoutError";
|
|
260
248
|
}
|
|
261
249
|
}
|
|
262
|
-
class
|
|
250
|
+
class Wt {
|
|
263
251
|
worker = null;
|
|
264
252
|
ready = null;
|
|
265
253
|
pending = null;
|
|
@@ -288,14 +276,14 @@ class Yt {
|
|
|
288
276
|
*/
|
|
289
277
|
init(e) {
|
|
290
278
|
if (this.destroyed) return Promise.reject(new Error("Stockfish engine destroyed"));
|
|
291
|
-
if (this.isUnavailable) return Promise.reject(new
|
|
279
|
+
if (this.isUnavailable) return Promise.reject(new Ne());
|
|
292
280
|
if (!this.ready) {
|
|
293
|
-
const n = e ?? (this.hasStarted ?
|
|
281
|
+
const n = e ?? (this.hasStarted ? Ut : zt), r = this.spawn(n).then(
|
|
294
282
|
() => {
|
|
295
283
|
this.initFailures = 0, this.hasStarted = !0;
|
|
296
284
|
},
|
|
297
|
-
(
|
|
298
|
-
throw this.initFailures++, this.ready === r && (this.ready = null), this.isUnavailable ? new
|
|
285
|
+
(i) => {
|
|
286
|
+
throw this.initFailures++, this.ready === r && (this.ready = null), this.isUnavailable ? new Ne() : i;
|
|
299
287
|
}
|
|
300
288
|
);
|
|
301
289
|
this.ready = r;
|
|
@@ -316,15 +304,15 @@ class Yt {
|
|
|
316
304
|
const r = typeof n.data == "string" ? n.data : "";
|
|
317
305
|
if (r.startsWith("bestmove")) {
|
|
318
306
|
this.searching = !1;
|
|
319
|
-
const
|
|
320
|
-
if (
|
|
321
|
-
this.pending = null,
|
|
322
|
-
const
|
|
323
|
-
|
|
307
|
+
const i = this.pending;
|
|
308
|
+
if (i) {
|
|
309
|
+
this.pending = null, i.timer !== null && clearTimeout(i.timer);
|
|
310
|
+
const s = r.split(" ")[1];
|
|
311
|
+
i.resolve(s && s !== "(none)" ? s : null);
|
|
324
312
|
}
|
|
325
313
|
}
|
|
326
|
-
for (const
|
|
327
|
-
|
|
314
|
+
for (const i of [...this.waiters])
|
|
315
|
+
i.match(r) && (this.waiters = this.waiters.filter((s) => s !== i), i.resolve(r));
|
|
328
316
|
}
|
|
329
317
|
handleWorkerError(e, n) {
|
|
330
318
|
if (e !== this.worker) return;
|
|
@@ -333,24 +321,24 @@ class Yt {
|
|
|
333
321
|
}
|
|
334
322
|
/** Wait for a message from the current worker, with a timeout. */
|
|
335
323
|
waitFor(e, n, r) {
|
|
336
|
-
return new Promise((
|
|
324
|
+
return new Promise((i, s) => {
|
|
337
325
|
const a = setTimeout(() => {
|
|
338
|
-
this.waiters = this.waiters.filter((c) => c !== o),
|
|
326
|
+
this.waiters = this.waiters.filter((c) => c !== o), s(new Oe(r));
|
|
339
327
|
}, n), o = {
|
|
340
328
|
match: e,
|
|
341
329
|
resolve: (c) => {
|
|
342
|
-
clearTimeout(a),
|
|
330
|
+
clearTimeout(a), i(c);
|
|
343
331
|
},
|
|
344
332
|
// Called when the worker is terminated, so callers fail fast
|
|
345
333
|
reject: (c) => {
|
|
346
|
-
clearTimeout(a),
|
|
334
|
+
clearTimeout(a), s(c);
|
|
347
335
|
}
|
|
348
336
|
};
|
|
349
337
|
this.waiters.push(o);
|
|
350
338
|
});
|
|
351
339
|
}
|
|
352
340
|
/** Terminate a worker. If it is the current one, the next search starts a new one. */
|
|
353
|
-
terminate(e, n = new
|
|
341
|
+
terminate(e, n = new Re()) {
|
|
354
342
|
try {
|
|
355
343
|
e.terminate();
|
|
356
344
|
} catch {
|
|
@@ -359,7 +347,7 @@ class Yt {
|
|
|
359
347
|
this.worker = null, this.ready = null, this.searching = !1;
|
|
360
348
|
const r = this.waiters;
|
|
361
349
|
this.waiters = [];
|
|
362
|
-
for (const
|
|
350
|
+
for (const i of r) i.reject(n);
|
|
363
351
|
}
|
|
364
352
|
/** Reject the in-flight search and clear its timer. */
|
|
365
353
|
failPending(e) {
|
|
@@ -388,26 +376,26 @@ class Yt {
|
|
|
388
376
|
* the engine does not answer even then, the worker is replaced and the
|
|
389
377
|
* search rejects with StockfishTimeoutError.
|
|
390
378
|
*/
|
|
391
|
-
async getBestMove(e, n, r =
|
|
392
|
-
const
|
|
379
|
+
async getBestMove(e, n, r = Ht) {
|
|
380
|
+
const i = Number.isFinite(n) ? Math.min(20, Math.max(1, Math.round(n))) : 10, s = ++this.searchId;
|
|
393
381
|
this.cancelPending(), await this.init();
|
|
394
382
|
const a = this.worker;
|
|
395
383
|
if (!a) throw new Error("Stockfish not initialized");
|
|
396
|
-
if (
|
|
384
|
+
if (s !== this.searchId) throw new ae();
|
|
397
385
|
try {
|
|
398
|
-
this.searching && await this.waitFor((o) => o.startsWith("bestmove"), Ze, "stop"), a.postMessage("isready"), await this.waitFor((o) => o === "readyok",
|
|
386
|
+
this.searching && await this.waitFor((o) => o.startsWith("bestmove"), Ze, "stop"), a.postMessage("isready"), await this.waitFor((o) => o === "readyok", Vt, "isready");
|
|
399
387
|
} catch (o) {
|
|
400
|
-
throw
|
|
388
|
+
throw s !== this.searchId ? new ae() : (o instanceof Oe && this.terminate(a), o);
|
|
401
389
|
}
|
|
402
|
-
if (
|
|
403
|
-
if (a !== this.worker || this.searching) throw new
|
|
390
|
+
if (s !== this.searchId) throw new ae();
|
|
391
|
+
if (a !== this.worker || this.searching) throw new Re();
|
|
404
392
|
return new Promise((o, c) => {
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
this.pending ===
|
|
408
|
-
this.pending ===
|
|
393
|
+
const m = { resolve: o, reject: c, timer: null };
|
|
394
|
+
m.timer = setTimeout(() => {
|
|
395
|
+
this.pending === m && (a.postMessage("stop"), m.timer = setTimeout(() => {
|
|
396
|
+
this.pending === m && (this.failPending(new Oe("search")), this.terminate(a));
|
|
409
397
|
}, Ze));
|
|
410
|
-
}, r), this.pending =
|
|
398
|
+
}, r), this.pending = m, this.searching = !0, a.postMessage("ucinewgame"), a.postMessage(`position fen ${W(e)}`), a.postMessage(`go depth ${i}`);
|
|
411
399
|
});
|
|
412
400
|
}
|
|
413
401
|
/**
|
|
@@ -425,78 +413,78 @@ class Yt {
|
|
|
425
413
|
e && (e.postMessage("quit"), this.terminate(e, new Error("Stockfish engine destroyed")));
|
|
426
414
|
}
|
|
427
415
|
}
|
|
428
|
-
const
|
|
429
|
-
function
|
|
416
|
+
const Yt = 300 * 1e3, ce = /* @__PURE__ */ new Map();
|
|
417
|
+
function dt(t) {
|
|
430
418
|
return t ?? "";
|
|
431
419
|
}
|
|
432
|
-
function
|
|
433
|
-
const e =
|
|
420
|
+
function Kt(t) {
|
|
421
|
+
const e = dt(t), n = ce.get(e);
|
|
434
422
|
for (; n && n.length > 0; ) {
|
|
435
423
|
const r = n.pop();
|
|
436
424
|
if (clearTimeout(r.timer), !r.engine.isDestroyed && !r.engine.isUnavailable) return r.engine;
|
|
437
425
|
r.engine.destroy();
|
|
438
426
|
}
|
|
439
|
-
return new
|
|
427
|
+
return new Wt(t);
|
|
440
428
|
}
|
|
441
429
|
function Xt(t, e) {
|
|
442
430
|
t.cancel();
|
|
443
|
-
const n =
|
|
444
|
-
if (r.some((
|
|
445
|
-
const
|
|
431
|
+
const n = dt(e), r = ce.get(n) ?? [];
|
|
432
|
+
if (r.some((s) => s.engine === t)) return;
|
|
433
|
+
const i = {
|
|
446
434
|
engine: t,
|
|
447
435
|
timer: setTimeout(() => {
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
},
|
|
436
|
+
const s = ce.get(n);
|
|
437
|
+
s && ce.set(n, s.filter((a) => a !== i)), t.destroy();
|
|
438
|
+
}, Yt)
|
|
451
439
|
};
|
|
452
|
-
r.push(
|
|
440
|
+
r.push(i), ce.set(n, r);
|
|
453
441
|
}
|
|
454
442
|
const Qt = 2e3, et = 45e3;
|
|
455
443
|
function Jt(t) {
|
|
456
|
-
const e =
|
|
457
|
-
|
|
458
|
-
const
|
|
459
|
-
e.current =
|
|
460
|
-
let
|
|
444
|
+
const e = w(null), [n, r] = k("loading"), [i, s] = k(!1), a = w(0);
|
|
445
|
+
B(() => {
|
|
446
|
+
const y = Kt(t);
|
|
447
|
+
e.current = y;
|
|
448
|
+
let g = !1, _ = null;
|
|
461
449
|
r("loading");
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}).catch((
|
|
466
|
-
|
|
450
|
+
const d = (v) => {
|
|
451
|
+
y.init().then(() => {
|
|
452
|
+
g || r("ready");
|
|
453
|
+
}).catch((C) => {
|
|
454
|
+
g || (console.warn(`Stockfish failed to load (attempt ${v}/${ut}):`, C.message), y.isUnavailable ? r("failed") : _ = setTimeout(() => d(v + 1), Qt));
|
|
467
455
|
});
|
|
468
456
|
};
|
|
469
|
-
return
|
|
470
|
-
|
|
457
|
+
return d(1), () => {
|
|
458
|
+
g = !0, _ && clearTimeout(_), Xt(y, t), e.current = null;
|
|
471
459
|
};
|
|
472
460
|
}, [t]);
|
|
473
|
-
const o = n === "ready", c =
|
|
474
|
-
async (
|
|
461
|
+
const o = n === "ready", c = S(
|
|
462
|
+
async (y, g) => {
|
|
475
463
|
if (!e.current || !o) return null;
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
const
|
|
479
|
-
a.current ===
|
|
464
|
+
const _ = ++a.current;
|
|
465
|
+
s(!0);
|
|
466
|
+
const d = setTimeout(() => {
|
|
467
|
+
a.current === _ && (console.warn(`[ChaosChess] Safety timeout: clearing isThinking after ${et / 1e3}s`), s(!1));
|
|
480
468
|
}, et);
|
|
481
469
|
try {
|
|
482
|
-
return await e.current.getBestMove(
|
|
483
|
-
} catch (
|
|
484
|
-
throw
|
|
470
|
+
return await e.current.getBestMove(y, g);
|
|
471
|
+
} catch (v) {
|
|
472
|
+
throw v instanceof Ne && r("failed"), v;
|
|
485
473
|
} finally {
|
|
486
|
-
clearTimeout(
|
|
474
|
+
clearTimeout(d), a.current === _ && s(!1);
|
|
487
475
|
}
|
|
488
476
|
},
|
|
489
477
|
[o]
|
|
490
|
-
),
|
|
478
|
+
), m = S(() => {
|
|
491
479
|
e.current?.cancel();
|
|
492
480
|
}, []);
|
|
493
|
-
return { status: n, isReady: o, isThinking:
|
|
481
|
+
return { status: n, isReady: o, isThinking: i, getBestMove: c, cancel: m };
|
|
494
482
|
}
|
|
495
|
-
const Zt = ["p", "n", "b", "r", "q"], ht = 10,
|
|
483
|
+
const Zt = ["p", "n", "b", "r", "q"], ht = 10, ft = 16, pt = 8;
|
|
496
484
|
function en(t, e) {
|
|
497
485
|
return t > e ? Math.random() < 0.7 ? "help_black" : "help_white" : e > t ? Math.random() < 0.7 ? "help_white" : "help_black" : Math.random() < 0.5 ? "help_white" : "help_black";
|
|
498
486
|
}
|
|
499
|
-
function
|
|
487
|
+
function Ae(t) {
|
|
500
488
|
return t[Math.floor(Math.random() * t.length)];
|
|
501
489
|
}
|
|
502
490
|
function tn(t) {
|
|
@@ -509,68 +497,68 @@ function tn(t) {
|
|
|
509
497
|
}
|
|
510
498
|
function nn(t, e) {
|
|
511
499
|
const n = parseInt(t[1]);
|
|
512
|
-
return
|
|
500
|
+
return Ae(!e || n === 1 || n === 8 ? ["n", "b", "r", "q"] : Zt);
|
|
513
501
|
}
|
|
514
502
|
function rn(t, e) {
|
|
515
|
-
const n =
|
|
516
|
-
let r = 0,
|
|
517
|
-
for (const
|
|
518
|
-
for (const a of
|
|
519
|
-
a && a.color === e && (r++, a.type === "p" &&
|
|
520
|
-
return { total: r, pawns:
|
|
503
|
+
const n = K(Y(t).position);
|
|
504
|
+
let r = 0, i = 0;
|
|
505
|
+
for (const s of n)
|
|
506
|
+
for (const a of s)
|
|
507
|
+
a && a.color === e && (r++, a.type === "p" && i++);
|
|
508
|
+
return { total: r, pawns: i };
|
|
521
509
|
}
|
|
522
510
|
function he(t) {
|
|
523
511
|
let e;
|
|
524
512
|
try {
|
|
525
|
-
e = new
|
|
513
|
+
e = new de(t);
|
|
526
514
|
} catch {
|
|
527
515
|
return !1;
|
|
528
516
|
}
|
|
529
|
-
const { position: n, activeColor: r, castling:
|
|
530
|
-
for (let
|
|
531
|
-
for (let
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
534
|
-
if (o[
|
|
535
|
-
if (
|
|
536
|
-
c[
|
|
517
|
+
const { position: n, activeColor: r, castling: i, enPassant: s } = Y(t), a = K(n), o = { w: 0, b: 0 }, c = { w: 0, b: 0 }, m = { w: [], b: [] };
|
|
518
|
+
for (let g = 0; g < 8; g++)
|
|
519
|
+
for (let _ = 0; _ < 8; _++) {
|
|
520
|
+
const d = a[g][_];
|
|
521
|
+
if (d) {
|
|
522
|
+
if (o[d.color]++, d.type === "p") {
|
|
523
|
+
if (g === 0 || g === 7) return !1;
|
|
524
|
+
c[d.color]++;
|
|
537
525
|
}
|
|
538
|
-
|
|
526
|
+
d.type === "k" && m[d.color].push(`${"abcdefgh"[_]}${8 - g}`);
|
|
539
527
|
}
|
|
540
528
|
}
|
|
541
|
-
for (const
|
|
542
|
-
if (
|
|
543
|
-
if (ct(
|
|
544
|
-
const
|
|
545
|
-
return !e.isAttacked(
|
|
529
|
+
for (const g of ["w", "b"])
|
|
530
|
+
if (m[g].length !== 1 || o[g] > ft || c[g] > pt) return !1;
|
|
531
|
+
if (ct(i, a) !== i || lt(s, r, a) !== s) return !1;
|
|
532
|
+
const y = e.turn() === "w" ? "b" : "w";
|
|
533
|
+
return !e.isAttacked(m[y][0], e.turn());
|
|
546
534
|
}
|
|
547
535
|
function tt(t, e) {
|
|
548
|
-
const n =
|
|
536
|
+
const n = It(t);
|
|
549
537
|
if (n.length === 0) return null;
|
|
550
|
-
const { total: r, pawns:
|
|
551
|
-
if (r >=
|
|
552
|
-
const
|
|
538
|
+
const { total: r, pawns: i } = rn(t, e);
|
|
539
|
+
if (r >= ft) return null;
|
|
540
|
+
const s = i < pt;
|
|
553
541
|
for (let a = 0; a < ht; a++) {
|
|
554
|
-
const o =
|
|
555
|
-
if (he(
|
|
556
|
-
return { newFen:
|
|
542
|
+
const o = Ae(n), c = nn(o, s), m = xt(t, o, c, e);
|
|
543
|
+
if (he(m))
|
|
544
|
+
return { newFen: m, square: o, piece: c };
|
|
557
545
|
}
|
|
558
546
|
return null;
|
|
559
547
|
}
|
|
560
548
|
function nt(t, e) {
|
|
561
|
-
const n =
|
|
549
|
+
const n = Ft(t, e, !0);
|
|
562
550
|
if (n.length === 0) return null;
|
|
563
551
|
for (const r of tn(n).slice(0, ht)) {
|
|
564
|
-
const
|
|
565
|
-
if (he(
|
|
566
|
-
return { newFen:
|
|
552
|
+
const i = $t(t, r);
|
|
553
|
+
if (he(i))
|
|
554
|
+
return { newFen: i, square: r };
|
|
567
555
|
}
|
|
568
556
|
return null;
|
|
569
557
|
}
|
|
570
558
|
function sn(t) {
|
|
571
|
-
const { white: e, black: n } =
|
|
572
|
-
if (
|
|
573
|
-
const o = tt(t,
|
|
559
|
+
const { white: e, black: n } = Et(t), r = en(e, n), i = Math.random() < 0.5 ? "add" : "remove", s = r === "help_white" ? "w" : "b", a = r === "help_white" ? "b" : "w";
|
|
560
|
+
if (i === "add") {
|
|
561
|
+
const o = tt(t, s);
|
|
574
562
|
if (o)
|
|
575
563
|
return {
|
|
576
564
|
newFen: o.newFen,
|
|
@@ -579,7 +567,7 @@ function sn(t) {
|
|
|
579
567
|
target: r,
|
|
580
568
|
square: o.square,
|
|
581
569
|
piece: o.piece,
|
|
582
|
-
color:
|
|
570
|
+
color: s,
|
|
583
571
|
whiteMaterial: e,
|
|
584
572
|
blackMaterial: n
|
|
585
573
|
}
|
|
@@ -609,7 +597,7 @@ function sn(t) {
|
|
|
609
597
|
blackMaterial: n
|
|
610
598
|
}
|
|
611
599
|
};
|
|
612
|
-
const c = tt(t,
|
|
600
|
+
const c = tt(t, s);
|
|
613
601
|
if (c)
|
|
614
602
|
return {
|
|
615
603
|
newFen: c.newFen,
|
|
@@ -618,7 +606,7 @@ function sn(t) {
|
|
|
618
606
|
target: r,
|
|
619
607
|
square: c.square,
|
|
620
608
|
piece: c.piece,
|
|
621
|
-
color:
|
|
609
|
+
color: s,
|
|
622
610
|
whiteMaterial: e,
|
|
623
611
|
blackMaterial: n
|
|
624
612
|
}
|
|
@@ -639,8 +627,8 @@ const on = [
|
|
|
639
627
|
// level 5
|
|
640
628
|
];
|
|
641
629
|
function an(t = 3) {
|
|
642
|
-
const e = Number.isFinite(t) ? Math.round(t) : 3, n = Math.max(0, Math.min(4, e - 1)), [r,
|
|
643
|
-
return (r + Math.random() * (
|
|
630
|
+
const e = Number.isFinite(t) ? Math.round(t) : 3, n = Math.max(0, Math.min(4, e - 1)), [r, i] = on[n];
|
|
631
|
+
return (r + Math.random() * (i - r)) * 1e3;
|
|
644
632
|
}
|
|
645
633
|
const cn = 200, ln = 1e3;
|
|
646
634
|
function rt() {
|
|
@@ -651,213 +639,248 @@ function un({
|
|
|
651
639
|
isPaused: e,
|
|
652
640
|
stupidLevel: n,
|
|
653
641
|
onChaosAction: r,
|
|
654
|
-
resetKey:
|
|
642
|
+
resetKey: i = 0
|
|
655
643
|
}) {
|
|
656
|
-
const [
|
|
657
|
-
|
|
658
|
-
const
|
|
659
|
-
const
|
|
660
|
-
c(
|
|
644
|
+
const [s, a] = k(0), [o, c] = k(0), [m, y] = k(null), [g, _] = k(null), d = w(t), v = w(e), C = w(n), $ = w(r), O = w(0), I = w(0), j = w(!1), P = w(!1);
|
|
645
|
+
d.current = t, v.current = e, C.current = n, $.current = r;
|
|
646
|
+
const D = S(() => {
|
|
647
|
+
const p = an(C.current), M = Math.ceil(p / 1e3);
|
|
648
|
+
c(M), a(M), O.current = p;
|
|
661
649
|
}, []);
|
|
662
650
|
ot(() => {
|
|
663
|
-
e && (
|
|
664
|
-
}, [e]),
|
|
665
|
-
|
|
666
|
-
}, [n,
|
|
667
|
-
const ne =
|
|
668
|
-
return
|
|
651
|
+
e && (j.current = !0);
|
|
652
|
+
}, [e]), B(() => {
|
|
653
|
+
D();
|
|
654
|
+
}, [n, D]);
|
|
655
|
+
const ne = w(!0);
|
|
656
|
+
return B(() => {
|
|
669
657
|
if (ne.current) {
|
|
670
658
|
ne.current = !1;
|
|
671
659
|
return;
|
|
672
660
|
}
|
|
673
|
-
|
|
674
|
-
}, [
|
|
675
|
-
|
|
676
|
-
const
|
|
677
|
-
|
|
661
|
+
y(null), _(null), D();
|
|
662
|
+
}, [i, D]), B(() => {
|
|
663
|
+
P.current = rt();
|
|
664
|
+
const p = () => {
|
|
665
|
+
P.current = rt(), I.current = Date.now(), P.current && (j.current = !0);
|
|
678
666
|
};
|
|
679
|
-
return document.addEventListener("visibilitychange",
|
|
680
|
-
}, []),
|
|
681
|
-
|
|
682
|
-
let
|
|
683
|
-
const
|
|
684
|
-
const
|
|
685
|
-
if (
|
|
686
|
-
|
|
667
|
+
return document.addEventListener("visibilitychange", p), () => document.removeEventListener("visibilitychange", p);
|
|
668
|
+
}, []), B(() => {
|
|
669
|
+
I.current = Date.now();
|
|
670
|
+
let p = null;
|
|
671
|
+
const M = setInterval(() => {
|
|
672
|
+
const F = Date.now(), re = F - I.current;
|
|
673
|
+
if (I.current = F, v.current || P.current) {
|
|
674
|
+
j.current = !0;
|
|
687
675
|
return;
|
|
688
676
|
}
|
|
689
|
-
if (
|
|
690
|
-
|
|
677
|
+
if (j.current) {
|
|
678
|
+
j.current = !1, O.current = Math.max(O.current, ln), a(Math.ceil(O.current / 1e3));
|
|
691
679
|
return;
|
|
692
680
|
}
|
|
693
|
-
if (
|
|
694
|
-
const
|
|
695
|
-
|
|
681
|
+
if (O.current -= re, a(Math.max(0, Math.ceil(O.current / 1e3))), O.current > 0) return;
|
|
682
|
+
const E = sn(d.current);
|
|
683
|
+
E && $.current(E.newFen) !== !1 && (y(E.action), _(E.action.square), p && clearTimeout(p), p = setTimeout(() => _(null), 600)), D();
|
|
696
684
|
}, cn);
|
|
697
685
|
return () => {
|
|
698
|
-
clearInterval(
|
|
686
|
+
clearInterval(M), p && clearTimeout(p);
|
|
699
687
|
};
|
|
700
|
-
}, [
|
|
688
|
+
}, [D]), { countdown: s, maxCountdown: o, lastAction: m, chaosSquare: g };
|
|
701
689
|
}
|
|
702
|
-
|
|
690
|
+
/*! Chess piece artwork: "Cburnett" set (c) Colin M.L. Burnett, BSD-3-Clause.
|
|
691
|
+
* Redistributed with colours replaced by CSS variables. Full licence text:
|
|
692
|
+
* THIRD_PARTY_NOTICES.md in @maxr0ssi/chaos-chess. */
|
|
693
|
+
const dn = {
|
|
694
|
+
k: "king",
|
|
695
|
+
q: "queen",
|
|
696
|
+
r: "rook",
|
|
697
|
+
b: "bishop",
|
|
698
|
+
n: "knight",
|
|
699
|
+
p: "pawn"
|
|
700
|
+
};
|
|
701
|
+
function mt(t, e) {
|
|
702
|
+
return `${e === "w" ? "white" : "black"} ${dn[t]}`;
|
|
703
|
+
}
|
|
704
|
+
const hn = {
|
|
705
|
+
wk: '<g style="stroke:var(--cc-pw-line)" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path stroke-linejoin="miter" d="M22.5 11.63V6M20 8h5"/><path style="fill:var(--cc-pw-body)" stroke-linecap="butt" stroke-linejoin="miter" d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5"/><path style="fill:var(--cc-pw-body)" d="M12.5 37c5.5 3.5 14.5 3.5 20 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-2.5-7.5-12-10.5-16-4-3 6 6 10.5 6 10.5v7"/><path d="M12.5 30c5.5-3 14.5-3 20 0m-20 3.5c5.5-3 14.5-3 20 0m-20 3.5c5.5-3 14.5-3 20 0"/></g>',
|
|
706
|
+
wq: '<g style="fill:var(--cc-pw-body);stroke:var(--cc-pw-line)" stroke-width="1.5" stroke-linejoin="round"><path d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z"/><path d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 11,36 11,36 C 9.5,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z"/><path d="M 11.5,30 C 15,29 30,29 33.5,30" fill="none"/><path d="M 12,33.5 C 18,32.5 27,32.5 33,33.5" fill="none"/><circle cx="6" cy="12" r="2" /><circle cx="14" cy="9" r="2" /><circle cx="22.5" cy="8" r="2" /><circle cx="31" cy="9" r="2" /><circle cx="39" cy="12" r="2" /></g>',
|
|
707
|
+
wr: '<g style="fill:var(--cc-pw-body);stroke:var(--cc-pw-line)" fill-rule="evenodd" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0.3)"><path d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z " stroke-linecap="butt" /><path d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z " stroke-linecap="butt" /><path d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14" stroke-linecap="butt" /><path d="M 34,14 L 31,17 L 14,17 L 11,14" /><path d="M 31,17 L 31,29.5 L 14,29.5 L 14,17" stroke-linecap="butt" stroke-linejoin="miter" /><path d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" /><path style="stroke:var(--cc-pw-line)" d="M 11,14 L 34,14" fill="none" stroke-linejoin="miter" /></g>',
|
|
708
|
+
wb: '<g style="stroke:var(--cc-pw-line)" fill="none" fill-rule="evenodd" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0.6)"><g style="fill:var(--cc-pw-body);stroke:var(--cc-pw-line)" stroke-linecap="butt"><path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z"/><path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z"/><path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z"/></g><path style="stroke:var(--cc-pw-line)" d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" fill="none" stroke-linejoin="miter"/></g>',
|
|
709
|
+
wn: '<g style="stroke:var(--cc-pw-line)" fill="none" fill-rule="evenodd" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0.3)"><path style="fill:var(--cc-pw-body);stroke:var(--cc-pw-line)" d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" /><path style="fill:var(--cc-pw-body);stroke:var(--cc-pw-line)" d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10" /><path style="fill:var(--cc-pw-line);stroke:var(--cc-pw-line)" d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z" /><path style="fill:var(--cc-pw-line);stroke:var(--cc-pw-line)" d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)" /></g>',
|
|
710
|
+
wp: '<path style="fill:var(--cc-pw-body);stroke:var(--cc-pw-line)" d="m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z" fill-rule="nonzero" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="miter"/>',
|
|
711
|
+
bk: '<g style="stroke:var(--cc-pb-line)" fill="none" fill-rule="evenodd" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path style="stroke:var(--cc-pb-line)" d="M 22.5,11.63 L 22.5,6" fill="none" stroke-linejoin="miter"/><path style="fill:var(--cc-pb-body)" d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25" stroke-linecap="butt" stroke-linejoin="miter"/><path style="fill:var(--cc-pb-body);stroke:var(--cc-pb-line)" d="M 12.5,37 C 18,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 20,16 10.5,13 6.5,19.5 C 3.5,25.5 12.5,30 12.5,30 L 12.5,37"/><path style="stroke:var(--cc-pb-line)" d="M 20,8 L 25,8" fill="none" stroke-linejoin="miter"/><path style="stroke:var(--cc-pb-detail)" d="M 32,29.5 C 32,29.5 40.5,25.5 38.03,19.85 C 34.15,14 25,18 22.5,24.5 L 22.5,26.6 L 22.5,24.5 C 20,18 10.85,14 6.97,19.85 C 4.5,25.5 13,29.5 13,29.5" fill="none"/><path style="stroke:var(--cc-pb-detail)" d="M 12.5,30 C 18,27 27,27 32.5,30 M 12.5,33.5 C 18,30.5 27,30.5 32.5,33.5 M 12.5,37 C 18,34 27,34 32.5,37" fill="none"/></g>',
|
|
712
|
+
bq: '<g style="fill:var(--cc-pb-body);stroke:var(--cc-pb-line)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path style="fill:var(--cc-pb-body)" d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z" stroke-linecap="butt" /><path d="m 9,26 c 0,2 1.5,2 2.5,4 1,1.5 1,1 0.5,3.5 -1.5,1 -1,2.5 -1,2.5 -1.5,1.5 0,2.5 0,2.5 6.5,1 16.5,1 23,0 0,0 1.5,-1 0,-2.5 0,0 0.5,-1.5 -1,-2.5 -0.5,-2.5 -0.5,-2 0.5,-3.5 1,-2 2.5,-2 2.5,-4 -8.5,-1.5 -18.5,-1.5 -27,0 z" /><path d="M 11.5,30 C 15,29 30,29 33.5,30" /><path d="m 12,33.5 c 6,-1 15,-1 21,0" /><circle cx="6" cy="12" r="2" /><circle cx="14" cy="9" r="2" /><circle cx="22.5" cy="8" r="2" /><circle cx="31" cy="9" r="2" /><circle cx="39" cy="12" r="2" /><path style="stroke:var(--cc-pb-line)" d="M 11,38.5 A 35,35 1 0 0 34,38.5" fill="none" stroke-linecap="butt" /><g style="stroke:var(--cc-pb-detail)" fill="none"><path d="M 11,29 A 35,35 1 0 1 34,29" /><path d="M 12.5,31.5 L 32.5,31.5" /><path d="M 11.5,34.5 A 35,35 1 0 0 33.5,34.5" /><path d="M 10.5,37.5 A 35,35 1 0 0 34.5,37.5" /></g></g>',
|
|
713
|
+
br: '<g style="fill:var(--cc-pb-body);stroke:var(--cc-pb-line)" fill-rule="evenodd" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0.3)"><path d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z " stroke-linecap="butt" /><path d="M 12.5,32 L 14,29.5 L 31,29.5 L 32.5,32 L 12.5,32 z " stroke-linecap="butt" /><path d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z " stroke-linecap="butt" /><path d="M 14,29.5 L 14,16.5 L 31,16.5 L 31,29.5 L 14,29.5 z " stroke-linecap="butt" stroke-linejoin="miter" /><path d="M 14,16.5 L 11,14 L 34,14 L 31,16.5 L 14,16.5 z " stroke-linecap="butt" /><path d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14 L 11,14 z " stroke-linecap="butt" /><path style="stroke:var(--cc-pb-detail)" d="M 12,35.5 L 33,35.5 L 33,35.5" fill="none" stroke-width="1" stroke-linejoin="miter" /><path style="stroke:var(--cc-pb-detail)" d="M 13,31.5 L 32,31.5" fill="none" stroke-width="1" stroke-linejoin="miter" /><path style="stroke:var(--cc-pb-detail)" d="M 14,29.5 L 31,29.5" fill="none" stroke-width="1" stroke-linejoin="miter" /><path style="stroke:var(--cc-pb-detail)" d="M 14,16.5 L 31,16.5" fill="none" stroke-width="1" stroke-linejoin="miter" /><path style="stroke:var(--cc-pb-detail)" d="M 11,14 L 34,14" fill="none" stroke-width="1" stroke-linejoin="miter" /></g>',
|
|
714
|
+
bb: '<g style="stroke:var(--cc-pb-line)" fill="none" fill-rule="evenodd" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0.6)"><g style="fill:var(--cc-pb-body);stroke:var(--cc-pb-line)" stroke-linecap="butt"><path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z"/><path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z"/><path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z"/></g><path style="stroke:var(--cc-pb-detail)" d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" fill="none" stroke-linejoin="miter"/></g>',
|
|
715
|
+
bn: '<g style="stroke:var(--cc-pb-line)" fill="none" fill-rule="evenodd" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" transform="translate(0,0.3)"><path style="fill:var(--cc-pb-body);stroke:var(--cc-pb-line)" d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" /><path style="fill:var(--cc-pb-body);stroke:var(--cc-pb-line)" d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10" /><path style="fill:var(--cc-pb-detail);stroke:var(--cc-pb-detail)" d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z" /><path style="fill:var(--cc-pb-detail);stroke:var(--cc-pb-detail)" d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)" /><path style="fill:var(--cc-pb-detail)" d="M 24.55,10.4 L 24.1,11.85 L 24.6,12 C 27.75,13 30.25,14.49 32.5,18.75 C 34.75,23.01 35.75,29.06 35.25,39 L 35.2,39.5 L 37.45,39.5 L 37.5,39 C 38,28.94 36.62,22.15 34.25,17.66 C 31.88,13.17 28.46,11.02 25.06,10.5 L 24.55,10.4 z " stroke="none" /></g>',
|
|
716
|
+
bp: '<path style="fill:var(--cc-pb-body);stroke:var(--cc-pb-line)" d="m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z" fill-rule="nonzero" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="miter"/>'
|
|
717
|
+
}, fn = "_square_i8q9c_1", pn = "_light_i8q9c_15", mn = "_dark_i8q9c_21", vn = "_selected_i8q9c_28", kn = "_check_i8q9c_29", gn = "_lastMoveFrom_i8q9c_30", yn = "_lastMoveTo_i8q9c_31", _n = "_legalMove_i8q9c_39", wn = "_legalCapture_i8q9c_52", Cn = "_chaosFlash_i8q9c_79", bn = "_pieceArt_i8q9c_84", Ln = "_piece_i8q9c_84", Mn = "_pieceWhite_i8q9c_100", Sn = "_pieceBlack_i8q9c_101", A = {
|
|
703
718
|
square: fn,
|
|
704
|
-
light:
|
|
705
|
-
dark:
|
|
706
|
-
selected:
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
chaosFlash:
|
|
713
|
-
|
|
714
|
-
|
|
719
|
+
light: pn,
|
|
720
|
+
dark: mn,
|
|
721
|
+
selected: vn,
|
|
722
|
+
check: kn,
|
|
723
|
+
lastMoveFrom: gn,
|
|
724
|
+
lastMoveTo: yn,
|
|
725
|
+
legalMove: _n,
|
|
726
|
+
legalCapture: wn,
|
|
727
|
+
chaosFlash: Cn,
|
|
728
|
+
pieceArt: bn,
|
|
729
|
+
piece: Ln,
|
|
730
|
+
pieceWhite: Mn,
|
|
715
731
|
pieceBlack: Sn
|
|
716
732
|
};
|
|
717
|
-
function
|
|
718
|
-
const r = `${e}${t}
|
|
719
|
-
if (!
|
|
720
|
-
const i = e === "w" ?
|
|
721
|
-
return /* @__PURE__ */ l(
|
|
733
|
+
function we({ type: t, color: e, className: n }) {
|
|
734
|
+
const r = hn[`${e}${t}`];
|
|
735
|
+
if (!r) return null;
|
|
736
|
+
const i = e === "w" ? A.pieceWhite : A.pieceBlack;
|
|
737
|
+
return /* @__PURE__ */ l(
|
|
738
|
+
"svg",
|
|
739
|
+
{
|
|
740
|
+
viewBox: "0 0 45 45",
|
|
741
|
+
role: "img",
|
|
742
|
+
"aria-label": mt(t, e),
|
|
743
|
+
className: `${A.pieceArt} ${n ?? ""} ${i}`,
|
|
744
|
+
dangerouslySetInnerHTML: { __html: r }
|
|
745
|
+
}
|
|
746
|
+
);
|
|
722
747
|
}
|
|
723
|
-
const Tn = "
|
|
748
|
+
const Tn = "_board_192mi_1", qn = "_rankLabel_192mi_17", Pn = "_fileLabel_192mi_31", Bn = "_boardLocked_192mi_45", Ce = {
|
|
724
749
|
board: Tn,
|
|
725
|
-
rankLabel:
|
|
726
|
-
fileLabel:
|
|
727
|
-
boardLocked:
|
|
750
|
+
rankLabel: qn,
|
|
751
|
+
fileLabel: Pn,
|
|
752
|
+
boardLocked: Bn
|
|
728
753
|
};
|
|
729
|
-
function
|
|
754
|
+
function On({
|
|
730
755
|
square: t,
|
|
731
756
|
piece: e,
|
|
732
757
|
isLight: n,
|
|
733
758
|
isSelected: r,
|
|
734
|
-
isLegalMove:
|
|
735
|
-
isCheck:
|
|
759
|
+
isLegalMove: i,
|
|
760
|
+
isCheck: s,
|
|
736
761
|
isLastMoveFrom: a,
|
|
737
762
|
isLastMoveTo: o,
|
|
738
763
|
isChaosFlash: c,
|
|
739
|
-
rankLabel:
|
|
740
|
-
fileLabel:
|
|
741
|
-
onClick:
|
|
764
|
+
rankLabel: m,
|
|
765
|
+
fileLabel: y,
|
|
766
|
+
onClick: g
|
|
742
767
|
}) {
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
n ?
|
|
746
|
-
r &&
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
!r && !
|
|
750
|
-
!r && !
|
|
751
|
-
c &&
|
|
768
|
+
const _ = [
|
|
769
|
+
A.square,
|
|
770
|
+
n ? A.light : A.dark,
|
|
771
|
+
r && A.selected,
|
|
772
|
+
i && (e ? A.legalCapture : A.legalMove),
|
|
773
|
+
s && A.check,
|
|
774
|
+
!r && !s && a && A.lastMoveFrom,
|
|
775
|
+
!r && !s && o && A.lastMoveTo,
|
|
776
|
+
c && A.chaosFlash
|
|
752
777
|
].filter(Boolean).join(" ");
|
|
753
|
-
return /* @__PURE__ */
|
|
778
|
+
return /* @__PURE__ */ L("div", { className: _, onClick: () => g(t), children: [
|
|
754
779
|
e && /* @__PURE__ */ l(
|
|
755
|
-
|
|
780
|
+
we,
|
|
756
781
|
{
|
|
757
782
|
type: e.type,
|
|
758
783
|
color: e.color,
|
|
759
|
-
className:
|
|
784
|
+
className: A.piece
|
|
760
785
|
}
|
|
761
786
|
),
|
|
762
|
-
|
|
763
|
-
|
|
787
|
+
m != null && /* @__PURE__ */ l("span", { className: Ce.rankLabel, children: m }),
|
|
788
|
+
y != null && /* @__PURE__ */ l("span", { className: Ce.fileLabel, children: y })
|
|
764
789
|
] });
|
|
765
790
|
}
|
|
766
|
-
const
|
|
767
|
-
function
|
|
768
|
-
return `${
|
|
791
|
+
const vt = "abcdefgh";
|
|
792
|
+
function it(t, e) {
|
|
793
|
+
return `${vt[e]}${8 - t}`;
|
|
769
794
|
}
|
|
770
|
-
function
|
|
795
|
+
function Rn(t, e) {
|
|
771
796
|
return (t + e) % 2 === 0;
|
|
772
797
|
}
|
|
773
|
-
const
|
|
798
|
+
const Nn = Nt.memo(function({
|
|
774
799
|
board: e,
|
|
775
800
|
selectedSquare: n,
|
|
776
801
|
legalMoves: r,
|
|
777
|
-
inCheck:
|
|
778
|
-
lastMove:
|
|
802
|
+
inCheck: i,
|
|
803
|
+
lastMove: s,
|
|
779
804
|
chaosSquare: a,
|
|
780
805
|
flipped: o,
|
|
781
806
|
locked: c,
|
|
782
|
-
onSquareClick:
|
|
807
|
+
onSquareClick: m
|
|
783
808
|
}) {
|
|
784
|
-
let
|
|
785
|
-
if (
|
|
786
|
-
for (let
|
|
787
|
-
for (let
|
|
788
|
-
const
|
|
789
|
-
|
|
809
|
+
let y = null;
|
|
810
|
+
if (i)
|
|
811
|
+
for (let d = 0; d < 8; d++)
|
|
812
|
+
for (let v = 0; v < 8; v++) {
|
|
813
|
+
const C = e[d][v];
|
|
814
|
+
C?.type === "k" && C.color === i && (y = it(d, v));
|
|
790
815
|
}
|
|
791
|
-
const
|
|
792
|
-
return /* @__PURE__ */ l("div", { className: `${
|
|
793
|
-
(
|
|
794
|
-
const
|
|
816
|
+
const g = o ? [7, 6, 5, 4, 3, 2, 1, 0] : [0, 1, 2, 3, 4, 5, 6, 7], _ = o ? [7, 6, 5, 4, 3, 2, 1, 0] : [0, 1, 2, 3, 4, 5, 6, 7];
|
|
817
|
+
return /* @__PURE__ */ l("div", { className: `${Ce.board}${c ? ` ${Ce.boardLocked}` : ""}`, children: g.map(
|
|
818
|
+
(d) => _.map((v) => {
|
|
819
|
+
const C = it(d, v), $ = e[d][v], O = g.indexOf(d), I = _.indexOf(v);
|
|
795
820
|
return /* @__PURE__ */ l(
|
|
796
|
-
|
|
821
|
+
On,
|
|
797
822
|
{
|
|
798
|
-
square:
|
|
799
|
-
piece:
|
|
800
|
-
isLight:
|
|
801
|
-
isSelected:
|
|
802
|
-
isLegalMove: r.includes(
|
|
803
|
-
isCheck:
|
|
804
|
-
isLastMoveFrom:
|
|
805
|
-
isLastMoveTo:
|
|
806
|
-
isChaosFlash: a ===
|
|
807
|
-
rankLabel:
|
|
808
|
-
fileLabel:
|
|
809
|
-
onClick:
|
|
823
|
+
square: C,
|
|
824
|
+
piece: $,
|
|
825
|
+
isLight: Rn(d, v),
|
|
826
|
+
isSelected: C === n,
|
|
827
|
+
isLegalMove: r.includes(C),
|
|
828
|
+
isCheck: C === y,
|
|
829
|
+
isLastMoveFrom: s?.from === C,
|
|
830
|
+
isLastMoveTo: s?.to === C,
|
|
831
|
+
isChaosFlash: a === C,
|
|
832
|
+
rankLabel: I === 0 ? 8 - d : void 0,
|
|
833
|
+
fileLabel: O === 7 ? vt[v] : void 0,
|
|
834
|
+
onClick: m
|
|
810
835
|
},
|
|
811
|
-
|
|
836
|
+
C
|
|
812
837
|
);
|
|
813
838
|
})
|
|
814
839
|
) });
|
|
815
|
-
}),
|
|
816
|
-
promotionOverlay:
|
|
817
|
-
promotionDialog:
|
|
818
|
-
promotionTitle:
|
|
819
|
-
promotionOptions:
|
|
820
|
-
promotionBtn:
|
|
821
|
-
gameOverOverlay:
|
|
822
|
-
gameOverBanner:
|
|
823
|
-
gameOverResult:
|
|
824
|
-
gameOverDetail:
|
|
825
|
-
restartBtn:
|
|
826
|
-
chaosBar:
|
|
827
|
-
chaosBarLabel:
|
|
828
|
-
chaosBarTrack:
|
|
840
|
+
}), An = "_promotionOverlay_1qv8i_2", En = "_promotionDialog_1qv8i_14", In = "_promotionTitle_1qv8i_27", Fn = "_promotionOptions_1qv8i_34", xn = "_promotionBtn_1qv8i_39", $n = "_gameOverOverlay_1qv8i_66", Dn = "_gameOverBanner_1qv8i_78", Gn = "_gameOverResult_1qv8i_91", jn = "_gameOverDetail_1qv8i_100", zn = "_restartBtn_1qv8i_107", Un = "_chaosBar_1qv8i_126", Vn = "_chaosBarLabel_1qv8i_134", Hn = "_chaosBarTrack_1qv8i_143", Wn = "_chaosBarFill_1qv8i_151", Yn = "_difficultySelector_1qv8i_160", Kn = "_difficultyLabel_1qv8i_167", Xn = "_difficultySlider_1qv8i_176", Qn = "_difficultyValue_1qv8i_207", Jn = "_sidePickerOverlay_1qv8i_214", Zn = "_sidePickerCard_1qv8i_222", er = "_sidePickerTitle_1qv8i_235", tr = "_sidePickerOptions_1qv8i_243", nr = "_sidePickerBtn_1qv8i_248", rr = "_sidePickerIcon_1qv8i_268", ir = "_sidePickerLabel_1qv8i_277", sr = "_sidePickerSettings_1qv8i_284", or = "_stupidLevel_1qv8i_293", ar = "_stupidLevelHeader_1qv8i_300", cr = "_stupidLevelLabel_1qv8i_307", lr = "_stupidLevelValue_1qv8i_316", ur = "_stupidLevelSlider_1qv8i_323", dr = "_muteBtn_1qv8i_355", hr = "_muteBtnMuted_1qv8i_380", fr = "_chaosToast_1qv8i_390", pr = "_chaosToastFading_1qv8i_413", u = {
|
|
841
|
+
promotionOverlay: An,
|
|
842
|
+
promotionDialog: En,
|
|
843
|
+
promotionTitle: In,
|
|
844
|
+
promotionOptions: Fn,
|
|
845
|
+
promotionBtn: xn,
|
|
846
|
+
gameOverOverlay: $n,
|
|
847
|
+
gameOverBanner: Dn,
|
|
848
|
+
gameOverResult: Gn,
|
|
849
|
+
gameOverDetail: jn,
|
|
850
|
+
restartBtn: zn,
|
|
851
|
+
chaosBar: Un,
|
|
852
|
+
chaosBarLabel: Vn,
|
|
853
|
+
chaosBarTrack: Hn,
|
|
829
854
|
chaosBarFill: Wn,
|
|
830
|
-
difficultySelector:
|
|
831
|
-
difficultyLabel:
|
|
832
|
-
difficultySlider:
|
|
833
|
-
difficultyValue:
|
|
834
|
-
sidePickerOverlay:
|
|
835
|
-
sidePickerCard:
|
|
836
|
-
sidePickerTitle:
|
|
837
|
-
sidePickerOptions:
|
|
838
|
-
sidePickerBtn:
|
|
839
|
-
sidePickerIcon:
|
|
840
|
-
|
|
841
|
-
sidePickerBlack: nr,
|
|
842
|
-
sidePickerLabel: rr,
|
|
855
|
+
difficultySelector: Yn,
|
|
856
|
+
difficultyLabel: Kn,
|
|
857
|
+
difficultySlider: Xn,
|
|
858
|
+
difficultyValue: Qn,
|
|
859
|
+
sidePickerOverlay: Jn,
|
|
860
|
+
sidePickerCard: Zn,
|
|
861
|
+
sidePickerTitle: er,
|
|
862
|
+
sidePickerOptions: tr,
|
|
863
|
+
sidePickerBtn: nr,
|
|
864
|
+
sidePickerIcon: rr,
|
|
865
|
+
sidePickerLabel: ir,
|
|
843
866
|
sidePickerSettings: sr,
|
|
844
|
-
stupidLevel:
|
|
845
|
-
stupidLevelHeader:
|
|
846
|
-
stupidLevelLabel:
|
|
847
|
-
stupidLevelValue:
|
|
848
|
-
stupidLevelSlider:
|
|
849
|
-
muteBtn:
|
|
850
|
-
muteBtnMuted:
|
|
851
|
-
chaosToast:
|
|
852
|
-
chaosToastFading:
|
|
867
|
+
stupidLevel: or,
|
|
868
|
+
stupidLevelHeader: ar,
|
|
869
|
+
stupidLevelLabel: cr,
|
|
870
|
+
stupidLevelValue: lr,
|
|
871
|
+
stupidLevelSlider: ur,
|
|
872
|
+
muteBtn: dr,
|
|
873
|
+
muteBtnMuted: hr,
|
|
874
|
+
chaosToast: fr,
|
|
875
|
+
chaosToastFading: pr
|
|
853
876
|
}, mr = [
|
|
854
877
|
{ type: "q", label: "Queen" },
|
|
855
878
|
{ type: "r", label: "Rook" },
|
|
856
879
|
{ type: "b", label: "Bishop" },
|
|
857
880
|
{ type: "n", label: "Knight" }
|
|
858
881
|
];
|
|
859
|
-
function
|
|
860
|
-
return /* @__PURE__ */ l("div", { className: u.promotionOverlay, children: /* @__PURE__ */
|
|
882
|
+
function vr({ color: t, onSelect: e }) {
|
|
883
|
+
return /* @__PURE__ */ l("div", { className: u.promotionOverlay, children: /* @__PURE__ */ L("div", { className: u.promotionDialog, children: [
|
|
861
884
|
/* @__PURE__ */ l("h3", { className: u.promotionTitle, children: "Promote pawn" }),
|
|
862
885
|
/* @__PURE__ */ l("div", { className: u.promotionOptions, children: mr.map(({ type: n, label: r }) => /* @__PURE__ */ l(
|
|
863
886
|
"button",
|
|
@@ -866,26 +889,26 @@ function pr({ color: t, onSelect: e }) {
|
|
|
866
889
|
className: u.promotionBtn,
|
|
867
890
|
onClick: () => e(n),
|
|
868
891
|
title: r,
|
|
869
|
-
children: /* @__PURE__ */ l(
|
|
892
|
+
children: /* @__PURE__ */ l(we, { type: n, color: t })
|
|
870
893
|
},
|
|
871
894
|
n
|
|
872
895
|
)) })
|
|
873
896
|
] }) });
|
|
874
897
|
}
|
|
875
|
-
function
|
|
898
|
+
function kr(t, e) {
|
|
876
899
|
return t.result === "checkmate" ? t.winner === e ? { title: "You Win!", detail: "Checkmate" } : { title: "You Lose", detail: "Checkmate" } : t.result === "stalemate" ? { title: "Draw", detail: "Stalemate" } : t.result === "insufficient" ? { title: "Draw", detail: "Insufficient material" } : t.result === "threefold" ? { title: "Draw", detail: "Threefold repetition" } : t.result === "fifty-move" ? { title: "Draw", detail: "Fifty-move rule" } : t.result === "king-captured" ? { title: t.winner === e ? "You Win!" : "You Lose", detail: "King captured" } : { title: "Draw", detail: "Game over" };
|
|
877
900
|
}
|
|
878
|
-
function
|
|
879
|
-
const { title: r, detail:
|
|
880
|
-
return /* @__PURE__ */ l("div", { className: u.gameOverOverlay, children: /* @__PURE__ */
|
|
901
|
+
function gr({ status: t, humanColor: e, onRestart: n }) {
|
|
902
|
+
const { title: r, detail: i } = kr(t, e);
|
|
903
|
+
return /* @__PURE__ */ l("div", { className: u.gameOverOverlay, children: /* @__PURE__ */ L("div", { className: u.gameOverBanner, children: [
|
|
881
904
|
/* @__PURE__ */ l("h2", { className: u.gameOverResult, children: r }),
|
|
882
|
-
/* @__PURE__ */ l("p", { className: u.gameOverDetail, children:
|
|
905
|
+
/* @__PURE__ */ l("p", { className: u.gameOverDetail, children: i }),
|
|
883
906
|
/* @__PURE__ */ l("button", { type: "button", className: u.restartBtn, onClick: n, children: "Play Again" })
|
|
884
907
|
] }) });
|
|
885
908
|
}
|
|
886
|
-
function
|
|
909
|
+
function yr({ countdown: t, maxCountdown: e }) {
|
|
887
910
|
const n = e > 0 ? (e - t) / e * 100 : 0, r = 1 - (t / e || 0);
|
|
888
|
-
return /* @__PURE__ */
|
|
911
|
+
return /* @__PURE__ */ L("div", { className: u.chaosBar, children: [
|
|
889
912
|
/* @__PURE__ */ l("span", { className: u.chaosBarLabel, children: "STUPIDITY" }),
|
|
890
913
|
/* @__PURE__ */ l("div", { className: u.chaosBarTrack, children: /* @__PURE__ */ l(
|
|
891
914
|
"div",
|
|
@@ -899,24 +922,24 @@ function _r({ countdown: t, maxCountdown: e }) {
|
|
|
899
922
|
) })
|
|
900
923
|
] });
|
|
901
924
|
}
|
|
902
|
-
function
|
|
903
|
-
const [e, n] =
|
|
904
|
-
if (
|
|
925
|
+
function _r({ action: t }) {
|
|
926
|
+
const [e, n] = k(!1), [r, i] = k(!1), [s, a] = k(null), o = w(void 0);
|
|
927
|
+
if (B(() => {
|
|
905
928
|
if (t)
|
|
906
|
-
return o.current && clearTimeout(o.current), a(t),
|
|
907
|
-
|
|
908
|
-
n(!1),
|
|
929
|
+
return o.current && clearTimeout(o.current), a(t), i(!1), n(!0), o.current = setTimeout(() => {
|
|
930
|
+
i(!0), o.current = setTimeout(() => {
|
|
931
|
+
n(!1), i(!1);
|
|
909
932
|
}, 400);
|
|
910
933
|
}, 1600), () => {
|
|
911
934
|
o.current && clearTimeout(o.current);
|
|
912
935
|
};
|
|
913
|
-
}, [t]), !e || !
|
|
914
|
-
const c =
|
|
936
|
+
}, [t]), !e || !s) return null;
|
|
937
|
+
const c = s.type === "add" && s.piece && s.color ? `A ${mt(s.piece, s.color)} appeared on ${s.square}!` : `The piece on ${s.square} vanished!`;
|
|
915
938
|
return /* @__PURE__ */ l("div", { className: `${u.chaosToast} ${r ? u.chaosToastFading : ""}`, children: c });
|
|
916
939
|
}
|
|
917
|
-
function
|
|
918
|
-
return /* @__PURE__ */
|
|
919
|
-
/* @__PURE__ */
|
|
940
|
+
function kt({ depth: t, onChange: e }) {
|
|
941
|
+
return /* @__PURE__ */ L("div", { className: u.difficultySelector, children: [
|
|
942
|
+
/* @__PURE__ */ L("span", { className: u.difficultyLabel, children: [
|
|
920
943
|
"AI Depth: ",
|
|
921
944
|
/* @__PURE__ */ l("span", { className: u.difficultyValue, children: t })
|
|
922
945
|
] }),
|
|
@@ -934,10 +957,10 @@ function vt({ depth: t, onChange: e }) {
|
|
|
934
957
|
] });
|
|
935
958
|
}
|
|
936
959
|
const wr = ["OFF", "CHILL", "MID", "STUPID", "CHAOS", "LOL"];
|
|
937
|
-
function
|
|
938
|
-
return /* @__PURE__ */
|
|
939
|
-
/* @__PURE__ */
|
|
940
|
-
/* @__PURE__ */ l("span", { className: u.stupidLevelLabel, children: "
|
|
960
|
+
function gt({ level: t, onChange: e }) {
|
|
961
|
+
return /* @__PURE__ */ L("div", { className: u.stupidLevel, children: [
|
|
962
|
+
/* @__PURE__ */ L("div", { className: u.stupidLevelHeader, children: [
|
|
963
|
+
/* @__PURE__ */ l("span", { className: u.stupidLevelLabel, children: "Stupid level" }),
|
|
941
964
|
/* @__PURE__ */ l("span", { className: u.stupidLevelValue, children: wr[t] })
|
|
942
965
|
] }),
|
|
943
966
|
/* @__PURE__ */ l(
|
|
@@ -954,38 +977,38 @@ function _t({ level: t, onChange: e }) {
|
|
|
954
977
|
)
|
|
955
978
|
] });
|
|
956
979
|
}
|
|
957
|
-
function
|
|
958
|
-
return /* @__PURE__ */ l("div", { className: u.sidePickerOverlay, children: /* @__PURE__ */
|
|
980
|
+
function Cr({ depth: t, onDepthChange: e, stupidLevel: n, onStupidLevelChange: r, onSelectSide: i }) {
|
|
981
|
+
return /* @__PURE__ */ l("div", { className: u.sidePickerOverlay, children: /* @__PURE__ */ L("div", { className: u.sidePickerCard, children: [
|
|
959
982
|
/* @__PURE__ */ l("h2", { className: u.sidePickerTitle, children: "Choose Your Side" }),
|
|
960
|
-
/* @__PURE__ */
|
|
961
|
-
/* @__PURE__ */
|
|
983
|
+
/* @__PURE__ */ L("div", { className: u.sidePickerOptions, children: [
|
|
984
|
+
/* @__PURE__ */ L(
|
|
962
985
|
"button",
|
|
963
986
|
{
|
|
964
987
|
type: "button",
|
|
965
988
|
className: u.sidePickerBtn,
|
|
966
|
-
onClick: () =>
|
|
989
|
+
onClick: () => i("w"),
|
|
967
990
|
children: [
|
|
968
|
-
/* @__PURE__ */ l("
|
|
991
|
+
/* @__PURE__ */ l(we, { type: "k", color: "w", className: u.sidePickerIcon }),
|
|
969
992
|
/* @__PURE__ */ l("span", { className: u.sidePickerLabel, children: "White" })
|
|
970
993
|
]
|
|
971
994
|
}
|
|
972
995
|
),
|
|
973
|
-
/* @__PURE__ */
|
|
996
|
+
/* @__PURE__ */ L(
|
|
974
997
|
"button",
|
|
975
998
|
{
|
|
976
999
|
type: "button",
|
|
977
1000
|
className: u.sidePickerBtn,
|
|
978
|
-
onClick: () =>
|
|
1001
|
+
onClick: () => i("b"),
|
|
979
1002
|
children: [
|
|
980
|
-
/* @__PURE__ */ l("
|
|
1003
|
+
/* @__PURE__ */ l(we, { type: "k", color: "b", className: u.sidePickerIcon }),
|
|
981
1004
|
/* @__PURE__ */ l("span", { className: u.sidePickerLabel, children: "Black" })
|
|
982
1005
|
]
|
|
983
1006
|
}
|
|
984
1007
|
)
|
|
985
1008
|
] }),
|
|
986
|
-
/* @__PURE__ */
|
|
987
|
-
/* @__PURE__ */ l(
|
|
988
|
-
/* @__PURE__ */ l(
|
|
1009
|
+
/* @__PURE__ */ L("div", { className: u.sidePickerSettings, children: [
|
|
1010
|
+
/* @__PURE__ */ l(kt, { depth: t, onChange: e }),
|
|
1011
|
+
/* @__PURE__ */ l(gt, { level: n, onChange: r })
|
|
989
1012
|
] })
|
|
990
1013
|
] }) });
|
|
991
1014
|
}
|
|
@@ -997,12 +1020,31 @@ function br({ muted: t, onToggle: e }) {
|
|
|
997
1020
|
className: `${u.muteBtn} ${t ? u.muteBtnMuted : ""}`,
|
|
998
1021
|
onClick: e,
|
|
999
1022
|
title: t ? "Unmute" : "Mute",
|
|
1000
|
-
|
|
1023
|
+
"aria-label": "Mute",
|
|
1024
|
+
"aria-pressed": t,
|
|
1025
|
+
children: /* @__PURE__ */ L(
|
|
1026
|
+
"svg",
|
|
1027
|
+
{
|
|
1028
|
+
viewBox: "0 0 24 24",
|
|
1029
|
+
width: "16",
|
|
1030
|
+
height: "16",
|
|
1031
|
+
fill: "none",
|
|
1032
|
+
stroke: "currentColor",
|
|
1033
|
+
strokeWidth: "2",
|
|
1034
|
+
strokeLinecap: "round",
|
|
1035
|
+
strokeLinejoin: "round",
|
|
1036
|
+
"aria-hidden": "true",
|
|
1037
|
+
children: [
|
|
1038
|
+
/* @__PURE__ */ l("path", { d: "M11 5 6 9H3v6h3l5 4V5z" }),
|
|
1039
|
+
t ? /* @__PURE__ */ l("path", { d: "m22 9-6 6M16 9l6 6" }) : /* @__PURE__ */ l("path", { d: "M15.5 8.5a5 5 0 0 1 0 7M18.5 5.5a9 9 0 0 1 0 13" })
|
|
1040
|
+
]
|
|
1041
|
+
}
|
|
1042
|
+
)
|
|
1001
1043
|
}
|
|
1002
1044
|
);
|
|
1003
1045
|
}
|
|
1004
1046
|
let oe = null;
|
|
1005
|
-
class
|
|
1047
|
+
class Lr {
|
|
1006
1048
|
muted;
|
|
1007
1049
|
constructor(e = !1) {
|
|
1008
1050
|
this.muted = e;
|
|
@@ -1032,15 +1074,15 @@ class Sr {
|
|
|
1032
1074
|
playCapture() {
|
|
1033
1075
|
const e = this.getCtx();
|
|
1034
1076
|
if (!e) return;
|
|
1035
|
-
const n = e.sampleRate * 0.1, r = e.createBuffer(1, n, e.sampleRate),
|
|
1077
|
+
const n = e.sampleRate * 0.1, r = e.createBuffer(1, n, e.sampleRate), i = r.getChannelData(0);
|
|
1036
1078
|
for (let c = 0; c < n; c++)
|
|
1037
|
-
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1079
|
+
i[c] = (Math.random() * 2 - 1) * Math.exp(-c / (e.sampleRate * 0.015));
|
|
1080
|
+
const s = e.createBufferSource();
|
|
1081
|
+
s.buffer = r;
|
|
1040
1082
|
const a = e.createBiquadFilter();
|
|
1041
1083
|
a.type = "bandpass", a.frequency.value = 3e3, a.Q.value = 2;
|
|
1042
1084
|
const o = e.createGain();
|
|
1043
|
-
o.gain.setValueAtTime(0.35, e.currentTime), o.gain.exponentialRampToValueAtTime(1e-3, e.currentTime + 0.1),
|
|
1085
|
+
o.gain.setValueAtTime(0.35, e.currentTime), o.gain.exponentialRampToValueAtTime(1e-3, e.currentTime + 0.1), s.connect(a).connect(o).connect(e.destination), s.start(), s.stop(e.currentTime + 0.1);
|
|
1044
1086
|
}
|
|
1045
1087
|
playCheck() {
|
|
1046
1088
|
const e = this.getCtx();
|
|
@@ -1059,27 +1101,27 @@ class Sr {
|
|
|
1059
1101
|
if (!e) return;
|
|
1060
1102
|
const n = [261.63, 329.63, 392];
|
|
1061
1103
|
for (const r of n) {
|
|
1062
|
-
const
|
|
1063
|
-
|
|
1104
|
+
const i = e.createOscillator(), s = e.createGain();
|
|
1105
|
+
i.type = "sine", i.frequency.value = r, s.gain.setValueAtTime(0.1, e.currentTime), s.gain.exponentialRampToValueAtTime(1e-3, e.currentTime + 0.4), i.connect(s).connect(e.destination), i.start(), i.stop(e.currentTime + 0.4);
|
|
1064
1106
|
}
|
|
1065
1107
|
}
|
|
1066
1108
|
}
|
|
1067
|
-
function
|
|
1109
|
+
function be(t) {
|
|
1068
1110
|
return typeof t == "number" && Number.isFinite(t);
|
|
1069
1111
|
}
|
|
1070
|
-
function
|
|
1071
|
-
return
|
|
1112
|
+
function Mr(t) {
|
|
1113
|
+
return be(t) ? Math.min(20, Math.max(1, Math.round(t))) : 10;
|
|
1072
1114
|
}
|
|
1073
|
-
function
|
|
1074
|
-
return
|
|
1115
|
+
function Sr(t) {
|
|
1116
|
+
return be(t) ? Math.min(5, Math.max(0, Math.round(t))) : 3;
|
|
1075
1117
|
}
|
|
1076
|
-
function
|
|
1118
|
+
function Tr(t) {
|
|
1077
1119
|
if (!t || typeof t != "object") return null;
|
|
1078
1120
|
const e = t;
|
|
1079
|
-
if (e.version !== 1 || e.phase !== "setup" && e.phase !== "playing" || e.humanColor !== "w" && e.humanColor !== "b" || !
|
|
1121
|
+
if (e.version !== 1 || e.phase !== "setup" && e.phase !== "playing" || e.humanColor !== "w" && e.humanColor !== "b" || !be(e.depth) || !be(e.stupidLevel) || typeof e.fen != "string") return null;
|
|
1080
1122
|
let n;
|
|
1081
1123
|
try {
|
|
1082
|
-
n =
|
|
1124
|
+
n = W(e.fen);
|
|
1083
1125
|
} catch {
|
|
1084
1126
|
return null;
|
|
1085
1127
|
}
|
|
@@ -1088,225 +1130,225 @@ function Mr(t) {
|
|
|
1088
1130
|
phase: e.phase,
|
|
1089
1131
|
fen: n,
|
|
1090
1132
|
humanColor: e.humanColor,
|
|
1091
|
-
depth:
|
|
1092
|
-
stupidLevel:
|
|
1133
|
+
depth: Mr(e.depth),
|
|
1134
|
+
stupidLevel: Sr(e.stupidLevel),
|
|
1093
1135
|
muted: e.muted === !0
|
|
1094
1136
|
} : null;
|
|
1095
1137
|
}
|
|
1096
|
-
const
|
|
1097
|
-
container:
|
|
1138
|
+
const qr = "_container_25ulv_1", Pr = "_topBar_25ulv_11", Br = "_topBarLeft_25ulv_23", Or = "_topBarRight_25ulv_29", Rr = "_newGameBtn_25ulv_35", Nr = "_aiUnavailable_25ulv_59", Ar = "_statusText_25ulv_65", Er = "_thinking_25ulv_71", Ir = "_bottomBar_25ulv_81", H = {
|
|
1139
|
+
container: qr,
|
|
1098
1140
|
topBar: Pr,
|
|
1099
1141
|
topBarLeft: Br,
|
|
1100
1142
|
topBarRight: Or,
|
|
1101
1143
|
newGameBtn: Rr,
|
|
1102
1144
|
aiUnavailable: Nr,
|
|
1103
|
-
statusText:
|
|
1104
|
-
thinking:
|
|
1105
|
-
bottomBar:
|
|
1106
|
-
},
|
|
1145
|
+
statusText: Ar,
|
|
1146
|
+
thinking: Er,
|
|
1147
|
+
bottomBar: Ir
|
|
1148
|
+
}, st = 2;
|
|
1107
1149
|
function Dr(t) {
|
|
1108
1150
|
const {
|
|
1109
1151
|
defaultDepth: e = 10,
|
|
1110
1152
|
defaultStupidLevel: n = 3,
|
|
1111
1153
|
defaultHumanColor: r,
|
|
1112
|
-
defaultMuted:
|
|
1113
|
-
depth:
|
|
1154
|
+
defaultMuted: i = !1,
|
|
1155
|
+
depth: s,
|
|
1114
1156
|
onDepthChange: a,
|
|
1115
1157
|
stupidLevel: o,
|
|
1116
1158
|
onStupidLevelChange: c,
|
|
1117
|
-
stockfishWorkerPath:
|
|
1118
|
-
skipSetup:
|
|
1119
|
-
showControls:
|
|
1120
|
-
showMuteButton:
|
|
1121
|
-
initialState:
|
|
1122
|
-
onStateChange:
|
|
1123
|
-
onGameOver:
|
|
1124
|
-
onMove:
|
|
1125
|
-
onChaosAction:
|
|
1126
|
-
onRestart:
|
|
1127
|
-
className:
|
|
1128
|
-
} = t, [
|
|
1129
|
-
if (!
|
|
1130
|
-
const h =
|
|
1159
|
+
stockfishWorkerPath: m,
|
|
1160
|
+
skipSetup: y = !1,
|
|
1161
|
+
showControls: g = !0,
|
|
1162
|
+
showMuteButton: _ = !0,
|
|
1163
|
+
initialState: d,
|
|
1164
|
+
onStateChange: v,
|
|
1165
|
+
onGameOver: C,
|
|
1166
|
+
onMove: $,
|
|
1167
|
+
onChaosAction: O,
|
|
1168
|
+
onRestart: I,
|
|
1169
|
+
className: j
|
|
1170
|
+
} = t, [P] = k(() => {
|
|
1171
|
+
if (!d) return null;
|
|
1172
|
+
const h = Tr(d);
|
|
1131
1173
|
return h || console.warn("[ChaosChess] Ignoring invalid initialState"), h;
|
|
1132
|
-
}), [
|
|
1133
|
-
|
|
1134
|
-
),
|
|
1135
|
-
|
|
1136
|
-
), [
|
|
1137
|
-
fen:
|
|
1138
|
-
turn:
|
|
1139
|
-
selectedSquare:
|
|
1140
|
-
legalMoves:
|
|
1141
|
-
gameStatus:
|
|
1142
|
-
promotionPending:
|
|
1143
|
-
lastMove:
|
|
1144
|
-
lastMoveDetail:
|
|
1174
|
+
}), [D, ne] = k(P?.depth ?? e), p = s ?? D, M = a ?? ne, [F, re] = k(P?.stupidLevel ?? n), E = o ?? F, fe = c ?? re, [Me, Se] = k(
|
|
1175
|
+
P?.humanColor ?? r ?? "w"
|
|
1176
|
+
), f = Me, [b, z] = k(P?.muted ?? i), [q] = k(() => new Lr(P?.muted ?? i)), [T, X] = k(
|
|
1177
|
+
P?.phase ?? (y || r ? "playing" : "setup")
|
|
1178
|
+
), [yt, _t] = k(0), {
|
|
1179
|
+
fen: R,
|
|
1180
|
+
turn: ie,
|
|
1181
|
+
selectedSquare: wt,
|
|
1182
|
+
legalMoves: Ct,
|
|
1183
|
+
gameStatus: N,
|
|
1184
|
+
promotionPending: Fe,
|
|
1185
|
+
lastMove: bt,
|
|
1186
|
+
lastMoveDetail: pe,
|
|
1145
1187
|
moveHistory: Q,
|
|
1146
|
-
board:
|
|
1147
|
-
handleSquareClick:
|
|
1148
|
-
handlePromotion:
|
|
1149
|
-
applyFen:
|
|
1150
|
-
applyMove:
|
|
1151
|
-
handleRestart:
|
|
1152
|
-
} =
|
|
1153
|
-
status:
|
|
1154
|
-
isReady:
|
|
1188
|
+
board: Lt,
|
|
1189
|
+
handleSquareClick: xe,
|
|
1190
|
+
handlePromotion: Mt,
|
|
1191
|
+
applyFen: $e,
|
|
1192
|
+
applyMove: De,
|
|
1193
|
+
handleRestart: Ge
|
|
1194
|
+
} = jt(P?.fen), {
|
|
1195
|
+
status: Te,
|
|
1196
|
+
isReady: me,
|
|
1155
1197
|
isThinking: J,
|
|
1156
|
-
getBestMove:
|
|
1157
|
-
cancel:
|
|
1158
|
-
} = Jt(
|
|
1198
|
+
getBestMove: je,
|
|
1199
|
+
cancel: ze
|
|
1200
|
+
} = Jt(m), ve = Te !== "failed", Z = ie === f, ke = w(R), Ue = w(f), qe = w(T);
|
|
1159
1201
|
ot(() => {
|
|
1160
|
-
|
|
1161
|
-
}, [
|
|
1162
|
-
const
|
|
1163
|
-
fen:
|
|
1164
|
-
isPaused:
|
|
1165
|
-
stupidLevel: Math.max(1,
|
|
1166
|
-
resetKey:
|
|
1167
|
-
onChaosAction:
|
|
1168
|
-
const
|
|
1169
|
-
if (
|
|
1170
|
-
const
|
|
1171
|
-
return he(
|
|
1172
|
-
}, [
|
|
1173
|
-
}),
|
|
1174
|
-
|
|
1175
|
-
ee && ee !==
|
|
1176
|
-
}, [ee,
|
|
1177
|
-
const
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
}, [
|
|
1202
|
+
ke.current = R, Ue.current = f, qe.current = T;
|
|
1203
|
+
}, [R, f, T]);
|
|
1204
|
+
const Pe = w(0), Ve = E > 0, St = T !== "playing" || !Ve || !Z || J || !!Fe || N.isGameOver, { countdown: Tt, maxCountdown: qt, lastAction: ee, chaosSquare: Be } = un({
|
|
1205
|
+
fen: R,
|
|
1206
|
+
isPaused: St,
|
|
1207
|
+
stupidLevel: Math.max(1, E),
|
|
1208
|
+
resetKey: yt,
|
|
1209
|
+
onChaosAction: S((h) => {
|
|
1210
|
+
const x = new de(ke.current);
|
|
1211
|
+
if (x.turn() !== Ue.current || ue(x).isGameOver) return !1;
|
|
1212
|
+
const U = W(h);
|
|
1213
|
+
return he(U) ? ($e(U), !0) : !1;
|
|
1214
|
+
}, [$e])
|
|
1215
|
+
}), He = w(ee);
|
|
1216
|
+
B(() => {
|
|
1217
|
+
ee && ee !== He.current && O?.(ee, R), He.current = ee;
|
|
1218
|
+
}, [ee, R, O]);
|
|
1219
|
+
const We = w(v);
|
|
1220
|
+
B(() => {
|
|
1221
|
+
We.current = v;
|
|
1222
|
+
}, [v]), B(() => {
|
|
1181
1223
|
const h = {
|
|
1182
1224
|
version: 1,
|
|
1183
|
-
phase:
|
|
1184
|
-
fen:
|
|
1185
|
-
humanColor:
|
|
1186
|
-
depth:
|
|
1187
|
-
stupidLevel:
|
|
1188
|
-
muted:
|
|
1225
|
+
phase: T,
|
|
1226
|
+
fen: R,
|
|
1227
|
+
humanColor: f,
|
|
1228
|
+
depth: p,
|
|
1229
|
+
stupidLevel: E,
|
|
1230
|
+
muted: b
|
|
1189
1231
|
};
|
|
1190
|
-
|
|
1191
|
-
}, [
|
|
1192
|
-
const
|
|
1232
|
+
We.current?.(h);
|
|
1233
|
+
}, [T, R, f, p, E, b]);
|
|
1234
|
+
const se = w(null), ge = w({ fen: "", count: 0 }), ye = S((h, x) => De(
|
|
1193
1235
|
{
|
|
1194
|
-
from:
|
|
1195
|
-
to:
|
|
1196
|
-
promotion:
|
|
1236
|
+
from: x.slice(0, 2),
|
|
1237
|
+
to: x.slice(2, 4),
|
|
1238
|
+
promotion: x.length > 4 ? x[4] : void 0
|
|
1197
1239
|
},
|
|
1198
1240
|
h
|
|
1199
|
-
), [
|
|
1200
|
-
if (
|
|
1201
|
-
const
|
|
1202
|
-
if (ue(
|
|
1203
|
-
const
|
|
1204
|
-
if (
|
|
1205
|
-
const te =
|
|
1206
|
-
return console.warn(`[ChaosChess] ${
|
|
1207
|
-
}, [
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1241
|
+
), [De]), Ye = S((h, x) => {
|
|
1242
|
+
if (ke.current !== h || qe.current !== "playing") return !0;
|
|
1243
|
+
const U = new de(h);
|
|
1244
|
+
if (ue(U).isGameOver) return !1;
|
|
1245
|
+
const V = U.moves({ verbose: !0 });
|
|
1246
|
+
if (V.length === 0) return !1;
|
|
1247
|
+
const te = V[Math.floor(Math.random() * V.length)];
|
|
1248
|
+
return console.warn(`[ChaosChess] ${x}; playing random move ${te.lan}`), ye(h, te.lan);
|
|
1249
|
+
}, [ye]), _e = S((h) => {
|
|
1250
|
+
const x = Pe.current, U = () => Pe.current !== x || qe.current !== "playing", V = (G) => {
|
|
1251
|
+
U() || Ye(h, G) || (se.current = h);
|
|
1210
1252
|
};
|
|
1211
|
-
if (!he(
|
|
1212
|
-
|
|
1253
|
+
if (!he(W(h))) {
|
|
1254
|
+
V("Position not supported by Stockfish");
|
|
1213
1255
|
return;
|
|
1214
1256
|
}
|
|
1215
|
-
const te =
|
|
1216
|
-
if (te >=
|
|
1217
|
-
|
|
1257
|
+
const te = ge.current.fen === h ? ge.current.count : 0;
|
|
1258
|
+
if (te >= st) {
|
|
1259
|
+
V("Stockfish keeps failing on this position");
|
|
1218
1260
|
return;
|
|
1219
1261
|
}
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
if (!
|
|
1223
|
-
if (!
|
|
1224
|
-
|
|
1262
|
+
const Rt = te > 0 ? Math.max(1, Math.floor(p / 2)) : p;
|
|
1263
|
+
je(h, Rt).then((G) => {
|
|
1264
|
+
if (!U() && ke.current === h) {
|
|
1265
|
+
if (!G) {
|
|
1266
|
+
V("Stockfish returned no move");
|
|
1225
1267
|
return;
|
|
1226
1268
|
}
|
|
1227
|
-
|
|
1269
|
+
se.current = null, ye(h, G) || V(`Stockfish move ${G} is not legal here`);
|
|
1228
1270
|
}
|
|
1229
|
-
}).catch((
|
|
1230
|
-
|
|
1271
|
+
}).catch((G) => {
|
|
1272
|
+
U() || G instanceof ae || G instanceof Re || (ge.current = { fen: h, count: te + 1 }, te + 1 >= st && V(`Stockfish failed (${G?.message ?? G})`));
|
|
1231
1273
|
});
|
|
1232
|
-
}, [
|
|
1233
|
-
|
|
1234
|
-
}, []),
|
|
1235
|
-
|
|
1236
|
-
}, [
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
}, [
|
|
1240
|
-
const Xe =
|
|
1241
|
-
|
|
1274
|
+
}, [je, p, ye, Ye]), Pt = S((h) => {
|
|
1275
|
+
Se(h), X("playing");
|
|
1276
|
+
}, []), Ke = S(() => {
|
|
1277
|
+
Pe.current++, ze(), Ge(), se.current = null, ge.current = { fen: "", count: 0 }, _t((h) => h + 1), X(y || r ? "playing" : "setup"), I?.();
|
|
1278
|
+
}, [Ge, ze, y, r, I]);
|
|
1279
|
+
B(() => {
|
|
1280
|
+
q.setMuted(b);
|
|
1281
|
+
}, [q, b]);
|
|
1282
|
+
const Xe = w(Q.length);
|
|
1283
|
+
B(() => {
|
|
1242
1284
|
if (Q.length > Xe.current) {
|
|
1243
|
-
|
|
1285
|
+
pe && (pe.check ? q.playCheck() : pe.captured ? q.playCapture() : q.playMove());
|
|
1244
1286
|
const h = Q[Q.length - 1];
|
|
1245
|
-
h &&
|
|
1287
|
+
h && $?.(h.fen, h.san, h.color);
|
|
1246
1288
|
}
|
|
1247
1289
|
Xe.current = Q.length;
|
|
1248
|
-
}, [Q.length,
|
|
1249
|
-
|
|
1250
|
-
}, [
|
|
1251
|
-
const Qe =
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
}, [
|
|
1255
|
-
|
|
1256
|
-
}, [
|
|
1257
|
-
if (
|
|
1258
|
-
const h = setTimeout(() =>
|
|
1290
|
+
}, [Q.length, pe, Q, $, q]), B(() => {
|
|
1291
|
+
Be && q.playChaos();
|
|
1292
|
+
}, [Be, q]);
|
|
1293
|
+
const Qe = w(N.isGameOver);
|
|
1294
|
+
B(() => {
|
|
1295
|
+
N.isGameOver && !Qe.current && (q.playGameOver(), C?.(N)), Qe.current = N.isGameOver;
|
|
1296
|
+
}, [N, C, q]), B(() => {
|
|
1297
|
+
T === "playing" && (Z || N.isGameOver || !me || J || se.current !== R && _e(R));
|
|
1298
|
+
}, [T, R, Z, N.isGameOver, me, J, _e]), B(() => {
|
|
1299
|
+
if (T !== "playing" || Z || J || N.isGameOver || !me || se.current === R) return;
|
|
1300
|
+
const h = setTimeout(() => _e(R), 3e3);
|
|
1259
1301
|
return () => clearTimeout(h);
|
|
1260
|
-
}, [
|
|
1261
|
-
const
|
|
1302
|
+
}, [T, Z, J, N.isGameOver, me, R, _e]);
|
|
1303
|
+
const Bt = S(
|
|
1262
1304
|
(h) => {
|
|
1263
|
-
|
|
1305
|
+
ve && ie !== f || xe(h);
|
|
1264
1306
|
},
|
|
1265
|
-
[
|
|
1266
|
-
),
|
|
1267
|
-
return
|
|
1268
|
-
|
|
1307
|
+
[ve, ie, f, xe]
|
|
1308
|
+
), Ot = N.isGameOver ? "Game Over" : J ? "" : ve ? Z ? "Your turn" : Te === "loading" ? "Loading engine..." : "Opponent thinking..." : `${ie === "w" ? "White" : "Black"} to move`, Je = [H.container, j].filter(Boolean).join(" ");
|
|
1309
|
+
return T === "setup" ? /* @__PURE__ */ l("div", { className: Je, "data-chaos-chess": "", children: /* @__PURE__ */ l(
|
|
1310
|
+
Cr,
|
|
1269
1311
|
{
|
|
1270
|
-
depth:
|
|
1271
|
-
onDepthChange:
|
|
1272
|
-
stupidLevel:
|
|
1273
|
-
onStupidLevelChange:
|
|
1274
|
-
onSelectSide:
|
|
1312
|
+
depth: p,
|
|
1313
|
+
onDepthChange: M,
|
|
1314
|
+
stupidLevel: E,
|
|
1315
|
+
onStupidLevelChange: fe,
|
|
1316
|
+
onSelectSide: Pt
|
|
1275
1317
|
}
|
|
1276
|
-
) }) : /* @__PURE__ */
|
|
1277
|
-
/* @__PURE__ */
|
|
1278
|
-
/* @__PURE__ */
|
|
1279
|
-
/* @__PURE__ */ l("span", { className:
|
|
1280
|
-
J && /* @__PURE__ */ l("span", { className:
|
|
1281
|
-
|
|
1318
|
+
) }) : /* @__PURE__ */ L("div", { className: Je, "data-chaos-chess": "", children: [
|
|
1319
|
+
/* @__PURE__ */ L("div", { className: H.topBar, children: [
|
|
1320
|
+
/* @__PURE__ */ L("div", { className: H.topBarLeft, children: [
|
|
1321
|
+
/* @__PURE__ */ l("span", { className: H.statusText, children: Ot }),
|
|
1322
|
+
J && /* @__PURE__ */ l("span", { className: H.thinking, children: "AI thinking..." }),
|
|
1323
|
+
Te === "failed" && /* @__PURE__ */ l("span", { className: H.aiUnavailable, role: "status", children: "AI unavailable" })
|
|
1282
1324
|
] }),
|
|
1283
|
-
/* @__PURE__ */
|
|
1284
|
-
/* @__PURE__ */ l("button", { type: "button", className:
|
|
1285
|
-
|
|
1325
|
+
/* @__PURE__ */ L("div", { className: H.topBarRight, children: [
|
|
1326
|
+
/* @__PURE__ */ l("button", { type: "button", className: H.newGameBtn, onClick: Ke, title: "Start a new game", children: "New game" }),
|
|
1327
|
+
_ && /* @__PURE__ */ l(br, { muted: b, onToggle: () => z((h) => !h) })
|
|
1286
1328
|
] })
|
|
1287
1329
|
] }),
|
|
1288
|
-
|
|
1330
|
+
Ve && /* @__PURE__ */ l(yr, { countdown: Tt, maxCountdown: qt }),
|
|
1289
1331
|
/* @__PURE__ */ l(
|
|
1290
|
-
|
|
1332
|
+
Nn,
|
|
1291
1333
|
{
|
|
1292
|
-
board:
|
|
1293
|
-
selectedSquare:
|
|
1294
|
-
legalMoves:
|
|
1295
|
-
inCheck:
|
|
1296
|
-
lastMove:
|
|
1297
|
-
chaosSquare:
|
|
1298
|
-
flipped:
|
|
1299
|
-
locked:
|
|
1300
|
-
onSquareClick:
|
|
1334
|
+
board: Lt,
|
|
1335
|
+
selectedSquare: wt,
|
|
1336
|
+
legalMoves: Ct,
|
|
1337
|
+
inCheck: N.inCheck,
|
|
1338
|
+
lastMove: bt,
|
|
1339
|
+
chaosSquare: Be,
|
|
1340
|
+
flipped: f === "b",
|
|
1341
|
+
locked: ve && !Z,
|
|
1342
|
+
onSquareClick: Bt
|
|
1301
1343
|
}
|
|
1302
1344
|
),
|
|
1303
|
-
|
|
1304
|
-
/* @__PURE__ */ l(
|
|
1305
|
-
/* @__PURE__ */ l(
|
|
1345
|
+
g && /* @__PURE__ */ L("div", { className: H.bottomBar, children: [
|
|
1346
|
+
/* @__PURE__ */ l(kt, { depth: p, onChange: M }),
|
|
1347
|
+
/* @__PURE__ */ l(gt, { level: E, onChange: fe })
|
|
1306
1348
|
] }),
|
|
1307
|
-
/* @__PURE__ */ l(
|
|
1308
|
-
|
|
1309
|
-
|
|
1349
|
+
/* @__PURE__ */ l(_r, { action: ee }),
|
|
1350
|
+
Fe && /* @__PURE__ */ l(vr, { color: ie, onSelect: Mt }),
|
|
1351
|
+
N.isGameOver && /* @__PURE__ */ l(gr, { status: N, humanColor: f, onRestart: Ke })
|
|
1310
1352
|
] });
|
|
1311
1353
|
}
|
|
1312
1354
|
export {
|