@maxr0ssi/chaos-chess 0.2.0 → 0.2.1

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