@maxr0ssi/chaos-chess 0.1.7 → 0.2.0

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