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