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