@maxr0ssi/chaos-chess 0.2.0 → 0.2.2

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