@maxr0ssi/chaos-chess 0.1.6 → 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)), [_, b] = d(null), [g, v] = d([]), [k, R] = d(null), [$, I] = d(null), [x, T] = d(t.current.board()), h = N(() => {
9
- c(null), l([]);
10
- }, []), D = N(() => {
11
- n(t.current.fen()), o(t.current.turn()), T(t.current.board()), f(pe(t.current));
12
- }, []), le = N((L) => {
13
- const m = t.current, S = 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(L)) {
17
- const q = m.get(r);
18
- if (q?.type === "p" && (q.color === "w" && L[1] === "8" || q.color === "b" && L[1] === "1")) {
19
- b({ from: r, to: L }), 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 M = m.move({ from: r, to: L });
24
- M && (R({ from: M.from, to: M.to }), I({ captured: !!M.captured, check: M.san.includes("+") || M.san.includes("#") }), v((P) => [
25
- ...P,
26
- { san: M.san, fen: m.fen(), color: M.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(L);
34
- if (H && H.color === S) {
35
- if (L === 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(L);
40
- const q = m.moves({ square: L, verbose: !0 });
41
- l(q.map((M) => M.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((L) => {
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 S = m.move({
50
- from: _.from,
51
- to: _.to,
52
- promotion: L
195
+ const V = S.move({
196
+ from: f.from,
197
+ to: f.to,
198
+ promotion: d
53
199
  });
54
- S && (R({ from: S.from, to: S.to }), I({ captured: !!S.captured, check: S.san.includes("+") || S.san.includes("#") }), v((H) => [
55
- ...H,
56
- { san: S.san, fen: m.fen(), color: S.color }
57
- ]));
200
+ V && $(V);
58
201
  } catch {
59
202
  }
60
- b(null), h(), D();
61
- }, [_, h, D]), Z = N((L) => {
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(L), 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), b(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,236 +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);
194
- } catch (b) {
195
- return console.warn("Stockfish error:", b), null;
482
+ return await e.current.getBestMove(k, _);
483
+ } catch (g) {
484
+ throw g instanceof Ee && r("failed"), g;
196
485
  } finally {
197
- clearTimeout(_), c.current === f && r(!1);
486
+ clearTimeout(f), a.current === w && i(!1);
198
487
  }
199
488
  },
200
- [n]
201
- );
202
- return { isReady: n, isThinking: o, getBestMove: i };
203
- }
204
- const st = {
205
- p: 1,
206
- n: 3,
207
- b: 3,
208
- r: 5,
209
- q: 9,
210
- k: 0
211
- }, ie = {
212
- wk: "♚︎",
213
- wq: "♛︎",
214
- wr: "♜︎",
215
- wb: "♝︎",
216
- wn: "♞︎",
217
- wp: "♟︎",
218
- bk: "♔︎",
219
- bq: "♕︎",
220
- br: "♖︎",
221
- bb: "♗︎",
222
- bn: "♘︎",
223
- bp: "♙︎"
224
- }, fe = "abcdefgh";
225
- function X(t) {
226
- const e = t.split(" ");
227
- return {
228
- position: e[0],
229
- activeColor: e[1],
230
- castling: e[2],
231
- enPassant: e[3],
232
- halfmove: e[4],
233
- fullmove: e[5]
234
- };
235
- }
236
- function J(t) {
237
- const e = [], n = t.split("/");
238
- for (const s of n) {
239
- const o = [];
240
- for (const r of s) {
241
- const c = parseInt(r);
242
- if (isNaN(c)) {
243
- const i = r === r.toUpperCase() ? "w" : "b", l = r.toLowerCase();
244
- o.push({ type: l, color: i });
245
- } else
246
- for (let i = 0; i < c; i++) o.push(null);
247
- }
248
- e.push(o);
249
- }
250
- return e;
251
- }
252
- function Ne(t) {
253
- return t.map((e) => {
254
- let n = "", s = 0;
255
- for (const o of e)
256
- if (o === null)
257
- s++;
258
- else {
259
- s > 0 && (n += s, s = 0);
260
- const r = o.color === "w" ? o.type.toUpperCase() : o.type;
261
- n += r;
262
- }
263
- return s > 0 && (n += s), n;
264
- }).join("/");
265
- }
266
- function Re(t) {
267
- 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 };
268
494
  }
269
- function rt(t) {
270
- const { position: e } = X(t), n = J(e);
271
- let s = 0, o = 0;
272
- for (const r of n)
273
- for (const c of r)
274
- if (c) {
275
- const i = st[c.type];
276
- c.color === "w" ? s += i : o += i;
277
- }
278
- return { white: s, black: o };
279
- }
280
- function ot(t) {
281
- const { position: e } = X(t), n = J(e), s = [];
282
- for (let o = 0; o < 8; o++)
283
- for (let r = 0; r < 8; r++)
284
- n[o][r] === null && s.push(`${fe[r]}${8 - o}`);
285
- return s;
286
- }
287
- function it(t, e, n = !0) {
288
- const { position: s } = X(t), o = J(s), r = [];
289
- for (let c = 0; c < 8; c++)
290
- for (let i = 0; i < 8; i++) {
291
- const l = o[c][i];
292
- if (l && l.color === e) {
293
- if (n && l.type === "k") continue;
294
- r.push(`${fe[i]}${8 - c}`);
295
- }
296
- }
297
- 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";
298
498
  }
299
499
  function Ie(t) {
300
- const e = fe.indexOf(t[0]);
301
- return [8 - parseInt(t[1]), e];
302
- }
303
- function at(t, e, n, s) {
304
- const o = X(t), r = J(o.position), [c, i] = Ie(e);
305
- return r[c][i] = { type: n, color: s }, o.position = Ne(r), Re(o);
306
- }
307
- function ct(t, e) {
308
- const n = X(t), s = J(n.position), [o, r] = Ie(e);
309
- return s[o][r] = null, n.position = Ne(s), Re(n);
500
+ return t[Math.floor(Math.random() * t.length)];
310
501
  }
311
- const lt = ["p", "n", "b", "r", "q"], qe = 3;
312
- function ut(t, e) {
313
- 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;
314
509
  }
315
- function ae(t) {
316
- 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);
317
513
  }
318
- function dt(t) {
319
- const e = parseInt(t[1]);
320
- 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 };
321
521
  }
322
- function Fe(t) {
522
+ function he(t) {
523
+ let e;
323
524
  try {
324
- return new oe().load(t), !0;
525
+ e = new fe(t);
325
526
  } catch {
326
527
  return !1;
327
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());
328
546
  }
329
- function Me(t, e) {
330
- const n = ot(t);
547
+ function tt(t, e) {
548
+ const n = Ft(t);
331
549
  if (n.length === 0) return null;
332
- for (let s = 0; s < qe; s++) {
333
- const o = ae(n), r = dt(o), c = at(t, o, r, e);
334
- if (Fe(c))
335
- 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 };
336
557
  }
337
558
  return null;
338
559
  }
339
- function Be(t, e) {
340
- const n = it(t, e, !0);
560
+ function nt(t, e) {
561
+ const n = $t(t, e, !0);
341
562
  if (n.length === 0) return null;
342
- for (let s = 0; s < qe; s++) {
343
- const o = ae(n), r = ct(t, o);
344
- if (Fe(r))
345
- 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 };
346
567
  }
347
568
  return null;
348
569
  }
349
- function ht(t) {
350
- 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";
351
- if (o === "add") {
352
- const i = Me(t, r);
353
- 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)
354
575
  return {
355
- newFen: i.newFen,
576
+ newFen: o.newFen,
356
577
  action: {
357
578
  type: "add",
358
- target: s,
359
- square: i.square,
360
- piece: i.piece,
361
- color: r,
579
+ target: r,
580
+ square: o.square,
581
+ piece: o.piece,
582
+ color: i,
362
583
  whiteMaterial: e,
363
584
  blackMaterial: n
364
585
  }
365
586
  };
366
- const l = Be(t, c);
367
- if (l)
587
+ const c = nt(t, a);
588
+ if (c)
368
589
  return {
369
- newFen: l.newFen,
590
+ newFen: c.newFen,
370
591
  action: {
371
592
  type: "remove",
372
- target: s,
373
- square: l.square,
593
+ target: r,
594
+ square: c.square,
374
595
  whiteMaterial: e,
375
596
  blackMaterial: n
376
597
  }
377
598
  };
378
599
  } else {
379
- const i = Be(t, c);
380
- if (i)
600
+ const o = nt(t, a);
601
+ if (o)
381
602
  return {
382
- newFen: i.newFen,
603
+ newFen: o.newFen,
383
604
  action: {
384
605
  type: "remove",
385
- target: s,
386
- square: i.square,
606
+ target: r,
607
+ square: o.square,
387
608
  whiteMaterial: e,
388
609
  blackMaterial: n
389
610
  }
390
611
  };
391
- const l = Me(t, r);
392
- if (l)
612
+ const c = tt(t, i);
613
+ if (c)
393
614
  return {
394
- newFen: l.newFen,
615
+ newFen: c.newFen,
395
616
  action: {
396
617
  type: "add",
397
- target: s,
398
- square: l.square,
399
- piece: l.piece,
400
- color: r,
618
+ target: r,
619
+ square: c.square,
620
+ piece: c.piece,
621
+ color: i,
401
622
  whiteMaterial: e,
402
623
  blackMaterial: n
403
624
  }
@@ -405,7 +626,7 @@ function ht(t) {
405
626
  }
406
627
  return null;
407
628
  }
408
- const mt = [
629
+ const on = [
409
630
  [12, 20],
410
631
  // level 1
411
632
  [8, 15],
@@ -417,267 +638,289 @@ const mt = [
417
638
  [1, 4]
418
639
  // level 5
419
640
  ];
420
- function pt(t = 3) {
421
- const e = Math.max(0, Math.min(4, t - 1)), [n, s] = mt[e];
422
- 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";
423
648
  }
424
- function ft({
649
+ function un({
425
650
  fen: t,
426
651
  isPaused: e,
427
652
  stupidLevel: n,
428
- onChaosAction: s
653
+ onChaosAction: r,
654
+ resetKey: s = 0
429
655
  }) {
430
- const [o, r] = d(0), [c, i] = d(0), [l, w] = d(null), [f, _] = d(null), b = y(t), g = y(e), v = y(n), k = y(s), R = y(0), $ = y(null);
431
- b.current = t, g.current = e, v.current = n, k.current = s;
432
- const I = N(() => {
433
- const T = pt(v.current), h = Math.ceil(T / 1e3);
434
- i(h), r(h), R.current = Date.now() + T;
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;
435
661
  }, []);
436
- F(() => (I(), $.current = setInterval(() => {
437
- if (g.current) return;
438
- const T = Math.max(0, Math.ceil((R.current - Date.now()) / 1e3));
439
- if (r(T), T <= 0) {
440
- if (g.current) {
441
- 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;
442
687
  return;
443
688
  }
444
- const h = ht(b.current);
445
- h && (w(h.action), _(h.action.square), k.current(h.newFen), setTimeout(() => _(null), 600)), I();
446
- }
447
- }, 200), () => {
448
- $.current && clearInterval($.current);
449
- }), [I]);
450
- const x = y(null);
451
- return F(() => {
452
- if (e)
453
- x.current = Date.now();
454
- else if (x.current !== null) {
455
- const T = Date.now() - x.current;
456
- R.current += T, x.current = null;
457
- }
458
- }, [e]), { countdown: o, maxCountdown: c, lastAction: l, chaosSquare: f };
459
- }
460
- 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", St = "_pieceWhite_1tsnw_78", Mt = "_pieceBlack_1tsnw_83", O = {
461
- square: vt,
462
- light: _t,
463
- dark: gt,
464
- selected: kt,
465
- legalMove: yt,
466
- legalCapture: wt,
467
- check: Ct,
468
- lastMoveFrom: bt,
469
- lastMoveTo: Tt,
470
- chaosFlash: Lt,
471
- piece: Pt,
472
- pieceWhite: St,
473
- pieceBlack: Mt
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
474
716
  };
475
- function De({ type: t, color: e, className: n }) {
476
- const s = `${e}${t}`, o = ie[s];
477
- if (!o) return null;
478
- const r = e === "w" ? O.pieceWhite : O.pieceBlack;
479
- return /* @__PURE__ */ a("span", { className: `${n ?? ""} ${r}`, children: o });
480
- }
481
- const Bt = "_board_1jwdv_1", Ot = "_rankLabel_1jwdv_13", Nt = "_fileLabel_1jwdv_24", Rt = "_boardLocked_1jwdv_35", ce = {
482
- board: Bt,
483
- rankLabel: Ot,
484
- fileLabel: Nt,
485
- 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
486
728
  };
487
- function It({
729
+ function Pn({
488
730
  square: t,
489
731
  piece: e,
490
732
  isLight: n,
491
- isSelected: s,
492
- isLegalMove: o,
493
- isCheck: r,
494
- isLastMoveFrom: c,
495
- isLastMoveTo: i,
496
- isChaosFlash: l,
497
- rankLabel: w,
498
- 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,
499
741
  onClick: _
500
742
  }) {
501
- const b = [
502
- O.square,
503
- n ? O.light : O.dark,
504
- s && O.selected,
505
- o && (e ? O.legalCapture : O.legalMove),
506
- r && O.check,
507
- !s && !r && c && O.lastMoveFrom,
508
- !s && !r && i && O.lastMoveTo,
509
- 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
510
752
  ].filter(Boolean).join(" ");
511
- return /* @__PURE__ */ C("div", { className: b, onClick: () => _(t), children: [
512
- e && /* @__PURE__ */ a(
513
- De,
753
+ return /* @__PURE__ */ M("div", { className: w, onClick: () => _(t), children: [
754
+ e && /* @__PURE__ */ l(
755
+ pt,
514
756
  {
515
757
  type: e.type,
516
758
  color: e.color,
517
- className: O.piece
759
+ className: q.piece
518
760
  }
519
761
  ),
520
- w != null && /* @__PURE__ */ a("span", { className: ce.rankLabel, children: w }),
521
- 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 })
522
764
  ] });
523
765
  }
524
- const $e = "abcdefgh";
525
- function Oe(t, e) {
526
- return `${$e[e]}${8 - t}`;
766
+ const gt = "abcdefgh";
767
+ function st(t, e) {
768
+ return `${gt[e]}${8 - t}`;
527
769
  }
528
- function qt(t, e) {
770
+ function Bn(t, e) {
529
771
  return (t + e) % 2 === 0;
530
772
  }
531
- const Ft = Ze.memo(function({
773
+ const On = Et.memo(function({
532
774
  board: e,
533
775
  selectedSquare: n,
534
- legalMoves: s,
535
- inCheck: o,
536
- lastMove: r,
537
- chaosSquare: c,
538
- flipped: i,
539
- locked: l,
540
- onSquareClick: w
776
+ legalMoves: r,
777
+ inCheck: s,
778
+ lastMove: i,
779
+ chaosSquare: a,
780
+ flipped: o,
781
+ locked: c,
782
+ onSquareClick: p
541
783
  }) {
542
- let f = null;
543
- if (o)
544
- for (let g = 0; g < 8; g++)
545
- for (let v = 0; v < 8; v++) {
546
- const k = e[g][v];
547
- 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));
548
790
  }
549
- const _ = i ? [7, 6, 5, 4, 3, 2, 1, 0] : [0, 1, 2, 3, 4, 5, 6, 7], b = i ? [7, 6, 5, 4, 3, 2, 1, 0] : [0, 1, 2, 3, 4, 5, 6, 7];
550
- return /* @__PURE__ */ a("div", { className: `${ce.board}${l ? ` ${ce.boardLocked}` : ""}`, children: _.map(
551
- (g) => b.map((v) => {
552
- const k = Oe(g, v), R = e[g][v], $ = _.indexOf(g), I = b.indexOf(v);
553
- return /* @__PURE__ */ a(
554
- 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,
555
797
  {
556
- square: k,
557
- piece: R,
558
- isLight: qt(g, v),
559
- isSelected: k === n,
560
- isLegalMove: s.includes(k),
561
- isCheck: k === f,
562
- isLastMoveFrom: r?.from === k,
563
- isLastMoveTo: r?.to === k,
564
- isChaosFlash: c === k,
565
- rankLabel: I === 0 ? 8 - g : void 0,
566
- fileLabel: $ === 7 ? $e[v] : void 0,
567
- 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
568
810
  },
569
- k
811
+ b
570
812
  );
571
813
  })
572
814
  ) });
573
- }), 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 = {
574
- promotionOverlay: Dt,
575
- promotionDialog: $t,
576
- promotionTitle: xt,
577
- promotionOptions: Gt,
578
- promotionBtn: At,
579
- gameOverOverlay: Et,
580
- gameOverBanner: Vt,
581
- gameOverResult: jt,
582
- gameOverDetail: Wt,
583
- restartBtn: Ht,
584
- chaosBar: Ut,
585
- chaosBarLabel: Yt,
586
- chaosBarTrack: zt,
587
- chaosBarFill: Qt,
588
- difficultySelector: Kt,
589
- difficultyLabel: Xt,
590
- difficultySlider: Jt,
591
- difficultyValue: Zt,
592
- sidePickerOverlay: en,
593
- sidePickerCard: tn,
594
- sidePickerTitle: nn,
595
- sidePickerOptions: sn,
596
- sidePickerBtn: rn,
597
- sidePickerIcon: on,
598
- sidePickerWhite: an,
599
- sidePickerBlack: cn,
600
- sidePickerLabel: ln,
601
- sidePickerSettings: un,
602
- stupidLevel: dn,
603
- stupidLevelHeader: hn,
604
- stupidLevelLabel: mn,
605
- stupidLevelValue: pn,
606
- stupidLevelSlider: fn,
607
- muteBtn: vn,
608
- muteBtnMuted: _n,
609
- chaosToast: gn,
610
- chaosToastFading: kn
611
- }, 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 = [
612
854
  { type: "q", label: "Queen" },
613
855
  { type: "r", label: "Rook" },
614
856
  { type: "b", label: "Bishop" },
615
857
  { type: "n", label: "Knight" }
616
858
  ];
617
- function wn({ color: t, onSelect: e }) {
618
- return /* @__PURE__ */ a("div", { className: u.promotionOverlay, children: /* @__PURE__ */ C("div", { className: u.promotionDialog, children: [
619
- /* @__PURE__ */ a("h3", { className: u.promotionTitle, children: "Promote pawn" }),
620
- /* @__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(
621
863
  "button",
622
864
  {
865
+ type: "button",
623
866
  className: u.promotionBtn,
624
867
  onClick: () => e(n),
625
- title: s,
626
- children: /* @__PURE__ */ a(De, { type: n, color: t })
868
+ title: r,
869
+ children: /* @__PURE__ */ l(pt, { type: n, color: t })
627
870
  },
628
871
  n
629
872
  )) })
630
873
  ] }) });
631
874
  }
632
- function Cn(t, e) {
633
- 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" };
634
877
  }
635
- function bn({ status: t, humanColor: e, onRestart: n }) {
636
- const { title: s, detail: o } = Cn(t, e);
637
- return /* @__PURE__ */ a("div", { className: u.gameOverOverlay, children: /* @__PURE__ */ C("div", { className: u.gameOverBanner, children: [
638
- /* @__PURE__ */ a("h2", { className: u.gameOverResult, children: s }),
639
- /* @__PURE__ */ a("p", { className: u.gameOverDetail, children: o }),
640
- /* @__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" })
641
884
  ] }) });
642
885
  }
643
- function Tn({ countdown: t, maxCountdown: e }) {
644
- const n = e > 0 ? (e - t) / e * 100 : 0, s = 1 - (t / e || 0);
645
- return /* @__PURE__ */ C("div", { className: u.chaosBar, children: [
646
- /* @__PURE__ */ a("span", { className: u.chaosBarLabel, children: "STUPIDITY" }),
647
- /* @__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(
648
891
  "div",
649
892
  {
650
893
  className: u.chaosBarFill,
651
894
  style: {
652
895
  width: `${n}%`,
653
- "--glow": s
896
+ "--glow": r
654
897
  }
655
898
  }
656
899
  ) })
657
900
  ] });
658
901
  }
659
- function Ln({ action: t }) {
660
- const [e, n] = d(!1), [s, o] = d(!1), [r, c] = d(null), i = y(void 0);
661
- 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(() => {
662
905
  if (t)
663
- return i.current && clearTimeout(i.current), c(t), o(!1), n(!0), i.current = setTimeout(() => {
664
- o(!0), i.current = setTimeout(() => {
665
- 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);
666
909
  }, 400);
667
910
  }, 1600), () => {
668
- i.current && clearTimeout(i.current);
911
+ o.current && clearTimeout(o.current);
669
912
  };
670
- }, [t]), !e || !r) return null;
671
- 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!`;
672
- 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 });
673
916
  }
674
- function xe({ depth: t, onChange: e }) {
675
- return /* @__PURE__ */ C("div", { className: u.difficultySelector, children: [
676
- /* @__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: [
677
920
  "AI Depth: ",
678
- /* @__PURE__ */ a("span", { className: u.difficultyValue, children: t })
921
+ /* @__PURE__ */ l("span", { className: u.difficultyValue, children: t })
679
922
  ] }),
680
- /* @__PURE__ */ a(
923
+ /* @__PURE__ */ l(
681
924
  "input",
682
925
  {
683
926
  className: u.difficultySlider,
@@ -690,14 +933,14 @@ function xe({ depth: t, onChange: e }) {
690
933
  )
691
934
  ] });
692
935
  }
693
- const Pn = ["OFF", "CHILL", "MID", "STUPID", "CHAOS", "LOL"];
694
- function Ge({ level: t, onChange: e }) {
695
- return /* @__PURE__ */ C("div", { className: u.stupidLevel, children: [
696
- /* @__PURE__ */ C("div", { className: u.stupidLevelHeader, children: [
697
- /* @__PURE__ */ a("span", { className: u.stupidLevelLabel, children: "STUPID" }),
698
- /* @__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] })
699
942
  ] }),
700
- /* @__PURE__ */ a(
943
+ /* @__PURE__ */ l(
701
944
  "input",
702
945
  {
703
946
  type: "range",
@@ -711,43 +954,46 @@ function Ge({ level: t, onChange: e }) {
711
954
  )
712
955
  ] });
713
956
  }
714
- function Sn({ depth: t, onDepthChange: e, stupidLevel: n, onStupidLevelChange: s, onSelectSide: o }) {
715
- return /* @__PURE__ */ a("div", { className: u.sidePickerOverlay, children: /* @__PURE__ */ C("div", { className: u.sidePickerCard, children: [
716
- /* @__PURE__ */ a("h2", { className: u.sidePickerTitle, children: "Choose Your Side" }),
717
- /* @__PURE__ */ C("div", { className: u.sidePickerOptions, children: [
718
- /* @__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(
719
962
  "button",
720
963
  {
964
+ type: "button",
721
965
  className: u.sidePickerBtn,
722
- onClick: () => o("w"),
966
+ onClick: () => s("w"),
723
967
  children: [
724
- /* @__PURE__ */ a("span", { className: `${u.sidePickerIcon} ${u.sidePickerWhite}`, children: ie.wk }),
725
- /* @__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" })
726
970
  ]
727
971
  }
728
972
  ),
729
- /* @__PURE__ */ C(
973
+ /* @__PURE__ */ M(
730
974
  "button",
731
975
  {
976
+ type: "button",
732
977
  className: u.sidePickerBtn,
733
- onClick: () => o("b"),
978
+ onClick: () => s("b"),
734
979
  children: [
735
- /* @__PURE__ */ a("span", { className: `${u.sidePickerIcon} ${u.sidePickerBlack}`, children: ie.bk }),
736
- /* @__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" })
737
982
  ]
738
983
  }
739
984
  )
740
985
  ] }),
741
- /* @__PURE__ */ C("div", { className: u.sidePickerSettings, children: [
742
- /* @__PURE__ */ a(xe, { depth: t, onChange: e }),
743
- /* @__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 })
744
989
  ] })
745
990
  ] }) });
746
991
  }
747
- function Mn({ muted: t, onToggle: e }) {
748
- return /* @__PURE__ */ a(
992
+ function br({ muted: t, onToggle: e }) {
993
+ return /* @__PURE__ */ l(
749
994
  "button",
750
995
  {
996
+ type: "button",
751
997
  className: `${u.muteBtn} ${t ? u.muteBtnMuted : ""}`,
752
998
  onClick: e,
753
999
  title: t ? "Unmute" : "Mute",
@@ -755,228 +1001,315 @@ function Mn({ muted: t, onToggle: e }) {
755
1001
  }
756
1002
  );
757
1003
  }
758
- class Bn {
759
- ctx = null;
760
- muted = !1;
1004
+ let oe = null;
1005
+ class Sr {
1006
+ muted;
1007
+ constructor(e = !1) {
1008
+ this.muted = e;
1009
+ }
761
1010
  getCtx() {
762
1011
  if (this.muted) return null;
763
- if (!this.ctx)
1012
+ if (!oe)
764
1013
  try {
765
- this.ctx = new AudioContext();
1014
+ oe = new AudioContext();
766
1015
  } catch {
767
1016
  return null;
768
1017
  }
769
- return this.ctx.state === "suspended" && this.ctx.resume(), this.ctx;
1018
+ return oe.state === "suspended" && oe.resume(), oe;
770
1019
  }
771
1020
  setMuted(e) {
772
1021
  this.muted = e;
773
1022
  }
1023
+ get isMuted() {
1024
+ return this.muted;
1025
+ }
774
1026
  playMove() {
775
1027
  const e = this.getCtx();
776
1028
  if (!e) return;
777
- const n = e.createOscillator(), s = e.createGain();
778
- 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);
779
1031
  }
780
1032
  playCapture() {
781
1033
  const e = this.getCtx();
782
1034
  if (!e) return;
783
- const n = e.sampleRate * 0.1, s = e.createBuffer(1, n, e.sampleRate), o = s.getChannelData(0);
784
- for (let l = 0; l < n; l++)
785
- o[l] = (Math.random() * 2 - 1) * Math.exp(-l / (e.sampleRate * 0.015));
786
- const r = e.createBufferSource();
787
- r.buffer = s;
788
- const c = e.createBiquadFilter();
789
- c.type = "bandpass", c.frequency.value = 3e3, c.Q.value = 2;
790
- const i = e.createGain();
791
- 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);
792
1044
  }
793
1045
  playCheck() {
794
1046
  const e = this.getCtx();
795
1047
  if (!e) return;
796
- const n = e.createOscillator(), s = e.createGain();
797
- 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);
798
1050
  }
799
1051
  playChaos() {
800
1052
  const e = this.getCtx();
801
1053
  if (!e) return;
802
- const n = e.createOscillator(), s = e.createGain();
803
- 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);
804
1056
  }
805
1057
  playGameOver() {
806
1058
  const e = this.getCtx();
807
1059
  if (!e) return;
808
1060
  const n = [261.63, 329.63, 392];
809
- for (const s of n) {
810
- const o = e.createOscillator(), r = e.createGain();
811
- 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);
812
1064
  }
813
1065
  }
814
1066
  }
815
- 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 = {
816
- container: On,
817
- topBar: Nn,
818
- topBarLeft: Rn,
819
- statusText: In,
820
- thinking: qn,
821
- bottomBar: Fn
822
- };
823
- 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) {
824
1108
  const {
825
1109
  defaultDepth: e = 10,
826
1110
  defaultStupidLevel: n = 3,
827
- defaultHumanColor: s,
828
- defaultMuted: o = !1,
829
- depth: r,
830
- onDepthChange: c,
831
- stupidLevel: i,
832
- onStupidLevelChange: l,
833
- stockfishWorkerPath: w,
834
- 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,
835
1119
  showControls: _ = !0,
836
- showMuteButton: b = !0,
837
- onGameOver: g,
838
- onMove: v,
839
- onChaosAction: k,
840
- onRestart: R,
841
- className: $
842
- } = t, [I, x] = d(e), T = r ?? I, h = c ?? x, [D, le] = d(n), W = i ?? D, Z = l ?? le, [ue, L] = d(s ?? "w"), m = ue, [S, H] = d(o), [q, M] = d(
843
- f || s ? "playing" : "setup"
844
- ), {
845
- fen: P,
846
- turn: Q,
847
- selectedSquare: Ae,
848
- legalMoves: Ee,
849
- gameStatus: B,
850
- promotionPending: ve,
851
- lastMove: Ve,
852
- lastMoveDetail: ee,
853
- moveHistory: G,
854
- board: je,
855
- handleSquareClick: _e,
856
- handlePromotion: We,
857
- applyFen: te,
858
- handleRestart: ge
859
- } = 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({
860
- fen: P,
861
- isPaused: He,
862
- stupidLevel: Math.max(1, W),
863
- onChaosAction: N((p) => {
864
- const j = new oe(he.current);
865
- j.turn() === we.current && (j.isGameOver() || te(p));
866
- }, [te])
867
- }), ye = y(V);
868
- F(() => {
869
- V && V !== ye.current && k?.(V, P), ye.current = V;
870
- }, [V, P, k]);
871
- const he = y(P);
872
- he.current = P;
873
- const we = y(m);
874
- we.current = m;
875
- const U = y(null), re = N((p) => {
876
- const j = p.slice(0, 2), Je = p.slice(2, 4), Le = p.length > 4 ? p[4] : void 0;
877
- try {
878
- const Pe = new oe(he.current), Se = { from: j, to: Je };
879
- Le && (Se.promotion = Le), Pe.move(Se) ? te(Pe.fen()) : console.warn("[ChaosChess] Stockfish move invalid for current position, will retry");
880
- } catch {
881
- console.warn("[ChaosChess] Stockfish move threw, will retry");
882
- }
883
- }, [te]), ze = N((p) => {
884
- L(p), M("playing");
885
- }, []), Qe = N(() => {
886
- ge(), M(f || s ? "playing" : "setup"), R?.();
887
- }, [ge, f, s, R]);
888
- F(() => {
889
- Y.setMuted(S);
890
- }, [S]);
891
- const Ce = y(G.length);
892
- F(() => {
893
- if (G.length > Ce.current) {
894
- ee && (ee.check ? Y.playCheck() : ee.captured ? Y.playCapture() : Y.playMove());
895
- const p = G[G.length - 1];
896
- 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;
897
1214
  }
898
- Ce.current = G.length;
899
- }, [G.length, ee, G, v]), F(() => {
900
- de && Y.playChaos();
901
- }, [de]);
902
- const be = y(!1);
903
- F(() => {
904
- B.isGameOver && !be.current && (Y.playGameOver(), g?.(B)), be.current = B.isGameOver;
905
- }, [B, g]);
906
- const me = y(!1);
907
- F(() => {
908
- if (q !== "playing") {
909
- 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");
910
1218
  return;
911
1219
  }
912
- E || B.isGameOver || !K || A || U.current !== P && (m === "b" && !me.current && (me.current = !0), ne(P, T).then((p) => {
913
- if (!p) {
914
- console.warn("[ChaosChess] Stockfish returned no move for position, skipping retries"), U.current = P;
915
- return;
916
- }
917
- U.current = null, re(p);
918
- }));
919
- }, [q, P, E, B.isGameOver, K, A, m, ne, T, re]), F(() => {
920
- if (q !== "playing" || E || A || B.isGameOver || !K || U.current === P) return;
921
- const p = setTimeout(() => {
922
- ne(P, T).then((j) => {
923
- if (!j) {
924
- U.current = P;
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");
925
1225
  return;
926
1226
  }
927
- U.current = null, re(j);
928
- });
929
- }, 3e3);
930
- return () => clearTimeout(p);
931
- }, [q, E, A, B.isGameOver, K, P, T, 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
- Sn,
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: T,
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
- b && /* @__PURE__ */ a(Mn, { muted: S, 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: T, 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