@vue-skuilder/courseware 0.1.34 → 0.1.35
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.
- package/dist/CourseWare-BTFRjgBR.js +305 -0
- package/dist/CourseWare-BTFRjgBR.js.map +1 -0
- package/dist/CourseWare-DSeyTAtH.cjs +2 -0
- package/dist/CourseWare-DSeyTAtH.cjs.map +1 -0
- package/dist/assets/CourseWare.css +1 -0
- package/dist/assets/chess.css +1 -0
- package/dist/assets/index.css +1 -1
- package/dist/assets/math.css +1 -0
- package/dist/assets/piano.css +1 -0
- package/dist/assets/sightsing.css +1 -0
- package/dist/assets/typing.css +1 -0
- package/dist/backend.cjs.js +1 -1
- package/dist/backend.cjs.js.map +1 -1
- package/dist/backend.mjs +4 -3
- package/dist/backend.mjs.map +1 -1
- package/dist/chess/components/ChessBoard.vue.d.ts.map +1 -1
- package/dist/chess/composables/useChessgroundBounds.d.ts +24 -0
- package/dist/chess/composables/useChessgroundBounds.d.ts.map +1 -0
- package/dist/chess/questions/puzzle/puzzle.vue.d.ts.map +1 -1
- package/dist/chess-BbHATAzk.js +2949 -0
- package/dist/chess-BbHATAzk.js.map +1 -0
- package/dist/chess-BsgVZARV.cjs +7 -0
- package/dist/chess-BsgVZARV.cjs.map +1 -0
- package/dist/chess-C_2RQEuq.cjs +1 -0
- package/dist/chess-X1bmWmh3.js +3 -0
- package/dist/french-Bxet7hJm.cjs +2 -0
- package/dist/french-Bxet7hJm.cjs.map +1 -0
- package/dist/french-Dk7YG8Td.js +140 -0
- package/dist/french-Dk7YG8Td.js.map +1 -0
- package/dist/french-evUMlbbq.js +3 -0
- package/dist/french-x9P8RRn8.cjs +1 -0
- package/dist/index.cjs.js +2 -170
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +172 -62021
- package/dist/index.mjs.map +1 -1
- package/dist/math-B1oDAkOy.cjs +34 -0
- package/dist/math-B1oDAkOy.cjs.map +1 -0
- package/dist/math-B4HbgYf6.js +13391 -0
- package/dist/math-B4HbgYf6.js.map +1 -0
- package/dist/math-BWlIa6-l.cjs +1 -0
- package/dist/math-DYni7rRl.js +3 -0
- package/dist/piano-BN5Btq91.js +3 -0
- package/dist/piano-Btvkzjfz.cjs +1 -0
- package/dist/piano-CefQUc72.cjs +2 -0
- package/dist/piano-CefQUc72.cjs.map +1 -0
- package/dist/piano-DF1g6yaX.js +3603 -0
- package/dist/piano-DF1g6yaX.js.map +1 -0
- package/dist/pitch-C-lh9ezH.cjs +2 -0
- package/dist/pitch-C-lh9ezH.cjs.map +1 -0
- package/dist/pitch-CgGJFkZ1.js +106 -0
- package/dist/pitch-CgGJFkZ1.js.map +1 -0
- package/dist/pitch-Dn0iNqiS.js +3 -0
- package/dist/pitch-DsopN5IR.cjs +1 -0
- package/dist/{shapes-nszfsx3o.js → shapes-BQUVJdp5.js} +3 -21
- package/dist/shapes-BQUVJdp5.js.map +1 -0
- package/dist/shapes-C_-mvrCc.cjs +2 -0
- package/dist/shapes-C_-mvrCc.cjs.map +1 -0
- package/dist/shapes-DRq8J94A.cjs +2 -0
- package/dist/shapes-DRq8J94A.cjs.map +1 -0
- package/dist/shapes-ICeg46lr.js +25 -0
- package/dist/shapes-ICeg46lr.js.map +1 -0
- package/dist/sightsing-BFQ7HRig.js +41061 -0
- package/dist/sightsing-BFQ7HRig.js.map +1 -0
- package/dist/sightsing-CJX3k0Fd.js +3 -0
- package/dist/sightsing-Cr_SJ5Vc.cjs +133 -0
- package/dist/sightsing-Cr_SJ5Vc.cjs.map +1 -0
- package/dist/sightsing-CtagQ0FJ.cjs +1 -0
- package/dist/typing-BevtfWlp.js +184 -0
- package/dist/typing-BevtfWlp.js.map +1 -0
- package/dist/typing-CBPjtwrg.cjs +1 -0
- package/dist/typing-CK-glKhm.cjs +2 -0
- package/dist/typing-CK-glKhm.cjs.map +1 -0
- package/dist/typing-k-ojjO7G.js +3 -0
- package/dist/word-work-BOnRlZgd.js +108 -0
- package/dist/word-work-BOnRlZgd.js.map +1 -0
- package/dist/word-work-C5MTSapy.cjs +1 -0
- package/dist/word-work-Dd6tIKrt.js +3 -0
- package/dist/word-work-fNbCLNuN.cjs +2 -0
- package/dist/word-work-fNbCLNuN.cjs.map +1 -0
- package/package.json +6 -5
- package/dist/shapes-DJ-ujuDr.cjs +0 -2
- package/dist/shapes-DJ-ujuDr.cjs.map +0 -1
- package/dist/shapes-nszfsx3o.js.map +0 -1
|
@@ -0,0 +1,2949 @@
|
|
|
1
|
+
import { r as e } from "./shapes-BQUVJdp5.js";
|
|
2
|
+
import { r as t, t as n } from "./CourseWare-BTFRjgBR.js";
|
|
3
|
+
import { Fragment as r, computed as i, createCommentVNode as a, createElementBlock as o, createElementVNode as s, defineComponent as c, onMounted as l, onUnmounted as u, openBlock as d, ref as f, renderList as p, toDisplayString as m, watch as h } from "vue";
|
|
4
|
+
import { Question as g, useQuestionView as _, useViewable as v } from "@vue-skuilder/common-ui";
|
|
5
|
+
import { DataShapeName as y, FieldType as b, Status as x } from "@vue-skuilder/common";
|
|
6
|
+
//#region src/chess/chessground/types.ts
|
|
7
|
+
var S = ["cg-white", "cg-black"], C = [
|
|
8
|
+
"a",
|
|
9
|
+
"b",
|
|
10
|
+
"c",
|
|
11
|
+
"d",
|
|
12
|
+
"e",
|
|
13
|
+
"f",
|
|
14
|
+
"g",
|
|
15
|
+
"h"
|
|
16
|
+
], w = [
|
|
17
|
+
"1",
|
|
18
|
+
"2",
|
|
19
|
+
"3",
|
|
20
|
+
"4",
|
|
21
|
+
"5",
|
|
22
|
+
"6",
|
|
23
|
+
"7",
|
|
24
|
+
"8"
|
|
25
|
+
], T = [...w].reverse(), E = Array.prototype.concat(...C.map((e) => w.map((t) => e + t))), pos2key = (e) => E[8 * e[0] + e[1]], key2pos = (e) => [e.charCodeAt(0) - 97, e.charCodeAt(1) - 49], D = E.map(key2pos);
|
|
26
|
+
function memo(e) {
|
|
27
|
+
let t, ret = () => (t === void 0 && (t = e()), t);
|
|
28
|
+
return ret.clear = () => {
|
|
29
|
+
t = void 0;
|
|
30
|
+
}, ret;
|
|
31
|
+
}
|
|
32
|
+
var timer = () => {
|
|
33
|
+
let e;
|
|
34
|
+
return {
|
|
35
|
+
start() {
|
|
36
|
+
e = performance.now();
|
|
37
|
+
},
|
|
38
|
+
cancel() {
|
|
39
|
+
e = void 0;
|
|
40
|
+
},
|
|
41
|
+
stop() {
|
|
42
|
+
if (!e) return 0;
|
|
43
|
+
let t = performance.now() - e;
|
|
44
|
+
return e = void 0, t;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}, opposite = (e) => e === "cg-white" ? "cg-black" : "cg-white", distanceSq = (e, t) => {
|
|
48
|
+
let n = e[0] - t[0], r = e[1] - t[1];
|
|
49
|
+
return n * n + r * r;
|
|
50
|
+
}, samePiece = (e, t) => e.role === t.role && e.color === t.color, posToTranslate = (e) => (t, n) => [(n ? t[0] : 7 - t[0]) * e.width / 8, (n ? 7 - t[1] : t[1]) * e.height / 8], translate = (e, t) => {
|
|
51
|
+
e.style.transform = `translate(${t[0]}px,${t[1]}px)`;
|
|
52
|
+
}, translateAndScale = (e, t, n = 1) => {
|
|
53
|
+
e.style.transform = `translate(${t[0]}px,${t[1]}px) scale(${n})`;
|
|
54
|
+
}, setVisible = (e, t) => {
|
|
55
|
+
e.style.visibility = t ? "visible" : "hidden";
|
|
56
|
+
}, eventPosition = (e) => {
|
|
57
|
+
if (e.clientX || e.clientX === 0) return [e.clientX, e.clientY];
|
|
58
|
+
if (e.targetTouches?.[0]) return [e.targetTouches[0].clientX, e.targetTouches[0].clientY];
|
|
59
|
+
}, isRightButton = (e) => e.button === 2, createEl = (e, t) => {
|
|
60
|
+
let n = document.createElement(e);
|
|
61
|
+
return t && (n.className = t), n;
|
|
62
|
+
};
|
|
63
|
+
function computeSquareCenter(e, t, n) {
|
|
64
|
+
let r = key2pos(e);
|
|
65
|
+
return t || (r[0] = 7 - r[0], r[1] = 7 - r[1]), [n.left + n.width * r[0] / 8 + n.width / 16, n.top + n.height * (7 - r[1]) / 8 + n.height / 16];
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/chess/chessground/premove.ts
|
|
69
|
+
var diff = (e, t) => Math.abs(e - t), pawn = (e) => (t, n, r, i) => diff(t, r) < 2 && (e === "cg-white" ? i === n + 1 || n <= 1 && i === n + 2 && t === r : i === n - 1 || n >= 6 && i === n - 2 && t === r), knight = (e, t, n, r) => {
|
|
70
|
+
let i = diff(e, n), a = diff(t, r);
|
|
71
|
+
return i === 1 && a === 2 || i === 2 && a === 1;
|
|
72
|
+
}, bishop = (e, t, n, r) => diff(e, n) === diff(t, r), rook = (e, t, n, r) => e === n || t === r, queen = (e, t, n, r) => bishop(e, t, n, r) || rook(e, t, n, r), king = (e, t, n) => (r, i, a, o) => diff(r, a) < 2 && diff(i, o) < 2 || n && i === o && i === (e === "cg-white" ? 0 : 7) && (r === 4 && (a === 2 && t.includes(0) || a === 6 && t.includes(7)) || t.includes(a));
|
|
73
|
+
function rookFilesOf(e, t) {
|
|
74
|
+
let n = t === "cg-white" ? "1" : "8", r = [];
|
|
75
|
+
for (let [i, a] of e) i[1] === n && a.color === t && a.role === "rook" && r.push(key2pos(i)[0]);
|
|
76
|
+
return r;
|
|
77
|
+
}
|
|
78
|
+
function premove(e, t, n) {
|
|
79
|
+
let r = e.get(t);
|
|
80
|
+
if (!r) return [];
|
|
81
|
+
let i = key2pos(t), a = r.role, o = a === "pawn" ? pawn(r.color) : a === "knight" ? knight : a === "bishop" ? bishop : a === "rook" ? rook : a === "queen" ? queen : king(r.color, rookFilesOf(e, r.color), n);
|
|
82
|
+
return D.filter((e) => (i[0] !== e[0] || i[1] !== e[1]) && o(i[0], i[1], e[0], e[1])).map(pos2key);
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/chess/chessground/board.ts
|
|
86
|
+
function callUserFunction(e, ...t) {
|
|
87
|
+
e && setTimeout(() => e(...t), 1);
|
|
88
|
+
}
|
|
89
|
+
function toggleOrientation(e) {
|
|
90
|
+
e.orientation = opposite(e.orientation), e.animation.current = e.draggable.current = e.selected = void 0;
|
|
91
|
+
}
|
|
92
|
+
function setPieces(e, t) {
|
|
93
|
+
for (let [n, r] of t) r ? e.pieces.set(n, r) : e.pieces.delete(n);
|
|
94
|
+
}
|
|
95
|
+
function setCheck(e, t) {
|
|
96
|
+
if (e.check = void 0, t === !0 && (t = e.turnColor), t) for (let [n, r] of e.pieces) r.role === "king" && r.color === t && (e.check = n);
|
|
97
|
+
}
|
|
98
|
+
function setPremove(e, t, n, r) {
|
|
99
|
+
unsetPredrop(e), e.premovable.current = [t, n], callUserFunction(e.premovable.events.set, t, n, r);
|
|
100
|
+
}
|
|
101
|
+
function unsetPremove(e) {
|
|
102
|
+
e.premovable.current && (e.premovable.current = void 0, callUserFunction(e.premovable.events.unset));
|
|
103
|
+
}
|
|
104
|
+
function setPredrop(e, t, n) {
|
|
105
|
+
unsetPremove(e), e.predroppable.current = {
|
|
106
|
+
role: t,
|
|
107
|
+
key: n
|
|
108
|
+
}, callUserFunction(e.predroppable.events.set, t, n);
|
|
109
|
+
}
|
|
110
|
+
function unsetPredrop(e) {
|
|
111
|
+
let t = e.predroppable;
|
|
112
|
+
t.current && (t.current = void 0, callUserFunction(t.events.unset));
|
|
113
|
+
}
|
|
114
|
+
function tryAutoCastle(e, t, n) {
|
|
115
|
+
if (!e.autoCastle) return !1;
|
|
116
|
+
let r = e.pieces.get(t);
|
|
117
|
+
if (!r || r.role !== "king") return !1;
|
|
118
|
+
let i = key2pos(t), a = key2pos(n);
|
|
119
|
+
if (i[1] !== 0 && i[1] !== 7 || i[1] !== a[1]) return !1;
|
|
120
|
+
i[0] === 4 && !e.pieces.has(n) && (a[0] === 6 ? n = pos2key([7, a[1]]) : a[0] === 2 && (n = pos2key([0, a[1]])));
|
|
121
|
+
let o = e.pieces.get(n);
|
|
122
|
+
return !o || o.color !== r.color || o.role !== "rook" ? !1 : (e.pieces.delete(t), e.pieces.delete(n), i[0] < a[0] ? (e.pieces.set(pos2key([6, a[1]]), r), e.pieces.set(pos2key([5, a[1]]), o)) : (e.pieces.set(pos2key([2, a[1]]), r), e.pieces.set(pos2key([3, a[1]]), o)), !0);
|
|
123
|
+
}
|
|
124
|
+
function baseMove(e, t, n) {
|
|
125
|
+
let r = e.pieces.get(t), i = e.pieces.get(n);
|
|
126
|
+
if (t === n || !r) return !1;
|
|
127
|
+
let a = i && i.color !== r.color ? i : void 0;
|
|
128
|
+
return n === e.selected && unselect(e), callUserFunction(e.events.move, t, n, a), tryAutoCastle(e, t, n) || (e.pieces.set(n, r), e.pieces.delete(t)), e.lastMove = [t, n], e.check = void 0, callUserFunction(e.events.change), a || !0;
|
|
129
|
+
}
|
|
130
|
+
function baseNewPiece(e, t, n, r) {
|
|
131
|
+
if (e.pieces.has(n)) if (r) e.pieces.delete(n);
|
|
132
|
+
else return !1;
|
|
133
|
+
return callUserFunction(e.events.dropNewPiece, t, n), e.pieces.set(n, t), e.lastMove = [n], e.check = void 0, callUserFunction(e.events.change), e.movable.dests = void 0, e.turnColor = opposite(e.turnColor), !0;
|
|
134
|
+
}
|
|
135
|
+
function baseUserMove(e, t, n) {
|
|
136
|
+
let r = baseMove(e, t, n);
|
|
137
|
+
return r && (e.movable.dests = void 0, e.turnColor = opposite(e.turnColor), e.animation.current = void 0), r;
|
|
138
|
+
}
|
|
139
|
+
function userMove(e, t, n) {
|
|
140
|
+
if (canMove(e, t, n)) {
|
|
141
|
+
let r = baseUserMove(e, t, n);
|
|
142
|
+
if (r) {
|
|
143
|
+
let i = e.hold.stop();
|
|
144
|
+
unselect(e);
|
|
145
|
+
let a = {
|
|
146
|
+
premove: !1,
|
|
147
|
+
ctrlKey: e.stats.ctrlKey,
|
|
148
|
+
holdTime: i
|
|
149
|
+
};
|
|
150
|
+
return r !== !0 && (a.captured = r), callUserFunction(e.movable.events.after, t, n, a), !0;
|
|
151
|
+
}
|
|
152
|
+
} else if (canPremove(e, t, n)) return setPremove(e, t, n, { ctrlKey: e.stats.ctrlKey }), unselect(e), !0;
|
|
153
|
+
return unselect(e), !1;
|
|
154
|
+
}
|
|
155
|
+
function dropNewPiece(e, t, n, r) {
|
|
156
|
+
let i = e.pieces.get(t);
|
|
157
|
+
i && (canDrop(e, t, n) || r) ? (e.pieces.delete(t), baseNewPiece(e, i, n, r), callUserFunction(e.movable.events.afterNewPiece, i.role, n, {
|
|
158
|
+
premove: !1,
|
|
159
|
+
predrop: !1
|
|
160
|
+
})) : i && canPredrop(e, t, n) ? setPredrop(e, i.role, n) : (unsetPremove(e), unsetPredrop(e)), e.pieces.delete(t), unselect(e);
|
|
161
|
+
}
|
|
162
|
+
function selectSquare(e, t, n) {
|
|
163
|
+
if (callUserFunction(e.events.select, t), e.selected) {
|
|
164
|
+
if (e.selected === t && !e.draggable.enabled) {
|
|
165
|
+
unselect(e), e.hold.cancel();
|
|
166
|
+
return;
|
|
167
|
+
} else if ((e.selectable.enabled || n) && e.selected !== t && userMove(e, e.selected, t)) {
|
|
168
|
+
e.stats.dragged = !1;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
(e.selectable.enabled || e.draggable.enabled) && (isMovable(e, t) || isPremovable(e, t)) && (setSelected(e, t), e.hold.start());
|
|
173
|
+
}
|
|
174
|
+
function setSelected(e, t) {
|
|
175
|
+
e.selected = t, isPremovable(e, t) ? e.premovable.customDests || (e.premovable.dests = premove(e.pieces, t, e.premovable.castle)) : e.premovable.dests = void 0;
|
|
176
|
+
}
|
|
177
|
+
function unselect(e) {
|
|
178
|
+
e.selected = void 0, e.premovable.dests = void 0, e.hold.cancel();
|
|
179
|
+
}
|
|
180
|
+
function isMovable(e, t) {
|
|
181
|
+
let n = e.pieces.get(t);
|
|
182
|
+
return !!n && (e.movable.color === "both" || e.movable.color === n.color && e.turnColor === n.color);
|
|
183
|
+
}
|
|
184
|
+
var canMove = (e, t, n) => t !== n && isMovable(e, t) && (e.movable.free || !!e.movable.dests?.get(t)?.includes(n));
|
|
185
|
+
function canDrop(e, t, n) {
|
|
186
|
+
let r = e.pieces.get(t);
|
|
187
|
+
return !!r && (t === n || !e.pieces.has(n)) && (e.movable.color === "both" || e.movable.color === r.color && e.turnColor === r.color);
|
|
188
|
+
}
|
|
189
|
+
function isPremovable(e, t) {
|
|
190
|
+
let n = e.pieces.get(t);
|
|
191
|
+
return !!n && e.premovable.enabled && e.movable.color === n.color && e.turnColor !== n.color;
|
|
192
|
+
}
|
|
193
|
+
function canPremove(e, t, n) {
|
|
194
|
+
let r = e.premovable.customDests?.get(t) ?? premove(e.pieces, t, e.premovable.castle);
|
|
195
|
+
return t !== n && isPremovable(e, t) && r.includes(n);
|
|
196
|
+
}
|
|
197
|
+
function canPredrop(e, t, n) {
|
|
198
|
+
let r = e.pieces.get(t), i = e.pieces.get(n);
|
|
199
|
+
return !!r && (!i || i.color !== e.movable.color) && e.predroppable.enabled && (r.role !== "pawn" || n[1] !== "1" && n[1] !== "8") && e.movable.color === r.color && e.turnColor !== r.color;
|
|
200
|
+
}
|
|
201
|
+
function isDraggable(e, t) {
|
|
202
|
+
let n = e.pieces.get(t);
|
|
203
|
+
return !!n && e.draggable.enabled && (e.movable.color === "both" || e.movable.color === n.color && (e.turnColor === n.color || e.premovable.enabled));
|
|
204
|
+
}
|
|
205
|
+
function playPremove(e) {
|
|
206
|
+
let t = e.premovable.current;
|
|
207
|
+
if (!t) return !1;
|
|
208
|
+
let n = t[0], r = t[1], i = !1;
|
|
209
|
+
if (canMove(e, n, r)) {
|
|
210
|
+
let t = baseUserMove(e, n, r);
|
|
211
|
+
if (t) {
|
|
212
|
+
let a = { premove: !0 };
|
|
213
|
+
t !== !0 && (a.captured = t), callUserFunction(e.movable.events.after, n, r, a), i = !0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return unsetPremove(e), i;
|
|
217
|
+
}
|
|
218
|
+
function playPredrop(e, t) {
|
|
219
|
+
let n = e.predroppable.current, r = !1;
|
|
220
|
+
return n ? (t(n) && baseNewPiece(e, {
|
|
221
|
+
role: n.role,
|
|
222
|
+
color: e.movable.color
|
|
223
|
+
}, n.key) && (callUserFunction(e.movable.events.afterNewPiece, n.role, n.key, {
|
|
224
|
+
premove: !1,
|
|
225
|
+
predrop: !0
|
|
226
|
+
}), r = !0), unsetPredrop(e), r) : !1;
|
|
227
|
+
}
|
|
228
|
+
function cancelMove(e) {
|
|
229
|
+
unsetPremove(e), unsetPredrop(e), unselect(e);
|
|
230
|
+
}
|
|
231
|
+
function stop(e) {
|
|
232
|
+
e.movable.color = e.movable.dests = e.animation.current = void 0, cancelMove(e);
|
|
233
|
+
}
|
|
234
|
+
function getKeyAtDomPos(e, t, n) {
|
|
235
|
+
let r = Math.floor(8 * (e[0] - n.left) / n.width);
|
|
236
|
+
t || (r = 7 - r);
|
|
237
|
+
let i = 7 - Math.floor(8 * (e[1] - n.top) / n.height);
|
|
238
|
+
return t || (i = 7 - i), r >= 0 && r < 8 && i >= 0 && i < 8 ? pos2key([r, i]) : void 0;
|
|
239
|
+
}
|
|
240
|
+
function getSnappedKeyAtDomPos(e, t, n, r) {
|
|
241
|
+
let i = key2pos(e), a = D.filter((e) => queen(i[0], i[1], e[0], e[1]) || knight(i[0], i[1], e[0], e[1])), o = a.map((e) => computeSquareCenter(pos2key(e), n, r)).map((e) => distanceSq(t, e)), [, s] = o.reduce((e, t, n) => e[0] < t ? e : [t, n], [o[0], 0]);
|
|
242
|
+
return pos2key(a[s]);
|
|
243
|
+
}
|
|
244
|
+
var whitePov = (e) => e.orientation === "cg-white", O = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", k = {
|
|
245
|
+
p: "pawn",
|
|
246
|
+
r: "rook",
|
|
247
|
+
n: "knight",
|
|
248
|
+
b: "bishop",
|
|
249
|
+
q: "queen",
|
|
250
|
+
k: "king"
|
|
251
|
+
}, A = {
|
|
252
|
+
pawn: "p",
|
|
253
|
+
rook: "r",
|
|
254
|
+
knight: "n",
|
|
255
|
+
bishop: "b",
|
|
256
|
+
queen: "q",
|
|
257
|
+
king: "k"
|
|
258
|
+
};
|
|
259
|
+
function read(e) {
|
|
260
|
+
e === "start" && (e = O);
|
|
261
|
+
let t = /* @__PURE__ */ new Map(), n = 7, r = 0;
|
|
262
|
+
for (let i of e) switch (i) {
|
|
263
|
+
case " ":
|
|
264
|
+
case "[": return t;
|
|
265
|
+
case "/":
|
|
266
|
+
if (--n, n < 0) return t;
|
|
267
|
+
r = 0;
|
|
268
|
+
break;
|
|
269
|
+
case "~": {
|
|
270
|
+
let e = t.get(pos2key([r - 1, n]));
|
|
271
|
+
e && (e.promoted = !0);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
default: {
|
|
275
|
+
let e = i.charCodeAt(0);
|
|
276
|
+
if (e < 57) r += e - 48;
|
|
277
|
+
else {
|
|
278
|
+
let e = i.toLowerCase();
|
|
279
|
+
t.set(pos2key([r, n]), {
|
|
280
|
+
role: k[e],
|
|
281
|
+
color: i === e ? "cg-black" : "cg-white"
|
|
282
|
+
}), ++r;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return t;
|
|
287
|
+
}
|
|
288
|
+
function write(e) {
|
|
289
|
+
return T.map((t) => C.map((n) => {
|
|
290
|
+
let r = e.get(n + t);
|
|
291
|
+
if (r) {
|
|
292
|
+
let e = A[r.role];
|
|
293
|
+
return r.color === "cg-white" && (e = e.toUpperCase()), r.promoted && (e += "~"), e;
|
|
294
|
+
} else return "1";
|
|
295
|
+
}).join("")).join("/").replace(/1{2,}/g, (e) => e.length.toString());
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/chess/chessground/config.ts
|
|
299
|
+
function applyAnimation(e, t) {
|
|
300
|
+
t.animation && (deepMerge(e.animation, t.animation), (e.animation.duration || 0) < 70 && (e.animation.enabled = !1));
|
|
301
|
+
}
|
|
302
|
+
function configure(e, t) {
|
|
303
|
+
if (t.movable?.dests && (e.movable.dests = void 0), t.drawable?.autoShapes && (e.drawable.autoShapes = []), deepMerge(e, t), t.fen && (e.pieces = read(t.fen), e.drawable.shapes = t.drawable?.shapes || []), "check" in t && setCheck(e, t.check || !1), "lastMove" in t && !t.lastMove ? e.lastMove = void 0 : t.lastMove && (e.lastMove = t.lastMove), e.selected && setSelected(e, e.selected), applyAnimation(e, t), !e.movable.rookCastle && e.movable.dests) {
|
|
304
|
+
let t = e.movable.color === "cg-white" ? "1" : "8", n = "e" + t, r = e.movable.dests.get(n), i = e.pieces.get(n);
|
|
305
|
+
if (!r || !i || i.role !== "king") return;
|
|
306
|
+
e.movable.dests.set(n, r.filter((e) => !(e === "a" + t && r.includes("c" + t)) && !(e === "h" + t && r.includes("g" + t))));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function deepMerge(e, t) {
|
|
310
|
+
for (let n in t) Object.prototype.hasOwnProperty.call(t, n) && (Object.prototype.hasOwnProperty.call(e, n) && isPlainObject(e[n]) && isPlainObject(t[n]) ? deepMerge(e[n], t[n]) : e[n] = t[n]);
|
|
311
|
+
}
|
|
312
|
+
function isPlainObject(e) {
|
|
313
|
+
if (typeof e != "object" || !e) return !1;
|
|
314
|
+
let t = Object.getPrototypeOf(e);
|
|
315
|
+
return t === Object.prototype || t === null;
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/chess/chessground/anim.ts
|
|
319
|
+
var anim = (e, t) => t.animation.enabled ? animate(e, t) : render$2(e, t);
|
|
320
|
+
function render$2(e, t) {
|
|
321
|
+
let n = e(t);
|
|
322
|
+
return t.dom.redraw(), n;
|
|
323
|
+
}
|
|
324
|
+
e(render$2, "render");
|
|
325
|
+
var makePiece = (e, t) => ({
|
|
326
|
+
key: e,
|
|
327
|
+
pos: key2pos(e),
|
|
328
|
+
piece: t
|
|
329
|
+
}), closer = (e, t) => t.sort((t, n) => distanceSq(e.pos, t.pos) - distanceSq(e.pos, n.pos))[0];
|
|
330
|
+
function computePlan(e, t) {
|
|
331
|
+
let n = /* @__PURE__ */ new Map(), r = [], i = /* @__PURE__ */ new Map(), a = [], o = [], s = /* @__PURE__ */ new Map(), c, l, u;
|
|
332
|
+
for (let [t, n] of e) s.set(t, makePiece(t, n));
|
|
333
|
+
for (let e of E) c = t.pieces.get(e), l = s.get(e), c ? l ? samePiece(c, l.piece) || (a.push(l), o.push(makePiece(e, c))) : o.push(makePiece(e, c)) : l && a.push(l);
|
|
334
|
+
for (let e of o) l = closer(e, a.filter((t) => samePiece(e.piece, t.piece))), l && (u = [l.pos[0] - e.pos[0], l.pos[1] - e.pos[1]], n.set(e.key, u.concat(u)), r.push(l.key));
|
|
335
|
+
for (let e of a) r.includes(e.key) || i.set(e.key, e.piece);
|
|
336
|
+
return {
|
|
337
|
+
anims: n,
|
|
338
|
+
fadings: i
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function step(e, t) {
|
|
342
|
+
let n = e.animation.current;
|
|
343
|
+
if (n === void 0) {
|
|
344
|
+
e.dom.destroyed || e.dom.redrawNow();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
let r = 1 - (t - n.start) * n.frequency;
|
|
348
|
+
if (r <= 0) e.animation.current = void 0, e.dom.redrawNow();
|
|
349
|
+
else {
|
|
350
|
+
let t = easing(r);
|
|
351
|
+
for (let e of n.plan.anims.values()) e[2] = e[0] * t, e[3] = e[1] * t;
|
|
352
|
+
e.dom.redrawNow(!0), requestAnimationFrame((t = performance.now()) => step(e, t));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function animate(e, t) {
|
|
356
|
+
let n = new Map(t.pieces), r = e(t), i = computePlan(n, t);
|
|
357
|
+
if (i.anims.size || i.fadings.size) {
|
|
358
|
+
let e = t.animation.current && t.animation.current.start;
|
|
359
|
+
t.animation.current = {
|
|
360
|
+
start: performance.now(),
|
|
361
|
+
frequency: 1 / t.animation.duration,
|
|
362
|
+
plan: i
|
|
363
|
+
}, e || step(t, performance.now());
|
|
364
|
+
} else t.dom.redraw();
|
|
365
|
+
return r;
|
|
366
|
+
}
|
|
367
|
+
var easing = (e) => e < .5 ? 4 * e * e * e : (e - 1) * (2 * e - 2) * (2 * e - 2) + 1, j = [
|
|
368
|
+
"green",
|
|
369
|
+
"red",
|
|
370
|
+
"blue",
|
|
371
|
+
"yellow"
|
|
372
|
+
];
|
|
373
|
+
function start$2(e, t) {
|
|
374
|
+
if (t.touches && t.touches.length > 1) return;
|
|
375
|
+
t.stopPropagation(), t.preventDefault(), t.ctrlKey ? unselect(e) : cancelMove(e);
|
|
376
|
+
let n = eventPosition(t), r = getKeyAtDomPos(n, whitePov(e), e.dom.bounds());
|
|
377
|
+
r && (e.drawable.current = {
|
|
378
|
+
orig: r,
|
|
379
|
+
pos: n,
|
|
380
|
+
brush: eventBrush(t),
|
|
381
|
+
snapToValidMove: e.drawable.defaultSnapToValidMove
|
|
382
|
+
}, processDraw(e));
|
|
383
|
+
}
|
|
384
|
+
e(start$2, "start");
|
|
385
|
+
function processDraw(e) {
|
|
386
|
+
requestAnimationFrame(() => {
|
|
387
|
+
let t = e.drawable.current;
|
|
388
|
+
if (t) {
|
|
389
|
+
let n = getKeyAtDomPos(t.pos, whitePov(e), e.dom.bounds());
|
|
390
|
+
n || (t.snapToValidMove = !1);
|
|
391
|
+
let r = t.snapToValidMove ? getSnappedKeyAtDomPos(t.orig, t.pos, whitePov(e), e.dom.bounds()) : n;
|
|
392
|
+
r !== t.mouseSq && (t.mouseSq = r, t.dest = r === t.orig ? void 0 : r, e.dom.redrawNow()), processDraw(e);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function move$1(e, t) {
|
|
397
|
+
e.drawable.current && (e.drawable.current.pos = eventPosition(t));
|
|
398
|
+
}
|
|
399
|
+
e(move$1, "move");
|
|
400
|
+
function end$1(e) {
|
|
401
|
+
let t = e.drawable.current;
|
|
402
|
+
t && (t.mouseSq && addShape(e.drawable, t), cancel$1(e));
|
|
403
|
+
}
|
|
404
|
+
e(end$1, "end");
|
|
405
|
+
function cancel$1(e) {
|
|
406
|
+
e.drawable.current && (e.drawable.current = void 0, e.dom.redraw());
|
|
407
|
+
}
|
|
408
|
+
e(cancel$1, "cancel");
|
|
409
|
+
function clear(e) {
|
|
410
|
+
e.drawable.shapes.length && (e.drawable.shapes = [], e.dom.redraw(), onChange(e.drawable));
|
|
411
|
+
}
|
|
412
|
+
function eventBrush(e) {
|
|
413
|
+
let t = (e.shiftKey || e.ctrlKey) && isRightButton(e), n = e.altKey || e.metaKey || e.getModifierState?.("AltGraph");
|
|
414
|
+
return j[(t ? 1 : 0) + (n ? 2 : 0)];
|
|
415
|
+
}
|
|
416
|
+
function addShape(e, t) {
|
|
417
|
+
let sameShape = (e) => e.orig === t.orig && e.dest === t.dest, n = e.shapes.find(sameShape);
|
|
418
|
+
n && (e.shapes = e.shapes.filter((e) => !sameShape(e))), (!n || n.brush !== t.brush) && e.shapes.push({
|
|
419
|
+
orig: t.orig,
|
|
420
|
+
dest: t.dest,
|
|
421
|
+
brush: t.brush
|
|
422
|
+
}), onChange(e);
|
|
423
|
+
}
|
|
424
|
+
function onChange(e) {
|
|
425
|
+
e.onChange && e.onChange(e.shapes);
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/chess/chessground/drag.ts
|
|
429
|
+
function start$1(e, t) {
|
|
430
|
+
if (!(e.trustAllEvents || t.isTrusted) || t.buttons !== void 0 && t.buttons > 1 || t.touches && t.touches.length > 1) return;
|
|
431
|
+
let n = e.dom.bounds(), r = eventPosition(t), i = getKeyAtDomPos(r, whitePov(e), n);
|
|
432
|
+
if (!i) return;
|
|
433
|
+
let a = e.pieces.get(i), o = e.selected;
|
|
434
|
+
if (!o && e.drawable.enabled && (e.drawable.eraseOnClick || !a || a.color !== e.turnColor) && clear(e), t.cancelable !== !1 && (!t.touches || e.blockTouchScroll || a || o || pieceCloseTo(e, r))) t.preventDefault();
|
|
435
|
+
else if (t.touches) return;
|
|
436
|
+
let s = !!e.premovable.current, c = !!e.predroppable.current;
|
|
437
|
+
e.stats.ctrlKey = t.ctrlKey, e.selected && canMove(e, e.selected, i) ? anim((e) => selectSquare(e, i), e) : selectSquare(e, i);
|
|
438
|
+
let l = e.selected === i, u = pieceElementByKey(e, i);
|
|
439
|
+
if (a && u && l && isDraggable(e, i)) {
|
|
440
|
+
e.draggable.current = {
|
|
441
|
+
orig: i,
|
|
442
|
+
piece: a,
|
|
443
|
+
origPos: r,
|
|
444
|
+
pos: r,
|
|
445
|
+
started: e.draggable.autoDistance && e.stats.dragged,
|
|
446
|
+
element: u,
|
|
447
|
+
previouslySelected: o,
|
|
448
|
+
originTarget: t.target,
|
|
449
|
+
keyHasChanged: !1
|
|
450
|
+
}, u.cgDragging = !0, u.classList.add("dragging");
|
|
451
|
+
let s = e.dom.elements.ghost;
|
|
452
|
+
s && (s.className = `ghost ${a.color} ${a.role}`, translate(s, posToTranslate(n)(key2pos(i), whitePov(e))), setVisible(s, !0)), processDrag(e);
|
|
453
|
+
} else s && unsetPremove(e), c && unsetPredrop(e);
|
|
454
|
+
e.dom.redraw();
|
|
455
|
+
}
|
|
456
|
+
e(start$1, "start");
|
|
457
|
+
function pieceCloseTo(e, t) {
|
|
458
|
+
let n = whitePov(e), r = e.dom.bounds(), i = (r.width / 8) ** 2;
|
|
459
|
+
for (let a of e.pieces.keys()) if (distanceSq(computeSquareCenter(a, n, r), t) <= i) return !0;
|
|
460
|
+
return !1;
|
|
461
|
+
}
|
|
462
|
+
function dragNewPiece(e, t, n, r) {
|
|
463
|
+
e.pieces.set("a0", t), e.dom.redraw();
|
|
464
|
+
let i = eventPosition(n);
|
|
465
|
+
e.draggable.current = {
|
|
466
|
+
orig: "a0",
|
|
467
|
+
piece: t,
|
|
468
|
+
origPos: i,
|
|
469
|
+
pos: i,
|
|
470
|
+
started: !0,
|
|
471
|
+
element: () => pieceElementByKey(e, "a0"),
|
|
472
|
+
originTarget: n.target,
|
|
473
|
+
newPiece: !0,
|
|
474
|
+
force: !!r,
|
|
475
|
+
keyHasChanged: !1
|
|
476
|
+
}, processDrag(e);
|
|
477
|
+
}
|
|
478
|
+
function processDrag(e) {
|
|
479
|
+
requestAnimationFrame(() => {
|
|
480
|
+
let t = e.draggable.current;
|
|
481
|
+
if (!t) return;
|
|
482
|
+
e.animation.current?.plan.anims.has(t.orig) && (e.animation.current = void 0);
|
|
483
|
+
let n = e.pieces.get(t.orig);
|
|
484
|
+
if (!n || !samePiece(n, t.piece)) cancel(e);
|
|
485
|
+
else if (!t.started && distanceSq(t.pos, t.origPos) >= e.draggable.distance ** 2 && (t.started = !0), t.started) {
|
|
486
|
+
if (typeof t.element == "function") {
|
|
487
|
+
let e = t.element();
|
|
488
|
+
if (!e) return;
|
|
489
|
+
e.cgDragging = !0, e.classList.add("dragging"), t.element = e;
|
|
490
|
+
}
|
|
491
|
+
let n = e.dom.bounds();
|
|
492
|
+
translate(t.element, [t.pos[0] - n.left - n.width / 16, t.pos[1] - n.top - n.height / 16]), t.keyHasChanged = t.keyHasChanged || t.orig !== getKeyAtDomPos(t.pos, whitePov(e), n);
|
|
493
|
+
}
|
|
494
|
+
processDrag(e);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
function move(e, t) {
|
|
498
|
+
e.draggable.current && (!t.touches || t.touches.length < 2) && (e.draggable.current.pos = eventPosition(t));
|
|
499
|
+
}
|
|
500
|
+
function end(e, t) {
|
|
501
|
+
let n = e.draggable.current;
|
|
502
|
+
if (!n) return;
|
|
503
|
+
if (t.type === "touchend" && t.cancelable !== !1 && t.preventDefault(), t.type === "touchend" && n.originTarget !== t.target && !n.newPiece) {
|
|
504
|
+
e.draggable.current = void 0;
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
unsetPremove(e), unsetPredrop(e);
|
|
508
|
+
let r = getKeyAtDomPos(eventPosition(t) || n.pos, whitePov(e), e.dom.bounds());
|
|
509
|
+
r && n.started && n.orig !== r ? n.newPiece ? dropNewPiece(e, n.orig, r, n.force) : (e.stats.ctrlKey = t.ctrlKey, userMove(e, n.orig, r) && (e.stats.dragged = !0)) : n.newPiece ? e.pieces.delete(n.orig) : e.draggable.deleteOnDropOff && !r && (e.pieces.delete(n.orig), callUserFunction(e.events.change)), (n.orig === n.previouslySelected || n.keyHasChanged) && (n.orig === r || !r) ? unselect(e) : e.selectable.enabled || unselect(e), removeDragElements(e), e.draggable.current = void 0, e.dom.redraw();
|
|
510
|
+
}
|
|
511
|
+
function cancel(e) {
|
|
512
|
+
let t = e.draggable.current;
|
|
513
|
+
t && (t.newPiece && e.pieces.delete(t.orig), e.draggable.current = void 0, unselect(e), removeDragElements(e), e.dom.redraw());
|
|
514
|
+
}
|
|
515
|
+
function removeDragElements(e) {
|
|
516
|
+
let t = e.dom.elements;
|
|
517
|
+
t.ghost && setVisible(t.ghost, !1);
|
|
518
|
+
}
|
|
519
|
+
function pieceElementByKey(e, t) {
|
|
520
|
+
let n = e.dom.elements.board.firstChild;
|
|
521
|
+
for (; n;) {
|
|
522
|
+
if (n.cgKey === t && n.tagName === "PIECE") return n;
|
|
523
|
+
n = n.nextSibling;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region src/chess/chessground/explosion.ts
|
|
528
|
+
function explosion(e, t) {
|
|
529
|
+
e.exploding = {
|
|
530
|
+
stage: 1,
|
|
531
|
+
keys: t
|
|
532
|
+
}, e.dom.redraw(), setTimeout(() => {
|
|
533
|
+
setStage(e, 2), setTimeout(() => setStage(e, void 0), 120);
|
|
534
|
+
}, 120);
|
|
535
|
+
}
|
|
536
|
+
function setStage(e, t) {
|
|
537
|
+
e.exploding && (t ? e.exploding.stage = t : e.exploding = void 0, e.dom.redraw());
|
|
538
|
+
}
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/chess/chessground/api.ts
|
|
541
|
+
function start(t, n) {
|
|
542
|
+
function toggleOrientation$1() {
|
|
543
|
+
toggleOrientation(t), n();
|
|
544
|
+
}
|
|
545
|
+
return e(toggleOrientation$1, "toggleOrientation"), {
|
|
546
|
+
set(e) {
|
|
547
|
+
e.orientation && e.orientation !== t.orientation && toggleOrientation$1(), applyAnimation(t, e), (e.fen ? anim : render$2)((t) => configure(t, e), t);
|
|
548
|
+
},
|
|
549
|
+
state: t,
|
|
550
|
+
getFen: () => write(t.pieces),
|
|
551
|
+
toggleOrientation: toggleOrientation$1,
|
|
552
|
+
setPieces(e) {
|
|
553
|
+
anim((t) => setPieces(t, e), t);
|
|
554
|
+
},
|
|
555
|
+
selectSquare(e, n) {
|
|
556
|
+
e ? anim((t) => selectSquare(t, e, n), t) : t.selected && (unselect(t), t.dom.redraw());
|
|
557
|
+
},
|
|
558
|
+
move(e, n) {
|
|
559
|
+
anim((t) => baseMove(t, e, n), t);
|
|
560
|
+
},
|
|
561
|
+
newPiece(e, n) {
|
|
562
|
+
anim((t) => baseNewPiece(t, e, n), t);
|
|
563
|
+
},
|
|
564
|
+
playPremove() {
|
|
565
|
+
if (t.premovable.current) {
|
|
566
|
+
if (anim(playPremove, t)) return !0;
|
|
567
|
+
t.dom.redraw();
|
|
568
|
+
}
|
|
569
|
+
return !1;
|
|
570
|
+
},
|
|
571
|
+
playPredrop(e) {
|
|
572
|
+
if (t.predroppable.current) {
|
|
573
|
+
let n = playPredrop(t, e);
|
|
574
|
+
return t.dom.redraw(), n;
|
|
575
|
+
}
|
|
576
|
+
return !1;
|
|
577
|
+
},
|
|
578
|
+
cancelPremove() {
|
|
579
|
+
render$2(unsetPremove, t);
|
|
580
|
+
},
|
|
581
|
+
cancelPredrop() {
|
|
582
|
+
render$2(unsetPredrop, t);
|
|
583
|
+
},
|
|
584
|
+
cancelMove() {
|
|
585
|
+
render$2((e) => {
|
|
586
|
+
cancelMove(e), cancel(e);
|
|
587
|
+
}, t);
|
|
588
|
+
},
|
|
589
|
+
stop() {
|
|
590
|
+
render$2((e) => {
|
|
591
|
+
stop(e), cancel(e);
|
|
592
|
+
}, t);
|
|
593
|
+
},
|
|
594
|
+
explode(e) {
|
|
595
|
+
explosion(t, e);
|
|
596
|
+
},
|
|
597
|
+
setAutoShapes(e) {
|
|
598
|
+
render$2((t) => t.drawable.autoShapes = e, t);
|
|
599
|
+
},
|
|
600
|
+
setShapes(e) {
|
|
601
|
+
render$2((t) => t.drawable.shapes = e, t);
|
|
602
|
+
},
|
|
603
|
+
getKeyAtDomPos(e) {
|
|
604
|
+
return getKeyAtDomPos(e, whitePov(t), t.dom.bounds());
|
|
605
|
+
},
|
|
606
|
+
redrawAll: n,
|
|
607
|
+
dragNewPiece(e, n, r) {
|
|
608
|
+
dragNewPiece(t, e, n, r);
|
|
609
|
+
},
|
|
610
|
+
destroy() {
|
|
611
|
+
stop(t), t.dom.unbind?.(), t.dom.destroyed = !0;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
//#endregion
|
|
616
|
+
//#region src/chess/chessground/state.ts
|
|
617
|
+
function defaults() {
|
|
618
|
+
return {
|
|
619
|
+
pieces: read(O),
|
|
620
|
+
orientation: "cg-white",
|
|
621
|
+
turnColor: "cg-white",
|
|
622
|
+
coordinates: !0,
|
|
623
|
+
coordinatesOnSquares: !1,
|
|
624
|
+
ranksPosition: "right",
|
|
625
|
+
autoCastle: !0,
|
|
626
|
+
viewOnly: !1,
|
|
627
|
+
disableContextMenu: !1,
|
|
628
|
+
addPieceZIndex: !1,
|
|
629
|
+
blockTouchScroll: !1,
|
|
630
|
+
pieceKey: !1,
|
|
631
|
+
trustAllEvents: !1,
|
|
632
|
+
highlight: {
|
|
633
|
+
lastMove: !0,
|
|
634
|
+
check: !0
|
|
635
|
+
},
|
|
636
|
+
animation: {
|
|
637
|
+
enabled: !0,
|
|
638
|
+
duration: 200
|
|
639
|
+
},
|
|
640
|
+
movable: {
|
|
641
|
+
free: !0,
|
|
642
|
+
color: "both",
|
|
643
|
+
showDests: !0,
|
|
644
|
+
events: {},
|
|
645
|
+
rookCastle: !0
|
|
646
|
+
},
|
|
647
|
+
premovable: {
|
|
648
|
+
enabled: !0,
|
|
649
|
+
showDests: !0,
|
|
650
|
+
castle: !0,
|
|
651
|
+
events: {}
|
|
652
|
+
},
|
|
653
|
+
predroppable: {
|
|
654
|
+
enabled: !1,
|
|
655
|
+
events: {}
|
|
656
|
+
},
|
|
657
|
+
draggable: {
|
|
658
|
+
enabled: !0,
|
|
659
|
+
distance: 3,
|
|
660
|
+
autoDistance: !0,
|
|
661
|
+
showGhost: !0,
|
|
662
|
+
deleteOnDropOff: !1
|
|
663
|
+
},
|
|
664
|
+
dropmode: { active: !1 },
|
|
665
|
+
selectable: { enabled: !0 },
|
|
666
|
+
stats: { dragged: !("ontouchstart" in window) },
|
|
667
|
+
events: {},
|
|
668
|
+
drawable: {
|
|
669
|
+
enabled: !0,
|
|
670
|
+
visible: !0,
|
|
671
|
+
defaultSnapToValidMove: !0,
|
|
672
|
+
eraseOnClick: !0,
|
|
673
|
+
shapes: [],
|
|
674
|
+
autoShapes: [],
|
|
675
|
+
brushes: {
|
|
676
|
+
green: {
|
|
677
|
+
key: "g",
|
|
678
|
+
color: "#15781B",
|
|
679
|
+
opacity: 1,
|
|
680
|
+
lineWidth: 10
|
|
681
|
+
},
|
|
682
|
+
red: {
|
|
683
|
+
key: "r",
|
|
684
|
+
color: "#882020",
|
|
685
|
+
opacity: 1,
|
|
686
|
+
lineWidth: 10
|
|
687
|
+
},
|
|
688
|
+
blue: {
|
|
689
|
+
key: "b",
|
|
690
|
+
color: "#003088",
|
|
691
|
+
opacity: 1,
|
|
692
|
+
lineWidth: 10
|
|
693
|
+
},
|
|
694
|
+
yellow: {
|
|
695
|
+
key: "y",
|
|
696
|
+
color: "#e68f00",
|
|
697
|
+
opacity: 1,
|
|
698
|
+
lineWidth: 10
|
|
699
|
+
},
|
|
700
|
+
paleBlue: {
|
|
701
|
+
key: "pb",
|
|
702
|
+
color: "#003088",
|
|
703
|
+
opacity: .4,
|
|
704
|
+
lineWidth: 15
|
|
705
|
+
},
|
|
706
|
+
paleGreen: {
|
|
707
|
+
key: "pg",
|
|
708
|
+
color: "#15781B",
|
|
709
|
+
opacity: .4,
|
|
710
|
+
lineWidth: 15
|
|
711
|
+
},
|
|
712
|
+
paleRed: {
|
|
713
|
+
key: "pr",
|
|
714
|
+
color: "#882020",
|
|
715
|
+
opacity: .4,
|
|
716
|
+
lineWidth: 15
|
|
717
|
+
},
|
|
718
|
+
paleGrey: {
|
|
719
|
+
key: "pgr",
|
|
720
|
+
color: "#4a4a4a",
|
|
721
|
+
opacity: .35,
|
|
722
|
+
lineWidth: 15
|
|
723
|
+
},
|
|
724
|
+
purple: {
|
|
725
|
+
key: "purple",
|
|
726
|
+
color: "#68217a",
|
|
727
|
+
opacity: .65,
|
|
728
|
+
lineWidth: 10
|
|
729
|
+
},
|
|
730
|
+
pink: {
|
|
731
|
+
key: "pink",
|
|
732
|
+
color: "#ee2080",
|
|
733
|
+
opacity: .5,
|
|
734
|
+
lineWidth: 10
|
|
735
|
+
},
|
|
736
|
+
white: {
|
|
737
|
+
key: "white",
|
|
738
|
+
color: "white",
|
|
739
|
+
opacity: 1,
|
|
740
|
+
lineWidth: 10
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
prevSvgHash: ""
|
|
744
|
+
},
|
|
745
|
+
hold: timer()
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
//#endregion
|
|
749
|
+
//#region src/chess/chessground/svg.ts
|
|
750
|
+
var M = {
|
|
751
|
+
hilitePrimary: {
|
|
752
|
+
key: "hilitePrimary",
|
|
753
|
+
color: "#3291ff",
|
|
754
|
+
opacity: 1,
|
|
755
|
+
lineWidth: 1
|
|
756
|
+
},
|
|
757
|
+
hiliteWhite: {
|
|
758
|
+
key: "hiliteWhite",
|
|
759
|
+
color: "#ffffff",
|
|
760
|
+
opacity: 1,
|
|
761
|
+
lineWidth: 1
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
function createDefs() {
|
|
765
|
+
let e = createElement("defs"), t = setAttributes(createElement("filter"), { id: "cg-filter-blur" });
|
|
766
|
+
return t.appendChild(setAttributes(createElement("feGaussianBlur"), { stdDeviation: "0.019" })), e.appendChild(t), e;
|
|
767
|
+
}
|
|
768
|
+
function renderSvg(e, t, n) {
|
|
769
|
+
let r = e.drawable, i = r.current, a = i && i.mouseSq ? i : void 0, o = /* @__PURE__ */ new Map(), s = e.dom.bounds(), c = r.autoShapes.filter((e) => !e.piece);
|
|
770
|
+
for (let t of r.shapes.concat(c).concat(a ? [a] : [])) {
|
|
771
|
+
if (!t.dest) continue;
|
|
772
|
+
let n = o.get(t.dest) ?? /* @__PURE__ */ new Set(), r = pos2user(orient(key2pos(t.orig), e.orientation), s), i = pos2user(orient(key2pos(t.dest), e.orientation), s);
|
|
773
|
+
n.add(moveAngle(r, i)), o.set(t.dest, n);
|
|
774
|
+
}
|
|
775
|
+
let l = r.shapes.concat(c).map((e) => ({
|
|
776
|
+
shape: e,
|
|
777
|
+
current: !1,
|
|
778
|
+
hash: shapeHash(e, isShort(e.dest, o), !1, s)
|
|
779
|
+
}));
|
|
780
|
+
a && l.push({
|
|
781
|
+
shape: a,
|
|
782
|
+
current: !0,
|
|
783
|
+
hash: shapeHash(a, isShort(a.dest, o), !0, s)
|
|
784
|
+
});
|
|
785
|
+
let u = l.map((e) => e.hash).join(";");
|
|
786
|
+
u !== e.drawable.prevSvgHash && (e.drawable.prevSvgHash = u, syncDefs(r, l, t.querySelector("defs")), syncShapes$1(l, t.querySelector("g"), n.querySelector("g"), (t) => renderShape$1(e, t, r.brushes, o, s)));
|
|
787
|
+
}
|
|
788
|
+
function syncDefs(e, t, n) {
|
|
789
|
+
let r = /* @__PURE__ */ new Map(), i;
|
|
790
|
+
for (let n of t.filter((e) => e.shape.dest && e.shape.brush)) i = makeCustomBrush(e.brushes[n.shape.brush], n.shape.modifiers), n.shape.modifiers?.hilite && r.set(hilite(i).key, hilite(i)), r.set(i.key, i);
|
|
791
|
+
let a = /* @__PURE__ */ new Set(), o = n.firstElementChild;
|
|
792
|
+
for (; o;) a.add(o.getAttribute("cgKey")), o = o.nextElementSibling;
|
|
793
|
+
for (let [e, t] of r.entries()) a.has(e) || n.appendChild(renderMarker(t));
|
|
794
|
+
}
|
|
795
|
+
function syncShapes$1(e, t, n, r) {
|
|
796
|
+
let i = /* @__PURE__ */ new Map();
|
|
797
|
+
for (let t of e) i.set(t.hash, !1);
|
|
798
|
+
for (let e of [t, n]) {
|
|
799
|
+
let t = [], n = e.firstElementChild, r;
|
|
800
|
+
for (; n;) r = n.getAttribute("cgHash"), i.has(r) ? i.set(r, !0) : t.push(n), n = n.nextElementSibling;
|
|
801
|
+
for (let n of t) e.removeChild(n);
|
|
802
|
+
}
|
|
803
|
+
for (let a of e.filter((e) => !i.get(e.hash))) for (let e of r(a)) e.isCustom ? n.appendChild(e.el) : t.appendChild(e.el);
|
|
804
|
+
}
|
|
805
|
+
e(syncShapes$1, "syncShapes");
|
|
806
|
+
function shapeHash({ orig: e, dest: t, brush: n, piece: r, modifiers: i, customSvg: a, label: o }, s, c, l) {
|
|
807
|
+
return [
|
|
808
|
+
l.width,
|
|
809
|
+
l.height,
|
|
810
|
+
c,
|
|
811
|
+
e,
|
|
812
|
+
t,
|
|
813
|
+
n,
|
|
814
|
+
s && "-",
|
|
815
|
+
r && pieceHash(r),
|
|
816
|
+
i && modifiersHash(i),
|
|
817
|
+
a && `custom-${textHash(a.html)},${a.center?.[0] ?? "o"}`,
|
|
818
|
+
o && `label-${textHash(o.text)}`
|
|
819
|
+
].filter((e) => e).join(",");
|
|
820
|
+
}
|
|
821
|
+
function pieceHash(e) {
|
|
822
|
+
return [
|
|
823
|
+
e.color,
|
|
824
|
+
e.role,
|
|
825
|
+
e.scale
|
|
826
|
+
].filter((e) => e).join(",");
|
|
827
|
+
}
|
|
828
|
+
function modifiersHash(e) {
|
|
829
|
+
return [e.lineWidth, e.hilite && "*"].filter((e) => e).join(",");
|
|
830
|
+
}
|
|
831
|
+
function textHash(e) {
|
|
832
|
+
let t = 0;
|
|
833
|
+
for (let n = 0; n < e.length; n++) t = (t << 5) - t + e.charCodeAt(n) >>> 0;
|
|
834
|
+
return t.toString();
|
|
835
|
+
}
|
|
836
|
+
function renderShape$1(e, { shape: t, current: n, hash: r }, i, a, o) {
|
|
837
|
+
let s = pos2user(orient(key2pos(t.orig), e.orientation), o), c = t.dest ? pos2user(orient(key2pos(t.dest), e.orientation), o) : s, l = t.brush && makeCustomBrush(i[t.brush], t.modifiers), u = a.get(t.dest), d = [];
|
|
838
|
+
if (l) {
|
|
839
|
+
let e = setAttributes(createElement("g"), { cgHash: r });
|
|
840
|
+
d.push({ el: e }), s[0] !== c[0] || s[1] !== c[1] ? e.appendChild(renderArrow(t, l, s, c, n, isShort(t.dest, a))) : e.appendChild(renderCircle(i[t.brush], s, n, o));
|
|
841
|
+
}
|
|
842
|
+
if (t.label) {
|
|
843
|
+
let e = t.label;
|
|
844
|
+
e.fill || t.brush && i[t.brush] && (e.fill = i[t.brush].color);
|
|
845
|
+
let n = t.brush ? void 0 : "tr";
|
|
846
|
+
d.push({
|
|
847
|
+
el: renderLabel(e, r, s, c, u, n),
|
|
848
|
+
isCustom: !0
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
if (t.customSvg) {
|
|
852
|
+
let e = t.customSvg.center ?? "orig", [n, i] = e === "label" ? labelCoords(s, c, u).map((e) => e - .5) : e === "dest" ? c : s, a = setAttributes(createElement("g"), {
|
|
853
|
+
transform: `translate(${n},${i})`,
|
|
854
|
+
cgHash: r
|
|
855
|
+
});
|
|
856
|
+
a.innerHTML = `<svg width="1" height="1" viewBox="0 0 100 100">${t.customSvg.html}</svg>`, d.push({
|
|
857
|
+
el: a,
|
|
858
|
+
isCustom: !0
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
return d;
|
|
862
|
+
}
|
|
863
|
+
e(renderShape$1, "renderShape");
|
|
864
|
+
function renderCircle(e, t, n, r) {
|
|
865
|
+
let i = circleWidth(), a = (r.width + r.height) / (4 * Math.max(r.width, r.height));
|
|
866
|
+
return setAttributes(createElement("circle"), {
|
|
867
|
+
stroke: e.color,
|
|
868
|
+
"stroke-width": i[n ? 0 : 1],
|
|
869
|
+
fill: "none",
|
|
870
|
+
opacity: opacity(e, n),
|
|
871
|
+
cx: t[0],
|
|
872
|
+
cy: t[1],
|
|
873
|
+
r: a - i[1] / 2
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
function hilite(e) {
|
|
877
|
+
return [
|
|
878
|
+
"#ffffff",
|
|
879
|
+
"#fff",
|
|
880
|
+
"white"
|
|
881
|
+
].includes(e.color) ? M.hilitePrimary : M.hiliteWhite;
|
|
882
|
+
}
|
|
883
|
+
function renderArrow(e, t, n, r, i, a) {
|
|
884
|
+
function renderLine(o) {
|
|
885
|
+
let s = arrowMargin(a && !i), c = r[0] - n[0], l = r[1] - n[1], u = Math.atan2(l, c), d = Math.cos(u) * s, f = Math.sin(u) * s;
|
|
886
|
+
return setAttributes(createElement("line"), {
|
|
887
|
+
stroke: o ? hilite(t).color : t.color,
|
|
888
|
+
"stroke-width": lineWidth(t, i) + (o ? .04 : 0),
|
|
889
|
+
"stroke-linecap": "round",
|
|
890
|
+
"marker-end": `url(#arrowhead-${o ? hilite(t).key : t.key})`,
|
|
891
|
+
opacity: e.modifiers?.hilite ? 1 : opacity(t, i),
|
|
892
|
+
x1: n[0],
|
|
893
|
+
y1: n[1],
|
|
894
|
+
x2: r[0] - d,
|
|
895
|
+
y2: r[1] - f
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
if (!e.modifiers?.hilite) return renderLine(!1);
|
|
899
|
+
let o = createElement("g"), s = setAttributes(createElement("g"), { filter: "url(#cg-filter-blur)" });
|
|
900
|
+
return s.appendChild(filterBox(n, r)), s.appendChild(renderLine(!0)), o.appendChild(s), o.appendChild(renderLine(!1)), o;
|
|
901
|
+
}
|
|
902
|
+
function renderMarker(e) {
|
|
903
|
+
let t = setAttributes(createElement("marker"), {
|
|
904
|
+
id: "arrowhead-" + e.key,
|
|
905
|
+
orient: "auto",
|
|
906
|
+
overflow: "visible",
|
|
907
|
+
markerWidth: 4,
|
|
908
|
+
markerHeight: 4,
|
|
909
|
+
refX: e.key.startsWith("hilite") ? 1.86 : 2.05,
|
|
910
|
+
refY: 2
|
|
911
|
+
});
|
|
912
|
+
return t.appendChild(setAttributes(createElement("path"), {
|
|
913
|
+
d: "M0,0 V4 L3,2 Z",
|
|
914
|
+
fill: e.color
|
|
915
|
+
})), t.setAttribute("cgKey", e.key), t;
|
|
916
|
+
}
|
|
917
|
+
function renderLabel(e, t, n, r, i, a) {
|
|
918
|
+
let o = .4, s = o * .75 ** e.text.length, c = labelCoords(n, r, i), l = a === "tr" ? .4 : 0, u = setAttributes(createElement("g"), {
|
|
919
|
+
transform: `translate(${c[0] + l},${c[1] - l})`,
|
|
920
|
+
cgHash: t
|
|
921
|
+
});
|
|
922
|
+
u.appendChild(setAttributes(createElement("circle"), {
|
|
923
|
+
r: o / 2,
|
|
924
|
+
"fill-opacity": a ? 1 : .8,
|
|
925
|
+
"stroke-opacity": a ? 1 : .7,
|
|
926
|
+
"stroke-width": .03,
|
|
927
|
+
fill: e.fill ?? "#666",
|
|
928
|
+
stroke: "white"
|
|
929
|
+
}));
|
|
930
|
+
let d = setAttributes(createElement("text"), {
|
|
931
|
+
"font-size": s,
|
|
932
|
+
"font-family": "Noto Sans",
|
|
933
|
+
"text-anchor": "middle",
|
|
934
|
+
fill: "white",
|
|
935
|
+
y: .13 * .75 ** e.text.length
|
|
936
|
+
});
|
|
937
|
+
return d.innerHTML = e.text, u.appendChild(d), u;
|
|
938
|
+
}
|
|
939
|
+
function orient(e, t) {
|
|
940
|
+
return t === "cg-white" ? e : [7 - e[0], 7 - e[1]];
|
|
941
|
+
}
|
|
942
|
+
function isShort(e, t) {
|
|
943
|
+
return !0 === (e && t.has(e) && t.get(e).size > 1);
|
|
944
|
+
}
|
|
945
|
+
function createElement(e) {
|
|
946
|
+
return document.createElementNS("http://www.w3.org/2000/svg", e);
|
|
947
|
+
}
|
|
948
|
+
function setAttributes(e, t) {
|
|
949
|
+
for (let n in t) Object.prototype.hasOwnProperty.call(t, n) && e.setAttribute(n, t[n]);
|
|
950
|
+
return e;
|
|
951
|
+
}
|
|
952
|
+
function makeCustomBrush(e, t) {
|
|
953
|
+
return t ? {
|
|
954
|
+
color: e.color,
|
|
955
|
+
opacity: Math.round(e.opacity * 10) / 10,
|
|
956
|
+
lineWidth: Math.round(t.lineWidth || e.lineWidth),
|
|
957
|
+
key: [e.key, t.lineWidth].filter((e) => e).join("")
|
|
958
|
+
} : e;
|
|
959
|
+
}
|
|
960
|
+
function circleWidth() {
|
|
961
|
+
return [3 / 64, 4 / 64];
|
|
962
|
+
}
|
|
963
|
+
function lineWidth(e, t) {
|
|
964
|
+
return (e.lineWidth || 10) * (t ? .85 : 1) / 64;
|
|
965
|
+
}
|
|
966
|
+
function opacity(e, t) {
|
|
967
|
+
return (e.opacity || 1) * (t ? .9 : 1);
|
|
968
|
+
}
|
|
969
|
+
function arrowMargin(e) {
|
|
970
|
+
return (e ? 20 : 10) / 64;
|
|
971
|
+
}
|
|
972
|
+
function pos2user(e, t) {
|
|
973
|
+
let n = Math.min(1, t.width / t.height), r = Math.min(1, t.height / t.width);
|
|
974
|
+
return [(e[0] - 3.5) * n, (3.5 - e[1]) * r];
|
|
975
|
+
}
|
|
976
|
+
function filterBox(e, t) {
|
|
977
|
+
let n = {
|
|
978
|
+
from: [Math.floor(Math.min(e[0], t[0])), Math.floor(Math.min(e[1], t[1]))],
|
|
979
|
+
to: [Math.ceil(Math.max(e[0], t[0])), Math.ceil(Math.max(e[1], t[1]))]
|
|
980
|
+
};
|
|
981
|
+
return setAttributes(createElement("rect"), {
|
|
982
|
+
x: n.from[0],
|
|
983
|
+
y: n.from[1],
|
|
984
|
+
width: n.to[0] - n.from[0],
|
|
985
|
+
height: n.to[1] - n.from[1],
|
|
986
|
+
fill: "none",
|
|
987
|
+
stroke: "none"
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
function moveAngle(e, t, n = !0) {
|
|
991
|
+
let r = Math.atan2(t[1] - e[1], t[0] - e[0]) + Math.PI;
|
|
992
|
+
return n ? (Math.round(r * 8 / Math.PI) + 16) % 16 : r;
|
|
993
|
+
}
|
|
994
|
+
function dist(e, t) {
|
|
995
|
+
return Math.sqrt([e[0] - t[0], e[1] - t[1]].reduce((e, t) => e + t * t, 0));
|
|
996
|
+
}
|
|
997
|
+
function labelCoords(e, t, n) {
|
|
998
|
+
let r = dist(e, t), i = moveAngle(e, t, !1);
|
|
999
|
+
if (n && (r -= 33 / 64, n.size > 1)) {
|
|
1000
|
+
r -= 10 / 64;
|
|
1001
|
+
let i = moveAngle(e, t);
|
|
1002
|
+
(n.has((i + 1) % 16) || n.has((i + 15) % 16)) && i & 1 && (r -= .4);
|
|
1003
|
+
}
|
|
1004
|
+
return [e[0] - Math.cos(i) * r, e[1] - Math.sin(i) * r].map((e) => e + .5);
|
|
1005
|
+
}
|
|
1006
|
+
//#endregion
|
|
1007
|
+
//#region src/chess/chessground/wrap.ts
|
|
1008
|
+
function renderWrap(e, t) {
|
|
1009
|
+
e.innerHTML = "", e.classList.add("cg-wrap");
|
|
1010
|
+
for (let n of S) e.classList.toggle("orientation-" + n, t.orientation === n);
|
|
1011
|
+
e.classList.toggle("manipulable", !t.viewOnly);
|
|
1012
|
+
let n = createEl("cg-container");
|
|
1013
|
+
e.appendChild(n);
|
|
1014
|
+
let r = createEl("cg-board");
|
|
1015
|
+
n.appendChild(r);
|
|
1016
|
+
let i, a, o;
|
|
1017
|
+
if (t.drawable.visible && (i = setAttributes(createElement("svg"), {
|
|
1018
|
+
class: "cg-shapes",
|
|
1019
|
+
viewBox: "-4 -4 8 8",
|
|
1020
|
+
preserveAspectRatio: "xMidYMid slice"
|
|
1021
|
+
}), i.appendChild(createDefs()), i.appendChild(createElement("g")), a = setAttributes(createElement("svg"), {
|
|
1022
|
+
class: "cg-custom-svgs",
|
|
1023
|
+
viewBox: "-3.5 -3.5 8 8",
|
|
1024
|
+
preserveAspectRatio: "xMidYMid slice"
|
|
1025
|
+
}), a.appendChild(createElement("g")), o = createEl("cg-auto-pieces"), n.appendChild(i), n.appendChild(a), n.appendChild(o)), t.coordinates) {
|
|
1026
|
+
let e = t.orientation === "cg-black" ? " black" : "", r = t.ranksPosition === "left" ? " left" : "";
|
|
1027
|
+
if (t.coordinatesOnSquares) {
|
|
1028
|
+
let i = t.orientation === "cg-white" ? (e) => e + 1 : (e) => 8 - e;
|
|
1029
|
+
C.forEach((t, a) => n.appendChild(renderCoords(w.map((e) => t + e), "squares rank" + i(a) + e + r)));
|
|
1030
|
+
} else n.appendChild(renderCoords(w, "ranks" + e + r)), n.appendChild(renderCoords(C, "files" + e));
|
|
1031
|
+
}
|
|
1032
|
+
let s;
|
|
1033
|
+
return t.draggable.enabled && t.draggable.showGhost && (s = createEl("piece", "ghost"), setVisible(s, !1), n.appendChild(s)), {
|
|
1034
|
+
board: r,
|
|
1035
|
+
container: n,
|
|
1036
|
+
wrap: e,
|
|
1037
|
+
ghost: s,
|
|
1038
|
+
svg: i,
|
|
1039
|
+
customSvg: a,
|
|
1040
|
+
autoPieces: o
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
function renderCoords(e, t) {
|
|
1044
|
+
let n = createEl("coords", t), r;
|
|
1045
|
+
for (let t of e) r = createEl("coord"), r.textContent = t, n.appendChild(r);
|
|
1046
|
+
return n;
|
|
1047
|
+
}
|
|
1048
|
+
//#endregion
|
|
1049
|
+
//#region src/chess/chessground/drop.ts
|
|
1050
|
+
function drop(e, t) {
|
|
1051
|
+
if (!e.dropmode.active) return;
|
|
1052
|
+
unsetPremove(e), unsetPredrop(e);
|
|
1053
|
+
let n = e.dropmode.piece;
|
|
1054
|
+
if (n) {
|
|
1055
|
+
e.pieces.set("a0", n);
|
|
1056
|
+
let r = eventPosition(t), i = r && getKeyAtDomPos(r, whitePov(e), e.dom.bounds());
|
|
1057
|
+
i && dropNewPiece(e, "a0", i);
|
|
1058
|
+
}
|
|
1059
|
+
e.dom.redraw();
|
|
1060
|
+
}
|
|
1061
|
+
//#endregion
|
|
1062
|
+
//#region src/chess/chessground/events.ts
|
|
1063
|
+
function bindBoard(e) {
|
|
1064
|
+
let t = e.dom.elements.board;
|
|
1065
|
+
if ((e.disableContextMenu || e.drawable.enabled) && t.addEventListener("contextmenu", (e) => e.preventDefault()), e.viewOnly) return;
|
|
1066
|
+
let n = startDragOrDraw(e);
|
|
1067
|
+
t.addEventListener("touchstart", n, { passive: !1 }), t.addEventListener("mousedown", n, { passive: !1 });
|
|
1068
|
+
}
|
|
1069
|
+
function bindDocument(e, t) {
|
|
1070
|
+
let n = [];
|
|
1071
|
+
if ("ResizeObserver" in window || n.push(unbindable(document.body, "chessground.resize", t)), !e.viewOnly) {
|
|
1072
|
+
let t = dragOrDraw(e, move, move$1), r = dragOrDraw(e, end, end$1);
|
|
1073
|
+
for (let e of ["touchmove", "mousemove"]) n.push(unbindable(document, e, t));
|
|
1074
|
+
for (let e of ["touchend", "mouseup"]) n.push(unbindable(document, e, r));
|
|
1075
|
+
let onScroll = () => e.dom.bounds.clear();
|
|
1076
|
+
n.push(unbindable(document, "scroll", onScroll, {
|
|
1077
|
+
capture: !0,
|
|
1078
|
+
passive: !0
|
|
1079
|
+
})), n.push(unbindable(window, "resize", onScroll, { passive: !0 }));
|
|
1080
|
+
}
|
|
1081
|
+
return () => n.forEach((e) => e());
|
|
1082
|
+
}
|
|
1083
|
+
function unbindable(e, t, n, r) {
|
|
1084
|
+
return e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r);
|
|
1085
|
+
}
|
|
1086
|
+
var startDragOrDraw = (e) => (t) => {
|
|
1087
|
+
e.draggable.current ? cancel(e) : e.drawable.current ? cancel$1(e) : t.shiftKey || isRightButton(t) ? e.drawable.enabled && start$2(e, t) : e.viewOnly || (e.dropmode.active ? drop(e, t) : start$1(e, t));
|
|
1088
|
+
}, dragOrDraw = (e, t, n) => (r) => {
|
|
1089
|
+
e.drawable.current ? e.drawable.enabled && n(e, r) : e.viewOnly || t(e, r);
|
|
1090
|
+
};
|
|
1091
|
+
//#endregion
|
|
1092
|
+
//#region src/chess/chessground/render.ts
|
|
1093
|
+
function render$1(e) {
|
|
1094
|
+
let t = whitePov(e), n = posToTranslate(e.dom.bounds()), r = e.dom.elements.board, i = e.pieces, a = e.animation.current, o = a ? a.plan.anims : /* @__PURE__ */ new Map(), s = a ? a.plan.fadings : /* @__PURE__ */ new Map(), c = e.draggable.current, l = computeSquareClasses(e), u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m, h, g, _, v, y, b, x, S, C;
|
|
1095
|
+
for (h = r.firstChild; h;) {
|
|
1096
|
+
if (m = h.cgKey, isPieceNode(h)) if (g = i.get(m), v = o.get(m), y = s.get(m), _ = h.cgPiece, h.cgDragging && (!c || c.orig !== m) && (h.classList.remove("dragging"), translate(h, n(key2pos(m), t)), h.cgDragging = !1), !y && h.cgFading && (h.cgFading = !1, h.classList.remove("fading")), g) {
|
|
1097
|
+
if (v && h.cgAnimating && _ === pieceNameOf(g)) {
|
|
1098
|
+
let e = key2pos(m);
|
|
1099
|
+
e[0] += v[2], e[1] += v[3], h.classList.add("anim"), translate(h, n(e, t));
|
|
1100
|
+
} else h.cgAnimating && (h.cgAnimating = !1, h.classList.remove("anim"), translate(h, n(key2pos(m), t)), e.addPieceZIndex && (h.style.zIndex = posZIndex(key2pos(m), t)));
|
|
1101
|
+
_ === pieceNameOf(g) && (!y || !h.cgFading) ? u.add(m) : y && _ === pieceNameOf(y) ? (h.classList.add("fading"), h.cgFading = !0) : appendValue(f, _, h);
|
|
1102
|
+
} else appendValue(f, _, h);
|
|
1103
|
+
else if (isSquareNode(h)) {
|
|
1104
|
+
let e = h.className;
|
|
1105
|
+
l.get(m) === e ? d.add(m) : appendValue(p, e, h);
|
|
1106
|
+
}
|
|
1107
|
+
h = h.nextSibling;
|
|
1108
|
+
}
|
|
1109
|
+
for (let [e, i] of l) if (!d.has(e)) {
|
|
1110
|
+
S = p.get(i), C = S && S.pop();
|
|
1111
|
+
let a = n(key2pos(e), t);
|
|
1112
|
+
if (C) C.cgKey = e, translate(C, a);
|
|
1113
|
+
else {
|
|
1114
|
+
let t = createEl("square", i);
|
|
1115
|
+
t.cgKey = e, translate(t, a), r.insertBefore(t, r.firstChild);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
for (let [a, s] of i) if (v = o.get(a), !u.has(a)) if (b = f.get(pieceNameOf(s)), x = b && b.pop(), x) {
|
|
1119
|
+
x.cgKey = a, x.cgFading && (x.classList.remove("fading"), x.cgFading = !1);
|
|
1120
|
+
let r = key2pos(a);
|
|
1121
|
+
e.addPieceZIndex && (x.style.zIndex = posZIndex(r, t)), v && (x.cgAnimating = !0, x.classList.add("anim"), r[0] += v[2], r[1] += v[3]), translate(x, n(r, t));
|
|
1122
|
+
} else {
|
|
1123
|
+
let i = pieceNameOf(s), o = createEl("piece", i), c = key2pos(a);
|
|
1124
|
+
o.cgPiece = i, o.cgKey = a, v && (o.cgAnimating = !0, c[0] += v[2], c[1] += v[3]), translate(o, n(c, t)), e.addPieceZIndex && (o.style.zIndex = posZIndex(c, t)), r.appendChild(o);
|
|
1125
|
+
}
|
|
1126
|
+
for (let t of f.values()) removeNodes(e, t);
|
|
1127
|
+
for (let t of p.values()) removeNodes(e, t);
|
|
1128
|
+
}
|
|
1129
|
+
e(render$1, "render");
|
|
1130
|
+
function renderResized$1(e) {
|
|
1131
|
+
let t = whitePov(e), n = posToTranslate(e.dom.bounds()), r = e.dom.elements.board.firstChild;
|
|
1132
|
+
for (; r;) (isPieceNode(r) && !r.cgAnimating || isSquareNode(r)) && translate(r, n(key2pos(r.cgKey), t)), r = r.nextSibling;
|
|
1133
|
+
}
|
|
1134
|
+
e(renderResized$1, "renderResized");
|
|
1135
|
+
function updateBounds(e) {
|
|
1136
|
+
let t = e.dom.elements.wrap.getBoundingClientRect(), n = e.dom.elements.container, r = t.height / t.width, i = Math.floor(t.width * window.devicePixelRatio / 8) * 8 / window.devicePixelRatio, a = i * r;
|
|
1137
|
+
n.style.width = i + "px", n.style.height = a + "px", e.dom.bounds.clear(), e.addDimensionsCssVarsTo?.style.setProperty("---cg-width", i + "px"), e.addDimensionsCssVarsTo?.style.setProperty("---cg-height", a + "px");
|
|
1138
|
+
}
|
|
1139
|
+
var isPieceNode = (e) => e.tagName === "PIECE", isSquareNode = (e) => e.tagName === "SQUARE";
|
|
1140
|
+
function removeNodes(e, t) {
|
|
1141
|
+
for (let n of t) e.dom.elements.board.removeChild(n);
|
|
1142
|
+
}
|
|
1143
|
+
function posZIndex(e, t) {
|
|
1144
|
+
let n = e[1];
|
|
1145
|
+
return `${t ? 10 - n : 3 + n}`;
|
|
1146
|
+
}
|
|
1147
|
+
var pieceNameOf = (e) => `${e.color} ${e.role}`;
|
|
1148
|
+
function computeSquareClasses(e) {
|
|
1149
|
+
let t = /* @__PURE__ */ new Map();
|
|
1150
|
+
if (e.lastMove && e.highlight.lastMove) for (let n of e.lastMove) addSquare(t, n, "last-move");
|
|
1151
|
+
if (e.check && e.highlight.check && addSquare(t, e.check, "check"), e.selected && (addSquare(t, e.selected, "selected"), e.movable.showDests)) {
|
|
1152
|
+
let n = e.movable.dests?.get(e.selected);
|
|
1153
|
+
if (n) for (let r of n) addSquare(t, r, "move-dest" + (e.pieces.has(r) ? " oc" : ""));
|
|
1154
|
+
let r = e.premovable.customDests?.get(e.selected) ?? e.premovable.dests;
|
|
1155
|
+
if (r) for (let n of r) addSquare(t, n, "premove-dest" + (e.pieces.has(n) ? " oc" : ""));
|
|
1156
|
+
}
|
|
1157
|
+
let n = e.premovable.current;
|
|
1158
|
+
if (n) for (let e of n) addSquare(t, e, "current-premove");
|
|
1159
|
+
else e.predroppable.current && addSquare(t, e.predroppable.current.key, "current-premove");
|
|
1160
|
+
let r = e.exploding;
|
|
1161
|
+
if (r) for (let e of r.keys) addSquare(t, e, "exploding" + r.stage);
|
|
1162
|
+
return e.highlight.custom && e.highlight.custom.forEach((e, n) => {
|
|
1163
|
+
addSquare(t, n, e);
|
|
1164
|
+
}), t;
|
|
1165
|
+
}
|
|
1166
|
+
function addSquare(e, t, n) {
|
|
1167
|
+
let r = e.get(t);
|
|
1168
|
+
r ? e.set(t, `${r} ${n}`) : e.set(t, n);
|
|
1169
|
+
}
|
|
1170
|
+
function appendValue(e, t, n) {
|
|
1171
|
+
let r = e.get(t);
|
|
1172
|
+
r ? r.push(n) : e.set(t, [n]);
|
|
1173
|
+
}
|
|
1174
|
+
//#endregion
|
|
1175
|
+
//#region src/chess/chessground/sync.ts
|
|
1176
|
+
function syncShapes(e, t, n) {
|
|
1177
|
+
let r = /* @__PURE__ */ new Map(), i = [];
|
|
1178
|
+
for (let t of e) r.set(t.hash, !1);
|
|
1179
|
+
let a = t.firstElementChild, o;
|
|
1180
|
+
for (; a;) o = a.getAttribute("cgHash"), r.has(o) ? r.set(o, !0) : i.push(a), a = a.nextElementSibling;
|
|
1181
|
+
for (let e of i) t.removeChild(e);
|
|
1182
|
+
for (let i of e) r.get(i.hash) || t.appendChild(n(i));
|
|
1183
|
+
}
|
|
1184
|
+
//#endregion
|
|
1185
|
+
//#region src/chess/chessground/autoPieces.ts
|
|
1186
|
+
function render(e, t) {
|
|
1187
|
+
syncShapes(e.drawable.autoShapes.filter((e) => e.piece).map((e) => ({
|
|
1188
|
+
shape: e,
|
|
1189
|
+
hash: hash(e),
|
|
1190
|
+
current: !1
|
|
1191
|
+
})), t, (t) => renderShape(e, t, e.dom.bounds()));
|
|
1192
|
+
}
|
|
1193
|
+
function renderResized(e) {
|
|
1194
|
+
let t = whitePov(e), n = posToTranslate(e.dom.bounds()), r = e.dom.elements.autoPieces?.firstChild;
|
|
1195
|
+
for (; r;) translateAndScale(r, n(key2pos(r.cgKey), t), r.cgScale), r = r.nextSibling;
|
|
1196
|
+
}
|
|
1197
|
+
function renderShape(e, { shape: t, hash: n }, r) {
|
|
1198
|
+
let i = t.orig, a = t.piece?.role, o = t.piece?.color, s = t.piece?.scale, c = createEl("piece", `${a} ${o}`);
|
|
1199
|
+
return c.setAttribute("cgHash", n), c.cgKey = i, c.cgScale = s, translateAndScale(c, posToTranslate(r)(key2pos(i), whitePov(e)), s), c;
|
|
1200
|
+
}
|
|
1201
|
+
var hash = (e) => [
|
|
1202
|
+
e.orig,
|
|
1203
|
+
e.piece?.role,
|
|
1204
|
+
e.piece?.color,
|
|
1205
|
+
e.piece?.scale
|
|
1206
|
+
].join(",");
|
|
1207
|
+
//#endregion
|
|
1208
|
+
//#region src/chess/chessground/chessground.ts
|
|
1209
|
+
function Chessground(e, t) {
|
|
1210
|
+
let n = defaults();
|
|
1211
|
+
configure(n, t || {});
|
|
1212
|
+
function redrawAll() {
|
|
1213
|
+
let t = "dom" in n ? n.dom.unbind : void 0, r = renderWrap(e, n), i = memo(() => r.board.getBoundingClientRect()), redrawNow = (e) => {
|
|
1214
|
+
render$1(a), r.autoPieces && render(a, r.autoPieces), !e && r.svg && renderSvg(a, r.svg, r.customSvg);
|
|
1215
|
+
}, onResize = () => {
|
|
1216
|
+
updateBounds(a), renderResized$1(a), r.autoPieces && renderResized(a);
|
|
1217
|
+
}, a = n;
|
|
1218
|
+
return a.dom = {
|
|
1219
|
+
elements: r,
|
|
1220
|
+
bounds: i,
|
|
1221
|
+
redraw: debounceRedraw(redrawNow),
|
|
1222
|
+
redrawNow,
|
|
1223
|
+
unbind: t
|
|
1224
|
+
}, a.drawable.prevSvgHash = "", updateBounds(a), redrawNow(!1), bindBoard(a), t || (a.dom.unbind = bindDocument(a, onResize)), a.events.insert?.(r), a;
|
|
1225
|
+
}
|
|
1226
|
+
return start(redrawAll(), redrawAll);
|
|
1227
|
+
}
|
|
1228
|
+
function debounceRedraw(e) {
|
|
1229
|
+
let t = !1;
|
|
1230
|
+
return () => {
|
|
1231
|
+
t || (t = !0, requestAnimationFrame(() => {
|
|
1232
|
+
e(), t = !1;
|
|
1233
|
+
}));
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
var N = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", Move = class {
|
|
1237
|
+
color;
|
|
1238
|
+
from;
|
|
1239
|
+
to;
|
|
1240
|
+
piece;
|
|
1241
|
+
captured;
|
|
1242
|
+
promotion;
|
|
1243
|
+
flags;
|
|
1244
|
+
san;
|
|
1245
|
+
lan;
|
|
1246
|
+
before;
|
|
1247
|
+
after;
|
|
1248
|
+
constructor(e, t) {
|
|
1249
|
+
let { color: n, piece: r, from: i, to: a, flags: o, captured: s, promotion: c } = t, l = algebraic(i), u = algebraic(a);
|
|
1250
|
+
this.color = n, this.piece = r, this.from = l, this.to = u, this.san = e._moveToSan(t, e._moves({ legal: !0 })), this.lan = l + u, this.before = e.fen(), e._makeMove(t), this.after = e.fen(), e._undoMove(), this.flags = "";
|
|
1251
|
+
for (let e in L) L[e] & o && (this.flags += F[e]);
|
|
1252
|
+
s && (this.captured = s), c && (this.promotion = c, this.lan += c);
|
|
1253
|
+
}
|
|
1254
|
+
isCapture() {
|
|
1255
|
+
return this.flags.indexOf(F.CAPTURE) > -1;
|
|
1256
|
+
}
|
|
1257
|
+
isPromotion() {
|
|
1258
|
+
return this.flags.indexOf(F.PROMOTION) > -1;
|
|
1259
|
+
}
|
|
1260
|
+
isEnPassant() {
|
|
1261
|
+
return this.flags.indexOf(F.EP_CAPTURE) > -1;
|
|
1262
|
+
}
|
|
1263
|
+
isKingsideCastle() {
|
|
1264
|
+
return this.flags.indexOf(F.KSIDE_CASTLE) > -1;
|
|
1265
|
+
}
|
|
1266
|
+
isQueensideCastle() {
|
|
1267
|
+
return this.flags.indexOf(F.QSIDE_CASTLE) > -1;
|
|
1268
|
+
}
|
|
1269
|
+
isBigPawn() {
|
|
1270
|
+
return this.flags.indexOf(F.BIG_PAWN) > -1;
|
|
1271
|
+
}
|
|
1272
|
+
}, P = -1, F = {
|
|
1273
|
+
NORMAL: "n",
|
|
1274
|
+
CAPTURE: "c",
|
|
1275
|
+
BIG_PAWN: "b",
|
|
1276
|
+
EP_CAPTURE: "e",
|
|
1277
|
+
PROMOTION: "p",
|
|
1278
|
+
KSIDE_CASTLE: "k",
|
|
1279
|
+
QSIDE_CASTLE: "q"
|
|
1280
|
+
}, I = /* @__PURE__ */ "a8.b8.c8.d8.e8.f8.g8.h8.a7.b7.c7.d7.e7.f7.g7.h7.a6.b6.c6.d6.e6.f6.g6.h6.a5.b5.c5.d5.e5.f5.g5.h5.a4.b4.c4.d4.e4.f4.g4.h4.a3.b3.c3.d3.e3.f3.g3.h3.a2.b2.c2.d2.e2.f2.g2.h2.a1.b1.c1.d1.e1.f1.g1.h1".split("."), L = {
|
|
1281
|
+
NORMAL: 1,
|
|
1282
|
+
CAPTURE: 2,
|
|
1283
|
+
BIG_PAWN: 4,
|
|
1284
|
+
EP_CAPTURE: 8,
|
|
1285
|
+
PROMOTION: 16,
|
|
1286
|
+
KSIDE_CASTLE: 32,
|
|
1287
|
+
QSIDE_CASTLE: 64
|
|
1288
|
+
}, R = {
|
|
1289
|
+
a8: 0,
|
|
1290
|
+
b8: 1,
|
|
1291
|
+
c8: 2,
|
|
1292
|
+
d8: 3,
|
|
1293
|
+
e8: 4,
|
|
1294
|
+
f8: 5,
|
|
1295
|
+
g8: 6,
|
|
1296
|
+
h8: 7,
|
|
1297
|
+
a7: 16,
|
|
1298
|
+
b7: 17,
|
|
1299
|
+
c7: 18,
|
|
1300
|
+
d7: 19,
|
|
1301
|
+
e7: 20,
|
|
1302
|
+
f7: 21,
|
|
1303
|
+
g7: 22,
|
|
1304
|
+
h7: 23,
|
|
1305
|
+
a6: 32,
|
|
1306
|
+
b6: 33,
|
|
1307
|
+
c6: 34,
|
|
1308
|
+
d6: 35,
|
|
1309
|
+
e6: 36,
|
|
1310
|
+
f6: 37,
|
|
1311
|
+
g6: 38,
|
|
1312
|
+
h6: 39,
|
|
1313
|
+
a5: 48,
|
|
1314
|
+
b5: 49,
|
|
1315
|
+
c5: 50,
|
|
1316
|
+
d5: 51,
|
|
1317
|
+
e5: 52,
|
|
1318
|
+
f5: 53,
|
|
1319
|
+
g5: 54,
|
|
1320
|
+
h5: 55,
|
|
1321
|
+
a4: 64,
|
|
1322
|
+
b4: 65,
|
|
1323
|
+
c4: 66,
|
|
1324
|
+
d4: 67,
|
|
1325
|
+
e4: 68,
|
|
1326
|
+
f4: 69,
|
|
1327
|
+
g4: 70,
|
|
1328
|
+
h4: 71,
|
|
1329
|
+
a3: 80,
|
|
1330
|
+
b3: 81,
|
|
1331
|
+
c3: 82,
|
|
1332
|
+
d3: 83,
|
|
1333
|
+
e3: 84,
|
|
1334
|
+
f3: 85,
|
|
1335
|
+
g3: 86,
|
|
1336
|
+
h3: 87,
|
|
1337
|
+
a2: 96,
|
|
1338
|
+
b2: 97,
|
|
1339
|
+
c2: 98,
|
|
1340
|
+
d2: 99,
|
|
1341
|
+
e2: 100,
|
|
1342
|
+
f2: 101,
|
|
1343
|
+
g2: 102,
|
|
1344
|
+
h2: 103,
|
|
1345
|
+
a1: 112,
|
|
1346
|
+
b1: 113,
|
|
1347
|
+
c1: 114,
|
|
1348
|
+
d1: 115,
|
|
1349
|
+
e1: 116,
|
|
1350
|
+
f1: 117,
|
|
1351
|
+
g1: 118,
|
|
1352
|
+
h1: 119
|
|
1353
|
+
}, z = {
|
|
1354
|
+
b: [
|
|
1355
|
+
16,
|
|
1356
|
+
32,
|
|
1357
|
+
17,
|
|
1358
|
+
15
|
|
1359
|
+
],
|
|
1360
|
+
w: [
|
|
1361
|
+
-16,
|
|
1362
|
+
-32,
|
|
1363
|
+
-17,
|
|
1364
|
+
-15
|
|
1365
|
+
]
|
|
1366
|
+
}, B = {
|
|
1367
|
+
n: [
|
|
1368
|
+
-18,
|
|
1369
|
+
-33,
|
|
1370
|
+
-31,
|
|
1371
|
+
-14,
|
|
1372
|
+
18,
|
|
1373
|
+
33,
|
|
1374
|
+
31,
|
|
1375
|
+
14
|
|
1376
|
+
],
|
|
1377
|
+
b: [
|
|
1378
|
+
-17,
|
|
1379
|
+
-15,
|
|
1380
|
+
17,
|
|
1381
|
+
15
|
|
1382
|
+
],
|
|
1383
|
+
r: [
|
|
1384
|
+
-16,
|
|
1385
|
+
1,
|
|
1386
|
+
16,
|
|
1387
|
+
-1
|
|
1388
|
+
],
|
|
1389
|
+
q: [
|
|
1390
|
+
-17,
|
|
1391
|
+
-16,
|
|
1392
|
+
-15,
|
|
1393
|
+
1,
|
|
1394
|
+
17,
|
|
1395
|
+
16,
|
|
1396
|
+
15,
|
|
1397
|
+
-1
|
|
1398
|
+
],
|
|
1399
|
+
k: [
|
|
1400
|
+
-17,
|
|
1401
|
+
-16,
|
|
1402
|
+
-15,
|
|
1403
|
+
1,
|
|
1404
|
+
17,
|
|
1405
|
+
16,
|
|
1406
|
+
15,
|
|
1407
|
+
-1
|
|
1408
|
+
]
|
|
1409
|
+
}, V = [
|
|
1410
|
+
20,
|
|
1411
|
+
0,
|
|
1412
|
+
0,
|
|
1413
|
+
0,
|
|
1414
|
+
0,
|
|
1415
|
+
0,
|
|
1416
|
+
0,
|
|
1417
|
+
24,
|
|
1418
|
+
0,
|
|
1419
|
+
0,
|
|
1420
|
+
0,
|
|
1421
|
+
0,
|
|
1422
|
+
0,
|
|
1423
|
+
0,
|
|
1424
|
+
20,
|
|
1425
|
+
0,
|
|
1426
|
+
0,
|
|
1427
|
+
20,
|
|
1428
|
+
0,
|
|
1429
|
+
0,
|
|
1430
|
+
0,
|
|
1431
|
+
0,
|
|
1432
|
+
0,
|
|
1433
|
+
24,
|
|
1434
|
+
0,
|
|
1435
|
+
0,
|
|
1436
|
+
0,
|
|
1437
|
+
0,
|
|
1438
|
+
0,
|
|
1439
|
+
20,
|
|
1440
|
+
0,
|
|
1441
|
+
0,
|
|
1442
|
+
0,
|
|
1443
|
+
0,
|
|
1444
|
+
20,
|
|
1445
|
+
0,
|
|
1446
|
+
0,
|
|
1447
|
+
0,
|
|
1448
|
+
0,
|
|
1449
|
+
24,
|
|
1450
|
+
0,
|
|
1451
|
+
0,
|
|
1452
|
+
0,
|
|
1453
|
+
0,
|
|
1454
|
+
20,
|
|
1455
|
+
0,
|
|
1456
|
+
0,
|
|
1457
|
+
0,
|
|
1458
|
+
0,
|
|
1459
|
+
0,
|
|
1460
|
+
0,
|
|
1461
|
+
20,
|
|
1462
|
+
0,
|
|
1463
|
+
0,
|
|
1464
|
+
0,
|
|
1465
|
+
24,
|
|
1466
|
+
0,
|
|
1467
|
+
0,
|
|
1468
|
+
0,
|
|
1469
|
+
20,
|
|
1470
|
+
0,
|
|
1471
|
+
0,
|
|
1472
|
+
0,
|
|
1473
|
+
0,
|
|
1474
|
+
0,
|
|
1475
|
+
0,
|
|
1476
|
+
0,
|
|
1477
|
+
0,
|
|
1478
|
+
20,
|
|
1479
|
+
0,
|
|
1480
|
+
0,
|
|
1481
|
+
24,
|
|
1482
|
+
0,
|
|
1483
|
+
0,
|
|
1484
|
+
20,
|
|
1485
|
+
0,
|
|
1486
|
+
0,
|
|
1487
|
+
0,
|
|
1488
|
+
0,
|
|
1489
|
+
0,
|
|
1490
|
+
0,
|
|
1491
|
+
0,
|
|
1492
|
+
0,
|
|
1493
|
+
0,
|
|
1494
|
+
0,
|
|
1495
|
+
20,
|
|
1496
|
+
2,
|
|
1497
|
+
24,
|
|
1498
|
+
2,
|
|
1499
|
+
20,
|
|
1500
|
+
0,
|
|
1501
|
+
0,
|
|
1502
|
+
0,
|
|
1503
|
+
0,
|
|
1504
|
+
0,
|
|
1505
|
+
0,
|
|
1506
|
+
0,
|
|
1507
|
+
0,
|
|
1508
|
+
0,
|
|
1509
|
+
0,
|
|
1510
|
+
0,
|
|
1511
|
+
2,
|
|
1512
|
+
53,
|
|
1513
|
+
56,
|
|
1514
|
+
53,
|
|
1515
|
+
2,
|
|
1516
|
+
0,
|
|
1517
|
+
0,
|
|
1518
|
+
0,
|
|
1519
|
+
0,
|
|
1520
|
+
0,
|
|
1521
|
+
0,
|
|
1522
|
+
24,
|
|
1523
|
+
24,
|
|
1524
|
+
24,
|
|
1525
|
+
24,
|
|
1526
|
+
24,
|
|
1527
|
+
24,
|
|
1528
|
+
56,
|
|
1529
|
+
0,
|
|
1530
|
+
56,
|
|
1531
|
+
24,
|
|
1532
|
+
24,
|
|
1533
|
+
24,
|
|
1534
|
+
24,
|
|
1535
|
+
24,
|
|
1536
|
+
24,
|
|
1537
|
+
0,
|
|
1538
|
+
0,
|
|
1539
|
+
0,
|
|
1540
|
+
0,
|
|
1541
|
+
0,
|
|
1542
|
+
0,
|
|
1543
|
+
2,
|
|
1544
|
+
53,
|
|
1545
|
+
56,
|
|
1546
|
+
53,
|
|
1547
|
+
2,
|
|
1548
|
+
0,
|
|
1549
|
+
0,
|
|
1550
|
+
0,
|
|
1551
|
+
0,
|
|
1552
|
+
0,
|
|
1553
|
+
0,
|
|
1554
|
+
0,
|
|
1555
|
+
0,
|
|
1556
|
+
0,
|
|
1557
|
+
0,
|
|
1558
|
+
0,
|
|
1559
|
+
20,
|
|
1560
|
+
2,
|
|
1561
|
+
24,
|
|
1562
|
+
2,
|
|
1563
|
+
20,
|
|
1564
|
+
0,
|
|
1565
|
+
0,
|
|
1566
|
+
0,
|
|
1567
|
+
0,
|
|
1568
|
+
0,
|
|
1569
|
+
0,
|
|
1570
|
+
0,
|
|
1571
|
+
0,
|
|
1572
|
+
0,
|
|
1573
|
+
0,
|
|
1574
|
+
20,
|
|
1575
|
+
0,
|
|
1576
|
+
0,
|
|
1577
|
+
24,
|
|
1578
|
+
0,
|
|
1579
|
+
0,
|
|
1580
|
+
20,
|
|
1581
|
+
0,
|
|
1582
|
+
0,
|
|
1583
|
+
0,
|
|
1584
|
+
0,
|
|
1585
|
+
0,
|
|
1586
|
+
0,
|
|
1587
|
+
0,
|
|
1588
|
+
0,
|
|
1589
|
+
20,
|
|
1590
|
+
0,
|
|
1591
|
+
0,
|
|
1592
|
+
0,
|
|
1593
|
+
24,
|
|
1594
|
+
0,
|
|
1595
|
+
0,
|
|
1596
|
+
0,
|
|
1597
|
+
20,
|
|
1598
|
+
0,
|
|
1599
|
+
0,
|
|
1600
|
+
0,
|
|
1601
|
+
0,
|
|
1602
|
+
0,
|
|
1603
|
+
0,
|
|
1604
|
+
20,
|
|
1605
|
+
0,
|
|
1606
|
+
0,
|
|
1607
|
+
0,
|
|
1608
|
+
0,
|
|
1609
|
+
24,
|
|
1610
|
+
0,
|
|
1611
|
+
0,
|
|
1612
|
+
0,
|
|
1613
|
+
0,
|
|
1614
|
+
20,
|
|
1615
|
+
0,
|
|
1616
|
+
0,
|
|
1617
|
+
0,
|
|
1618
|
+
0,
|
|
1619
|
+
20,
|
|
1620
|
+
0,
|
|
1621
|
+
0,
|
|
1622
|
+
0,
|
|
1623
|
+
0,
|
|
1624
|
+
0,
|
|
1625
|
+
24,
|
|
1626
|
+
0,
|
|
1627
|
+
0,
|
|
1628
|
+
0,
|
|
1629
|
+
0,
|
|
1630
|
+
0,
|
|
1631
|
+
20,
|
|
1632
|
+
0,
|
|
1633
|
+
0,
|
|
1634
|
+
20,
|
|
1635
|
+
0,
|
|
1636
|
+
0,
|
|
1637
|
+
0,
|
|
1638
|
+
0,
|
|
1639
|
+
0,
|
|
1640
|
+
0,
|
|
1641
|
+
24,
|
|
1642
|
+
0,
|
|
1643
|
+
0,
|
|
1644
|
+
0,
|
|
1645
|
+
0,
|
|
1646
|
+
0,
|
|
1647
|
+
0,
|
|
1648
|
+
20
|
|
1649
|
+
], H = [
|
|
1650
|
+
17,
|
|
1651
|
+
0,
|
|
1652
|
+
0,
|
|
1653
|
+
0,
|
|
1654
|
+
0,
|
|
1655
|
+
0,
|
|
1656
|
+
0,
|
|
1657
|
+
16,
|
|
1658
|
+
0,
|
|
1659
|
+
0,
|
|
1660
|
+
0,
|
|
1661
|
+
0,
|
|
1662
|
+
0,
|
|
1663
|
+
0,
|
|
1664
|
+
15,
|
|
1665
|
+
0,
|
|
1666
|
+
0,
|
|
1667
|
+
17,
|
|
1668
|
+
0,
|
|
1669
|
+
0,
|
|
1670
|
+
0,
|
|
1671
|
+
0,
|
|
1672
|
+
0,
|
|
1673
|
+
16,
|
|
1674
|
+
0,
|
|
1675
|
+
0,
|
|
1676
|
+
0,
|
|
1677
|
+
0,
|
|
1678
|
+
0,
|
|
1679
|
+
15,
|
|
1680
|
+
0,
|
|
1681
|
+
0,
|
|
1682
|
+
0,
|
|
1683
|
+
0,
|
|
1684
|
+
17,
|
|
1685
|
+
0,
|
|
1686
|
+
0,
|
|
1687
|
+
0,
|
|
1688
|
+
0,
|
|
1689
|
+
16,
|
|
1690
|
+
0,
|
|
1691
|
+
0,
|
|
1692
|
+
0,
|
|
1693
|
+
0,
|
|
1694
|
+
15,
|
|
1695
|
+
0,
|
|
1696
|
+
0,
|
|
1697
|
+
0,
|
|
1698
|
+
0,
|
|
1699
|
+
0,
|
|
1700
|
+
0,
|
|
1701
|
+
17,
|
|
1702
|
+
0,
|
|
1703
|
+
0,
|
|
1704
|
+
0,
|
|
1705
|
+
16,
|
|
1706
|
+
0,
|
|
1707
|
+
0,
|
|
1708
|
+
0,
|
|
1709
|
+
15,
|
|
1710
|
+
0,
|
|
1711
|
+
0,
|
|
1712
|
+
0,
|
|
1713
|
+
0,
|
|
1714
|
+
0,
|
|
1715
|
+
0,
|
|
1716
|
+
0,
|
|
1717
|
+
0,
|
|
1718
|
+
17,
|
|
1719
|
+
0,
|
|
1720
|
+
0,
|
|
1721
|
+
16,
|
|
1722
|
+
0,
|
|
1723
|
+
0,
|
|
1724
|
+
15,
|
|
1725
|
+
0,
|
|
1726
|
+
0,
|
|
1727
|
+
0,
|
|
1728
|
+
0,
|
|
1729
|
+
0,
|
|
1730
|
+
0,
|
|
1731
|
+
0,
|
|
1732
|
+
0,
|
|
1733
|
+
0,
|
|
1734
|
+
0,
|
|
1735
|
+
17,
|
|
1736
|
+
0,
|
|
1737
|
+
16,
|
|
1738
|
+
0,
|
|
1739
|
+
15,
|
|
1740
|
+
0,
|
|
1741
|
+
0,
|
|
1742
|
+
0,
|
|
1743
|
+
0,
|
|
1744
|
+
0,
|
|
1745
|
+
0,
|
|
1746
|
+
0,
|
|
1747
|
+
0,
|
|
1748
|
+
0,
|
|
1749
|
+
0,
|
|
1750
|
+
0,
|
|
1751
|
+
0,
|
|
1752
|
+
17,
|
|
1753
|
+
16,
|
|
1754
|
+
15,
|
|
1755
|
+
0,
|
|
1756
|
+
0,
|
|
1757
|
+
0,
|
|
1758
|
+
0,
|
|
1759
|
+
0,
|
|
1760
|
+
0,
|
|
1761
|
+
0,
|
|
1762
|
+
1,
|
|
1763
|
+
1,
|
|
1764
|
+
1,
|
|
1765
|
+
1,
|
|
1766
|
+
1,
|
|
1767
|
+
1,
|
|
1768
|
+
1,
|
|
1769
|
+
0,
|
|
1770
|
+
-1,
|
|
1771
|
+
-1,
|
|
1772
|
+
-1,
|
|
1773
|
+
-1,
|
|
1774
|
+
-1,
|
|
1775
|
+
-1,
|
|
1776
|
+
-1,
|
|
1777
|
+
0,
|
|
1778
|
+
0,
|
|
1779
|
+
0,
|
|
1780
|
+
0,
|
|
1781
|
+
0,
|
|
1782
|
+
0,
|
|
1783
|
+
0,
|
|
1784
|
+
-15,
|
|
1785
|
+
-16,
|
|
1786
|
+
-17,
|
|
1787
|
+
0,
|
|
1788
|
+
0,
|
|
1789
|
+
0,
|
|
1790
|
+
0,
|
|
1791
|
+
0,
|
|
1792
|
+
0,
|
|
1793
|
+
0,
|
|
1794
|
+
0,
|
|
1795
|
+
0,
|
|
1796
|
+
0,
|
|
1797
|
+
0,
|
|
1798
|
+
0,
|
|
1799
|
+
-15,
|
|
1800
|
+
0,
|
|
1801
|
+
-16,
|
|
1802
|
+
0,
|
|
1803
|
+
-17,
|
|
1804
|
+
0,
|
|
1805
|
+
0,
|
|
1806
|
+
0,
|
|
1807
|
+
0,
|
|
1808
|
+
0,
|
|
1809
|
+
0,
|
|
1810
|
+
0,
|
|
1811
|
+
0,
|
|
1812
|
+
0,
|
|
1813
|
+
0,
|
|
1814
|
+
-15,
|
|
1815
|
+
0,
|
|
1816
|
+
0,
|
|
1817
|
+
-16,
|
|
1818
|
+
0,
|
|
1819
|
+
0,
|
|
1820
|
+
-17,
|
|
1821
|
+
0,
|
|
1822
|
+
0,
|
|
1823
|
+
0,
|
|
1824
|
+
0,
|
|
1825
|
+
0,
|
|
1826
|
+
0,
|
|
1827
|
+
0,
|
|
1828
|
+
0,
|
|
1829
|
+
-15,
|
|
1830
|
+
0,
|
|
1831
|
+
0,
|
|
1832
|
+
0,
|
|
1833
|
+
-16,
|
|
1834
|
+
0,
|
|
1835
|
+
0,
|
|
1836
|
+
0,
|
|
1837
|
+
-17,
|
|
1838
|
+
0,
|
|
1839
|
+
0,
|
|
1840
|
+
0,
|
|
1841
|
+
0,
|
|
1842
|
+
0,
|
|
1843
|
+
0,
|
|
1844
|
+
-15,
|
|
1845
|
+
0,
|
|
1846
|
+
0,
|
|
1847
|
+
0,
|
|
1848
|
+
0,
|
|
1849
|
+
-16,
|
|
1850
|
+
0,
|
|
1851
|
+
0,
|
|
1852
|
+
0,
|
|
1853
|
+
0,
|
|
1854
|
+
-17,
|
|
1855
|
+
0,
|
|
1856
|
+
0,
|
|
1857
|
+
0,
|
|
1858
|
+
0,
|
|
1859
|
+
-15,
|
|
1860
|
+
0,
|
|
1861
|
+
0,
|
|
1862
|
+
0,
|
|
1863
|
+
0,
|
|
1864
|
+
0,
|
|
1865
|
+
-16,
|
|
1866
|
+
0,
|
|
1867
|
+
0,
|
|
1868
|
+
0,
|
|
1869
|
+
0,
|
|
1870
|
+
0,
|
|
1871
|
+
-17,
|
|
1872
|
+
0,
|
|
1873
|
+
0,
|
|
1874
|
+
-15,
|
|
1875
|
+
0,
|
|
1876
|
+
0,
|
|
1877
|
+
0,
|
|
1878
|
+
0,
|
|
1879
|
+
0,
|
|
1880
|
+
0,
|
|
1881
|
+
-16,
|
|
1882
|
+
0,
|
|
1883
|
+
0,
|
|
1884
|
+
0,
|
|
1885
|
+
0,
|
|
1886
|
+
0,
|
|
1887
|
+
0,
|
|
1888
|
+
-17
|
|
1889
|
+
], U = {
|
|
1890
|
+
p: 1,
|
|
1891
|
+
n: 2,
|
|
1892
|
+
b: 4,
|
|
1893
|
+
r: 8,
|
|
1894
|
+
q: 16,
|
|
1895
|
+
k: 32
|
|
1896
|
+
}, W = "pnbrqkPNBRQK", G = [
|
|
1897
|
+
"n",
|
|
1898
|
+
"b",
|
|
1899
|
+
"r",
|
|
1900
|
+
"q"
|
|
1901
|
+
], K = 7, q = 6, J = 1, Y = 0, X = {
|
|
1902
|
+
k: L.KSIDE_CASTLE,
|
|
1903
|
+
q: L.QSIDE_CASTLE
|
|
1904
|
+
}, Z = {
|
|
1905
|
+
w: [{
|
|
1906
|
+
square: R.a1,
|
|
1907
|
+
flag: L.QSIDE_CASTLE
|
|
1908
|
+
}, {
|
|
1909
|
+
square: R.h1,
|
|
1910
|
+
flag: L.KSIDE_CASTLE
|
|
1911
|
+
}],
|
|
1912
|
+
b: [{
|
|
1913
|
+
square: R.a8,
|
|
1914
|
+
flag: L.QSIDE_CASTLE
|
|
1915
|
+
}, {
|
|
1916
|
+
square: R.h8,
|
|
1917
|
+
flag: L.KSIDE_CASTLE
|
|
1918
|
+
}]
|
|
1919
|
+
}, Q = {
|
|
1920
|
+
b: J,
|
|
1921
|
+
w: q
|
|
1922
|
+
}, ee = [
|
|
1923
|
+
"1-0",
|
|
1924
|
+
"0-1",
|
|
1925
|
+
"1/2-1/2",
|
|
1926
|
+
"*"
|
|
1927
|
+
];
|
|
1928
|
+
function rank(e) {
|
|
1929
|
+
return e >> 4;
|
|
1930
|
+
}
|
|
1931
|
+
function file(e) {
|
|
1932
|
+
return e & 15;
|
|
1933
|
+
}
|
|
1934
|
+
function isDigit(e) {
|
|
1935
|
+
return "0123456789".indexOf(e) !== -1;
|
|
1936
|
+
}
|
|
1937
|
+
function algebraic(e) {
|
|
1938
|
+
let t = file(e), n = rank(e);
|
|
1939
|
+
return "abcdefgh".substring(t, t + 1) + "87654321".substring(n, n + 1);
|
|
1940
|
+
}
|
|
1941
|
+
function swapColor$1(e) {
|
|
1942
|
+
return e === "w" ? "b" : "w";
|
|
1943
|
+
}
|
|
1944
|
+
e(swapColor$1, "swapColor");
|
|
1945
|
+
function validateFen(e) {
|
|
1946
|
+
let t = e.split(/\s+/);
|
|
1947
|
+
if (t.length !== 6) return {
|
|
1948
|
+
ok: !1,
|
|
1949
|
+
error: "Invalid FEN: must contain six space-delimited fields"
|
|
1950
|
+
};
|
|
1951
|
+
let n = parseInt(t[5], 10);
|
|
1952
|
+
if (isNaN(n) || n <= 0) return {
|
|
1953
|
+
ok: !1,
|
|
1954
|
+
error: "Invalid FEN: move number must be a positive integer"
|
|
1955
|
+
};
|
|
1956
|
+
let r = parseInt(t[4], 10);
|
|
1957
|
+
if (isNaN(r) || r < 0) return {
|
|
1958
|
+
ok: !1,
|
|
1959
|
+
error: "Invalid FEN: half move counter number must be a non-negative integer"
|
|
1960
|
+
};
|
|
1961
|
+
if (!/^(-|[abcdefgh][36])$/.test(t[3])) return {
|
|
1962
|
+
ok: !1,
|
|
1963
|
+
error: "Invalid FEN: en-passant square is invalid"
|
|
1964
|
+
};
|
|
1965
|
+
if (/[^kKqQ-]/.test(t[2])) return {
|
|
1966
|
+
ok: !1,
|
|
1967
|
+
error: "Invalid FEN: castling availability is invalid"
|
|
1968
|
+
};
|
|
1969
|
+
if (!/^(w|b)$/.test(t[1])) return {
|
|
1970
|
+
ok: !1,
|
|
1971
|
+
error: "Invalid FEN: side-to-move is invalid"
|
|
1972
|
+
};
|
|
1973
|
+
let i = t[0].split("/");
|
|
1974
|
+
if (i.length !== 8) return {
|
|
1975
|
+
ok: !1,
|
|
1976
|
+
error: "Invalid FEN: piece data does not contain 8 '/'-delimited rows"
|
|
1977
|
+
};
|
|
1978
|
+
for (let e = 0; e < i.length; e++) {
|
|
1979
|
+
let t = 0, n = !1;
|
|
1980
|
+
for (let r = 0; r < i[e].length; r++) if (isDigit(i[e][r])) {
|
|
1981
|
+
if (n) return {
|
|
1982
|
+
ok: !1,
|
|
1983
|
+
error: "Invalid FEN: piece data is invalid (consecutive number)"
|
|
1984
|
+
};
|
|
1985
|
+
t += parseInt(i[e][r], 10), n = !0;
|
|
1986
|
+
} else {
|
|
1987
|
+
if (!/^[prnbqkPRNBQK]$/.test(i[e][r])) return {
|
|
1988
|
+
ok: !1,
|
|
1989
|
+
error: "Invalid FEN: piece data is invalid (invalid piece)"
|
|
1990
|
+
};
|
|
1991
|
+
t += 1, n = !1;
|
|
1992
|
+
}
|
|
1993
|
+
if (t !== 8) return {
|
|
1994
|
+
ok: !1,
|
|
1995
|
+
error: "Invalid FEN: piece data is invalid (too many squares in rank)"
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
if (t[3][1] == "3" && t[1] == "w" || t[3][1] == "6" && t[1] == "b") return {
|
|
1999
|
+
ok: !1,
|
|
2000
|
+
error: "Invalid FEN: illegal en-passant square"
|
|
2001
|
+
};
|
|
2002
|
+
for (let { color: e, regex: n } of [{
|
|
2003
|
+
color: "white",
|
|
2004
|
+
regex: /K/g
|
|
2005
|
+
}, {
|
|
2006
|
+
color: "black",
|
|
2007
|
+
regex: /k/g
|
|
2008
|
+
}]) {
|
|
2009
|
+
if (!n.test(t[0])) return {
|
|
2010
|
+
ok: !1,
|
|
2011
|
+
error: `Invalid FEN: missing ${e} king`
|
|
2012
|
+
};
|
|
2013
|
+
if ((t[0].match(n) || []).length > 1) return {
|
|
2014
|
+
ok: !1,
|
|
2015
|
+
error: `Invalid FEN: too many ${e} kings`
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
return Array.from(i[0] + i[7]).some((e) => e.toUpperCase() === "P") ? {
|
|
2019
|
+
ok: !1,
|
|
2020
|
+
error: "Invalid FEN: some pawns are on the edge rows"
|
|
2021
|
+
} : { ok: !0 };
|
|
2022
|
+
}
|
|
2023
|
+
function getDisambiguator(e, t) {
|
|
2024
|
+
let n = e.from, r = e.to, i = e.piece, a = 0, o = 0, s = 0;
|
|
2025
|
+
for (let e = 0, c = t.length; e < c; e++) {
|
|
2026
|
+
let c = t[e].from, l = t[e].to;
|
|
2027
|
+
i === t[e].piece && n !== c && r === l && (a++, rank(n) === rank(c) && o++, file(n) === file(c) && s++);
|
|
2028
|
+
}
|
|
2029
|
+
return a > 0 ? o > 0 && s > 0 ? algebraic(n) : s > 0 ? algebraic(n).charAt(1) : algebraic(n).charAt(0) : "";
|
|
2030
|
+
}
|
|
2031
|
+
function addMove(e, t, n, r, i, a = void 0, o = L.NORMAL) {
|
|
2032
|
+
let s = rank(r);
|
|
2033
|
+
if (i === "p" && (s === K || s === Y)) for (let s = 0; s < G.length; s++) {
|
|
2034
|
+
let c = G[s];
|
|
2035
|
+
e.push({
|
|
2036
|
+
color: t,
|
|
2037
|
+
from: n,
|
|
2038
|
+
to: r,
|
|
2039
|
+
piece: i,
|
|
2040
|
+
captured: a,
|
|
2041
|
+
promotion: c,
|
|
2042
|
+
flags: o | L.PROMOTION
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
else e.push({
|
|
2046
|
+
color: t,
|
|
2047
|
+
from: n,
|
|
2048
|
+
to: r,
|
|
2049
|
+
piece: i,
|
|
2050
|
+
captured: a,
|
|
2051
|
+
flags: o
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
function inferPieceType(e) {
|
|
2055
|
+
let t = e.charAt(0);
|
|
2056
|
+
return t >= "a" && t <= "h" ? e.match(/[a-h]\d.*[a-h]\d/) ? void 0 : "p" : (t = t.toLowerCase(), t === "o" ? "k" : t);
|
|
2057
|
+
}
|
|
2058
|
+
function strippedSan(e) {
|
|
2059
|
+
return e.replace(/=/, "").replace(/[+#]?[?!]*$/, "");
|
|
2060
|
+
}
|
|
2061
|
+
function trimFen(e) {
|
|
2062
|
+
return e.split(" ").slice(0, 4).join(" ");
|
|
2063
|
+
}
|
|
2064
|
+
var Chess = class {
|
|
2065
|
+
_board = Array(128);
|
|
2066
|
+
_turn = "w";
|
|
2067
|
+
_header = {};
|
|
2068
|
+
_kings = {
|
|
2069
|
+
w: P,
|
|
2070
|
+
b: P
|
|
2071
|
+
};
|
|
2072
|
+
_epSquare = -1;
|
|
2073
|
+
_halfMoves = 0;
|
|
2074
|
+
_moveNumber = 0;
|
|
2075
|
+
_history = [];
|
|
2076
|
+
_comments = {};
|
|
2077
|
+
_castling = {
|
|
2078
|
+
w: 0,
|
|
2079
|
+
b: 0
|
|
2080
|
+
};
|
|
2081
|
+
_positionCount = {};
|
|
2082
|
+
constructor(e = N, { skipValidation: t = !1 } = {}) {
|
|
2083
|
+
this.load(e, { skipValidation: t });
|
|
2084
|
+
}
|
|
2085
|
+
clear({ preserveHeaders: e = !1 } = {}) {
|
|
2086
|
+
this._board = Array(128), this._kings = {
|
|
2087
|
+
w: P,
|
|
2088
|
+
b: P
|
|
2089
|
+
}, this._turn = "w", this._castling = {
|
|
2090
|
+
w: 0,
|
|
2091
|
+
b: 0
|
|
2092
|
+
}, this._epSquare = P, this._halfMoves = 0, this._moveNumber = 1, this._history = [], this._comments = {}, this._header = e ? this._header : {}, this._positionCount = {}, delete this._header.SetUp, delete this._header.FEN;
|
|
2093
|
+
}
|
|
2094
|
+
load(e, { skipValidation: t = !1, preserveHeaders: n = !1 } = {}) {
|
|
2095
|
+
let r = e.split(/\s+/);
|
|
2096
|
+
if (r.length >= 2 && r.length < 6 && (e = r.concat([
|
|
2097
|
+
"-",
|
|
2098
|
+
"-",
|
|
2099
|
+
"0",
|
|
2100
|
+
"1"
|
|
2101
|
+
].slice(-(6 - r.length))).join(" ")), r = e.split(/\s+/), !t) {
|
|
2102
|
+
let { ok: t, error: n } = validateFen(e);
|
|
2103
|
+
if (!t) throw Error(n);
|
|
2104
|
+
}
|
|
2105
|
+
let i = r[0], a = 0;
|
|
2106
|
+
this.clear({ preserveHeaders: n });
|
|
2107
|
+
for (let e = 0; e < i.length; e++) {
|
|
2108
|
+
let t = i.charAt(e);
|
|
2109
|
+
if (t === "/") a += 8;
|
|
2110
|
+
else if (isDigit(t)) a += parseInt(t, 10);
|
|
2111
|
+
else {
|
|
2112
|
+
let e = t < "a" ? "w" : "b";
|
|
2113
|
+
this._put({
|
|
2114
|
+
type: t.toLowerCase(),
|
|
2115
|
+
color: e
|
|
2116
|
+
}, algebraic(a)), a++;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
this._turn = r[1], r[2].indexOf("K") > -1 && (this._castling.w |= L.KSIDE_CASTLE), r[2].indexOf("Q") > -1 && (this._castling.w |= L.QSIDE_CASTLE), r[2].indexOf("k") > -1 && (this._castling.b |= L.KSIDE_CASTLE), r[2].indexOf("q") > -1 && (this._castling.b |= L.QSIDE_CASTLE), this._epSquare = r[3] === "-" ? P : R[r[3]], this._halfMoves = parseInt(r[4], 10), this._moveNumber = parseInt(r[5], 10), this._updateSetup(e), this._incPositionCount(e);
|
|
2120
|
+
}
|
|
2121
|
+
fen() {
|
|
2122
|
+
let e = 0, t = "";
|
|
2123
|
+
for (let n = R.a8; n <= R.h1; n++) {
|
|
2124
|
+
if (this._board[n]) {
|
|
2125
|
+
e > 0 && (t += e, e = 0);
|
|
2126
|
+
let { color: r, type: i } = this._board[n];
|
|
2127
|
+
t += r === "w" ? i.toUpperCase() : i.toLowerCase();
|
|
2128
|
+
} else e++;
|
|
2129
|
+
n + 1 & 136 && (e > 0 && (t += e), n !== R.h1 && (t += "/"), e = 0, n += 8);
|
|
2130
|
+
}
|
|
2131
|
+
let n = "";
|
|
2132
|
+
this._castling.w & L.KSIDE_CASTLE && (n += "K"), this._castling.w & L.QSIDE_CASTLE && (n += "Q"), this._castling.b & L.KSIDE_CASTLE && (n += "k"), this._castling.b & L.QSIDE_CASTLE && (n += "q"), n ||= "-";
|
|
2133
|
+
let r = "-";
|
|
2134
|
+
if (this._epSquare !== P) {
|
|
2135
|
+
let e = this._epSquare + (this._turn === "w" ? 16 : -16), t = [e + 1, e - 1];
|
|
2136
|
+
for (let e of t) {
|
|
2137
|
+
if (e & 136) continue;
|
|
2138
|
+
let t = this._turn;
|
|
2139
|
+
if (this._board[e]?.color === t && this._board[e]?.type === "p") {
|
|
2140
|
+
this._makeMove({
|
|
2141
|
+
color: t,
|
|
2142
|
+
from: e,
|
|
2143
|
+
to: this._epSquare,
|
|
2144
|
+
piece: "p",
|
|
2145
|
+
captured: "p",
|
|
2146
|
+
flags: L.EP_CAPTURE
|
|
2147
|
+
});
|
|
2148
|
+
let n = !this._isKingAttacked(t);
|
|
2149
|
+
if (this._undoMove(), n) {
|
|
2150
|
+
r = algebraic(this._epSquare);
|
|
2151
|
+
break;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
return [
|
|
2157
|
+
t,
|
|
2158
|
+
this._turn,
|
|
2159
|
+
n,
|
|
2160
|
+
r,
|
|
2161
|
+
this._halfMoves,
|
|
2162
|
+
this._moveNumber
|
|
2163
|
+
].join(" ");
|
|
2164
|
+
}
|
|
2165
|
+
_updateSetup(e) {
|
|
2166
|
+
this._history.length > 0 || (e === "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" ? (delete this._header.SetUp, delete this._header.FEN) : (this._header.SetUp = "1", this._header.FEN = e));
|
|
2167
|
+
}
|
|
2168
|
+
reset() {
|
|
2169
|
+
this.load(N);
|
|
2170
|
+
}
|
|
2171
|
+
get(e) {
|
|
2172
|
+
return this._board[R[e]];
|
|
2173
|
+
}
|
|
2174
|
+
put({ type: e, color: t }, n) {
|
|
2175
|
+
return this._put({
|
|
2176
|
+
type: e,
|
|
2177
|
+
color: t
|
|
2178
|
+
}, n) ? (this._updateCastlingRights(), this._updateEnPassantSquare(), this._updateSetup(this.fen()), !0) : !1;
|
|
2179
|
+
}
|
|
2180
|
+
_put({ type: e, color: t }, n) {
|
|
2181
|
+
if (W.indexOf(e.toLowerCase()) === -1 || !(n in R)) return !1;
|
|
2182
|
+
let r = R[n];
|
|
2183
|
+
if (e == "k" && !(this._kings[t] == P || this._kings[t] == r)) return !1;
|
|
2184
|
+
let i = this._board[r];
|
|
2185
|
+
return i && i.type === "k" && (this._kings[i.color] = P), this._board[r] = {
|
|
2186
|
+
type: e,
|
|
2187
|
+
color: t
|
|
2188
|
+
}, e === "k" && (this._kings[t] = r), !0;
|
|
2189
|
+
}
|
|
2190
|
+
remove(e) {
|
|
2191
|
+
let t = this.get(e);
|
|
2192
|
+
return delete this._board[R[e]], t && t.type === "k" && (this._kings[t.color] = P), this._updateCastlingRights(), this._updateEnPassantSquare(), this._updateSetup(this.fen()), t;
|
|
2193
|
+
}
|
|
2194
|
+
_updateCastlingRights() {
|
|
2195
|
+
let e = this._board[R.e1]?.type === "k" && this._board[R.e1]?.color === "w", t = this._board[R.e8]?.type === "k" && this._board[R.e8]?.color === "b";
|
|
2196
|
+
(!e || this._board[R.a1]?.type !== "r" || this._board[R.a1]?.color !== "w") && (this._castling.w &= ~L.QSIDE_CASTLE), (!e || this._board[R.h1]?.type !== "r" || this._board[R.h1]?.color !== "w") && (this._castling.w &= ~L.KSIDE_CASTLE), (!t || this._board[R.a8]?.type !== "r" || this._board[R.a8]?.color !== "b") && (this._castling.b &= ~L.QSIDE_CASTLE), (!t || this._board[R.h8]?.type !== "r" || this._board[R.h8]?.color !== "b") && (this._castling.b &= ~L.KSIDE_CASTLE);
|
|
2197
|
+
}
|
|
2198
|
+
_updateEnPassantSquare() {
|
|
2199
|
+
if (this._epSquare === P) return;
|
|
2200
|
+
let e = this._epSquare + (this._turn === "w" ? -16 : 16), t = this._epSquare + (this._turn === "w" ? 16 : -16), n = [t + 1, t - 1];
|
|
2201
|
+
if (this._board[e] !== null || this._board[this._epSquare] !== null || this._board[t]?.color !== swapColor$1(this._turn) || this._board[t]?.type !== "p") {
|
|
2202
|
+
this._epSquare = P;
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2205
|
+
let canCapture = (e) => !(e & 136) && this._board[e]?.color === this._turn && this._board[e]?.type === "p";
|
|
2206
|
+
n.some(canCapture) || (this._epSquare = P);
|
|
2207
|
+
}
|
|
2208
|
+
_attacked(e, t, n) {
|
|
2209
|
+
let r = [];
|
|
2210
|
+
for (let i = R.a8; i <= R.h1; i++) {
|
|
2211
|
+
if (i & 136) {
|
|
2212
|
+
i += 7;
|
|
2213
|
+
continue;
|
|
2214
|
+
}
|
|
2215
|
+
if (this._board[i] === void 0 || this._board[i].color !== e) continue;
|
|
2216
|
+
let a = this._board[i], o = i - t;
|
|
2217
|
+
if (o === 0) continue;
|
|
2218
|
+
let s = o + 119;
|
|
2219
|
+
if (V[s] & U[a.type]) {
|
|
2220
|
+
if (a.type === "p") {
|
|
2221
|
+
if (o > 0 && a.color === "w" || o <= 0 && a.color === "b") if (n) r.push(algebraic(i));
|
|
2222
|
+
else return !0;
|
|
2223
|
+
continue;
|
|
2224
|
+
}
|
|
2225
|
+
if (a.type === "n" || a.type === "k") if (n) {
|
|
2226
|
+
r.push(algebraic(i));
|
|
2227
|
+
continue;
|
|
2228
|
+
} else return !0;
|
|
2229
|
+
let e = H[s], c = i + e, l = !1;
|
|
2230
|
+
for (; c !== t;) {
|
|
2231
|
+
if (this._board[c] != null) {
|
|
2232
|
+
l = !0;
|
|
2233
|
+
break;
|
|
2234
|
+
}
|
|
2235
|
+
c += e;
|
|
2236
|
+
}
|
|
2237
|
+
if (!l) if (n) {
|
|
2238
|
+
r.push(algebraic(i));
|
|
2239
|
+
continue;
|
|
2240
|
+
} else return !0;
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
return n ? r : !1;
|
|
2244
|
+
}
|
|
2245
|
+
attackers(e, t) {
|
|
2246
|
+
return t ? this._attacked(t, R[e], !0) : this._attacked(this._turn, R[e], !0);
|
|
2247
|
+
}
|
|
2248
|
+
_isKingAttacked(e) {
|
|
2249
|
+
let t = this._kings[e];
|
|
2250
|
+
return t === -1 ? !1 : this._attacked(swapColor$1(e), t);
|
|
2251
|
+
}
|
|
2252
|
+
isAttacked(e, t) {
|
|
2253
|
+
return this._attacked(t, R[e]);
|
|
2254
|
+
}
|
|
2255
|
+
isCheck() {
|
|
2256
|
+
return this._isKingAttacked(this._turn);
|
|
2257
|
+
}
|
|
2258
|
+
inCheck() {
|
|
2259
|
+
return this.isCheck();
|
|
2260
|
+
}
|
|
2261
|
+
isCheckmate() {
|
|
2262
|
+
return this.isCheck() && this._moves().length === 0;
|
|
2263
|
+
}
|
|
2264
|
+
isStalemate() {
|
|
2265
|
+
return !this.isCheck() && this._moves().length === 0;
|
|
2266
|
+
}
|
|
2267
|
+
isInsufficientMaterial() {
|
|
2268
|
+
let e = {
|
|
2269
|
+
b: 0,
|
|
2270
|
+
n: 0,
|
|
2271
|
+
r: 0,
|
|
2272
|
+
q: 0,
|
|
2273
|
+
k: 0,
|
|
2274
|
+
p: 0
|
|
2275
|
+
}, t = [], n = 0, r = 0;
|
|
2276
|
+
for (let i = R.a8; i <= R.h1; i++) {
|
|
2277
|
+
if (r = (r + 1) % 2, i & 136) {
|
|
2278
|
+
i += 7;
|
|
2279
|
+
continue;
|
|
2280
|
+
}
|
|
2281
|
+
let a = this._board[i];
|
|
2282
|
+
a && (e[a.type] = a.type in e ? e[a.type] + 1 : 1, a.type === "b" && t.push(r), n++);
|
|
2283
|
+
}
|
|
2284
|
+
if (n === 2 || n === 3 && (e.b === 1 || e.n === 1)) return !0;
|
|
2285
|
+
if (n === e.b + 2) {
|
|
2286
|
+
let e = 0, n = t.length;
|
|
2287
|
+
for (let r = 0; r < n; r++) e += t[r];
|
|
2288
|
+
if (e === 0 || e === n) return !0;
|
|
2289
|
+
}
|
|
2290
|
+
return !1;
|
|
2291
|
+
}
|
|
2292
|
+
isThreefoldRepetition() {
|
|
2293
|
+
return this._getPositionCount(this.fen()) >= 3;
|
|
2294
|
+
}
|
|
2295
|
+
isDrawByFiftyMoves() {
|
|
2296
|
+
return this._halfMoves >= 100;
|
|
2297
|
+
}
|
|
2298
|
+
isDraw() {
|
|
2299
|
+
return this.isDrawByFiftyMoves() || this.isStalemate() || this.isInsufficientMaterial() || this.isThreefoldRepetition();
|
|
2300
|
+
}
|
|
2301
|
+
isGameOver() {
|
|
2302
|
+
return this.isCheckmate() || this.isStalemate() || this.isDraw();
|
|
2303
|
+
}
|
|
2304
|
+
moves({ verbose: e = !1, square: t = void 0, piece: n = void 0 } = {}) {
|
|
2305
|
+
let r = this._moves({
|
|
2306
|
+
square: t,
|
|
2307
|
+
piece: n
|
|
2308
|
+
});
|
|
2309
|
+
return e ? r.map((e) => new Move(this, e)) : r.map((e) => this._moveToSan(e, r));
|
|
2310
|
+
}
|
|
2311
|
+
_moves({ legal: e = !0, piece: t = void 0, square: n = void 0 } = {}) {
|
|
2312
|
+
let r = n ? n.toLowerCase() : void 0, i = t?.toLowerCase(), a = [], o = this._turn, s = swapColor$1(o), c = R.a8, l = R.h1, u = !1;
|
|
2313
|
+
if (r) if (r in R) c = l = R[r], u = !0;
|
|
2314
|
+
else return [];
|
|
2315
|
+
for (let e = c; e <= l; e++) {
|
|
2316
|
+
if (e & 136) {
|
|
2317
|
+
e += 7;
|
|
2318
|
+
continue;
|
|
2319
|
+
}
|
|
2320
|
+
if (!this._board[e] || this._board[e].color === s) continue;
|
|
2321
|
+
let { type: t } = this._board[e], n;
|
|
2322
|
+
if (t === "p") {
|
|
2323
|
+
if (i && i !== t) continue;
|
|
2324
|
+
n = e + z[o][0], this._board[n] || (addMove(a, o, e, n, "p"), n = e + z[o][1], Q[o] === rank(e) && !this._board[n] && addMove(a, o, e, n, "p", void 0, L.BIG_PAWN));
|
|
2325
|
+
for (let t = 2; t < 4; t++) n = e + z[o][t], !(n & 136) && (this._board[n]?.color === s ? addMove(a, o, e, n, "p", this._board[n].type, L.CAPTURE) : n === this._epSquare && addMove(a, o, e, n, "p", "p", L.EP_CAPTURE));
|
|
2326
|
+
} else {
|
|
2327
|
+
if (i && i !== t) continue;
|
|
2328
|
+
for (let r = 0, i = B[t].length; r < i; r++) {
|
|
2329
|
+
let i = B[t][r];
|
|
2330
|
+
for (n = e; n += i, !(n & 136);) {
|
|
2331
|
+
if (!this._board[n]) addMove(a, o, e, n, t);
|
|
2332
|
+
else {
|
|
2333
|
+
if (this._board[n].color === o) break;
|
|
2334
|
+
addMove(a, o, e, n, t, this._board[n].type, L.CAPTURE);
|
|
2335
|
+
break;
|
|
2336
|
+
}
|
|
2337
|
+
if (t === "n" || t === "k") break;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
if ((i === void 0 || i === "k") && (!u || l === this._kings[o])) {
|
|
2343
|
+
if (this._castling[o] & L.KSIDE_CASTLE) {
|
|
2344
|
+
let e = this._kings[o], t = e + 2;
|
|
2345
|
+
!this._board[e + 1] && !this._board[t] && !this._attacked(s, this._kings[o]) && !this._attacked(s, e + 1) && !this._attacked(s, t) && addMove(a, o, this._kings[o], t, "k", void 0, L.KSIDE_CASTLE);
|
|
2346
|
+
}
|
|
2347
|
+
if (this._castling[o] & L.QSIDE_CASTLE) {
|
|
2348
|
+
let e = this._kings[o], t = e - 2;
|
|
2349
|
+
!this._board[e - 1] && !this._board[e - 2] && !this._board[e - 3] && !this._attacked(s, this._kings[o]) && !this._attacked(s, e - 1) && !this._attacked(s, t) && addMove(a, o, this._kings[o], t, "k", void 0, L.QSIDE_CASTLE);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
if (!e || this._kings[o] === -1) return a;
|
|
2353
|
+
let d = [];
|
|
2354
|
+
for (let e = 0, t = a.length; e < t; e++) this._makeMove(a[e]), this._isKingAttacked(o) || d.push(a[e]), this._undoMove();
|
|
2355
|
+
return d;
|
|
2356
|
+
}
|
|
2357
|
+
move(e, { strict: t = !1 } = {}) {
|
|
2358
|
+
let n = null;
|
|
2359
|
+
if (typeof e == "string") n = this._moveFromSan(e, t);
|
|
2360
|
+
else if (typeof e == "object") {
|
|
2361
|
+
let t = this._moves();
|
|
2362
|
+
for (let r = 0, i = t.length; r < i; r++) if (e.from === algebraic(t[r].from) && e.to === algebraic(t[r].to) && (!("promotion" in t[r]) || e.promotion === t[r].promotion)) {
|
|
2363
|
+
n = t[r];
|
|
2364
|
+
break;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
if (!n) throw typeof e == "string" ? Error(`Invalid move: ${e}`) : Error(`Invalid move: ${JSON.stringify(e)}`);
|
|
2368
|
+
let r = new Move(this, n);
|
|
2369
|
+
return this._makeMove(n), this._incPositionCount(r.after), r;
|
|
2370
|
+
}
|
|
2371
|
+
_push(e) {
|
|
2372
|
+
this._history.push({
|
|
2373
|
+
move: e,
|
|
2374
|
+
kings: {
|
|
2375
|
+
b: this._kings.b,
|
|
2376
|
+
w: this._kings.w
|
|
2377
|
+
},
|
|
2378
|
+
turn: this._turn,
|
|
2379
|
+
castling: {
|
|
2380
|
+
b: this._castling.b,
|
|
2381
|
+
w: this._castling.w
|
|
2382
|
+
},
|
|
2383
|
+
epSquare: this._epSquare,
|
|
2384
|
+
halfMoves: this._halfMoves,
|
|
2385
|
+
moveNumber: this._moveNumber
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2388
|
+
_makeMove(e) {
|
|
2389
|
+
let t = this._turn, n = swapColor$1(t);
|
|
2390
|
+
if (this._push(e), this._board[e.to] = this._board[e.from], delete this._board[e.from], e.flags & L.EP_CAPTURE && (this._turn === "b" ? delete this._board[e.to - 16] : delete this._board[e.to + 16]), e.promotion && (this._board[e.to] = {
|
|
2391
|
+
type: e.promotion,
|
|
2392
|
+
color: t
|
|
2393
|
+
}), this._board[e.to].type === "k") {
|
|
2394
|
+
if (this._kings[t] = e.to, e.flags & L.KSIDE_CASTLE) {
|
|
2395
|
+
let t = e.to - 1, n = e.to + 1;
|
|
2396
|
+
this._board[t] = this._board[n], delete this._board[n];
|
|
2397
|
+
} else if (e.flags & L.QSIDE_CASTLE) {
|
|
2398
|
+
let t = e.to + 1, n = e.to - 2;
|
|
2399
|
+
this._board[t] = this._board[n], delete this._board[n];
|
|
2400
|
+
}
|
|
2401
|
+
this._castling[t] = 0;
|
|
2402
|
+
}
|
|
2403
|
+
if (this._castling[t]) {
|
|
2404
|
+
for (let n = 0, r = Z[t].length; n < r; n++) if (e.from === Z[t][n].square && this._castling[t] & Z[t][n].flag) {
|
|
2405
|
+
this._castling[t] ^= Z[t][n].flag;
|
|
2406
|
+
break;
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
if (this._castling[n]) {
|
|
2410
|
+
for (let t = 0, r = Z[n].length; t < r; t++) if (e.to === Z[n][t].square && this._castling[n] & Z[n][t].flag) {
|
|
2411
|
+
this._castling[n] ^= Z[n][t].flag;
|
|
2412
|
+
break;
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
e.flags & L.BIG_PAWN ? t === "b" ? this._epSquare = e.to - 16 : this._epSquare = e.to + 16 : this._epSquare = P, e.piece === "p" || e.flags & (L.CAPTURE | L.EP_CAPTURE) ? this._halfMoves = 0 : this._halfMoves++, t === "b" && this._moveNumber++, this._turn = n;
|
|
2416
|
+
}
|
|
2417
|
+
undo() {
|
|
2418
|
+
let e = this._undoMove();
|
|
2419
|
+
if (e) {
|
|
2420
|
+
let t = new Move(this, e);
|
|
2421
|
+
return this._decPositionCount(t.after), t;
|
|
2422
|
+
}
|
|
2423
|
+
return null;
|
|
2424
|
+
}
|
|
2425
|
+
_undoMove() {
|
|
2426
|
+
let e = this._history.pop();
|
|
2427
|
+
if (e === void 0) return null;
|
|
2428
|
+
let t = e.move;
|
|
2429
|
+
this._kings = e.kings, this._turn = e.turn, this._castling = e.castling, this._epSquare = e.epSquare, this._halfMoves = e.halfMoves, this._moveNumber = e.moveNumber;
|
|
2430
|
+
let n = this._turn, r = swapColor$1(n);
|
|
2431
|
+
if (this._board[t.from] = this._board[t.to], this._board[t.from].type = t.piece, delete this._board[t.to], t.captured) if (t.flags & L.EP_CAPTURE) {
|
|
2432
|
+
let e;
|
|
2433
|
+
e = n === "b" ? t.to - 16 : t.to + 16, this._board[e] = {
|
|
2434
|
+
type: "p",
|
|
2435
|
+
color: r
|
|
2436
|
+
};
|
|
2437
|
+
} else this._board[t.to] = {
|
|
2438
|
+
type: t.captured,
|
|
2439
|
+
color: r
|
|
2440
|
+
};
|
|
2441
|
+
if (t.flags & (L.KSIDE_CASTLE | L.QSIDE_CASTLE)) {
|
|
2442
|
+
let e, n;
|
|
2443
|
+
t.flags & L.KSIDE_CASTLE ? (e = t.to + 1, n = t.to - 1) : (e = t.to - 2, n = t.to + 1), this._board[e] = this._board[n], delete this._board[n];
|
|
2444
|
+
}
|
|
2445
|
+
return t;
|
|
2446
|
+
}
|
|
2447
|
+
pgn({ newline: e = "\n", maxWidth: t = 0 } = {}) {
|
|
2448
|
+
let n = [], r = !1;
|
|
2449
|
+
for (let t in this._header) n.push("[" + t + " \"" + this._header[t] + "\"]" + e), r = !0;
|
|
2450
|
+
r && this._history.length && n.push(e);
|
|
2451
|
+
let appendComment = (e) => {
|
|
2452
|
+
let t = this._comments[this.fen()];
|
|
2453
|
+
if (t !== void 0) {
|
|
2454
|
+
let n = e.length > 0 ? " " : "";
|
|
2455
|
+
e = `${e}${n}{${t}}`;
|
|
2456
|
+
}
|
|
2457
|
+
return e;
|
|
2458
|
+
}, i = [];
|
|
2459
|
+
for (; this._history.length > 0;) i.push(this._undoMove());
|
|
2460
|
+
let a = [], o = "";
|
|
2461
|
+
for (i.length === 0 && a.push(appendComment("")); i.length > 0;) {
|
|
2462
|
+
o = appendComment(o);
|
|
2463
|
+
let e = i.pop();
|
|
2464
|
+
if (!e) break;
|
|
2465
|
+
if (!this._history.length && e.color === "b") {
|
|
2466
|
+
let e = `${this._moveNumber}. ...`;
|
|
2467
|
+
o = o ? `${o} ${e}` : e;
|
|
2468
|
+
} else e.color === "w" && (o.length && a.push(o), o = this._moveNumber + ".");
|
|
2469
|
+
o = o + " " + this._moveToSan(e, this._moves({ legal: !0 })), this._makeMove(e);
|
|
2470
|
+
}
|
|
2471
|
+
if (o.length && a.push(appendComment(o)), this._header.Result !== void 0 && a.push(this._header.Result), t === 0) return n.join("") + a.join(" ");
|
|
2472
|
+
let strip = function() {
|
|
2473
|
+
return n.length > 0 && n[n.length - 1] === " " ? (n.pop(), !0) : !1;
|
|
2474
|
+
}, wrapComment = function(r, i) {
|
|
2475
|
+
for (let a of i.split(" ")) if (a) {
|
|
2476
|
+
if (r + a.length > t) {
|
|
2477
|
+
for (; strip();) r--;
|
|
2478
|
+
n.push(e), r = 0;
|
|
2479
|
+
}
|
|
2480
|
+
n.push(a), r += a.length, n.push(" "), r++;
|
|
2481
|
+
}
|
|
2482
|
+
return strip() && r--, r;
|
|
2483
|
+
}, s = 0;
|
|
2484
|
+
for (let r = 0; r < a.length; r++) {
|
|
2485
|
+
if (s + a[r].length > t && a[r].includes("{")) {
|
|
2486
|
+
s = wrapComment(s, a[r]);
|
|
2487
|
+
continue;
|
|
2488
|
+
}
|
|
2489
|
+
s + a[r].length > t && r !== 0 ? (n[n.length - 1] === " " && n.pop(), n.push(e), s = 0) : r !== 0 && (n.push(" "), s++), n.push(a[r]), s += a[r].length;
|
|
2490
|
+
}
|
|
2491
|
+
return n.join("");
|
|
2492
|
+
}
|
|
2493
|
+
header(...e) {
|
|
2494
|
+
for (let t = 0; t < e.length; t += 2) typeof e[t] == "string" && typeof e[t + 1] == "string" && (this._header[e[t]] = e[t + 1]);
|
|
2495
|
+
return this._header;
|
|
2496
|
+
}
|
|
2497
|
+
setHeader(e, t) {
|
|
2498
|
+
return this._header[e] = t, this._header;
|
|
2499
|
+
}
|
|
2500
|
+
removeHeader(e) {
|
|
2501
|
+
return e in this._header ? (delete this._header[e], !0) : !1;
|
|
2502
|
+
}
|
|
2503
|
+
getHeaders() {
|
|
2504
|
+
return this._header;
|
|
2505
|
+
}
|
|
2506
|
+
loadPgn(e, { strict: t = !1, newlineChar: n = "\r?\n" } = {}) {
|
|
2507
|
+
function mask(e) {
|
|
2508
|
+
return e.replace(/\\/g, "\\");
|
|
2509
|
+
}
|
|
2510
|
+
function parsePgnHeader(e) {
|
|
2511
|
+
let t = {}, r = e.split(new RegExp(mask(n))), i = "", a = "";
|
|
2512
|
+
for (let e = 0; e < r.length; e++) {
|
|
2513
|
+
let n = /^\s*\[\s*([A-Za-z]+)\s*"(.*)"\s*\]\s*$/;
|
|
2514
|
+
i = r[e].replace(n, "$1"), a = r[e].replace(n, "$2"), i.trim().length > 0 && (t[i] = a);
|
|
2515
|
+
}
|
|
2516
|
+
return t;
|
|
2517
|
+
}
|
|
2518
|
+
e = e.trim();
|
|
2519
|
+
let r = RegExp("^(\\[((?:" + mask(n) + ")|.)*\\])((?:\\s*" + mask(n) + "){2}|(?:\\s*" + mask(n) + ")*$)").exec(e), i = r && r.length >= 2 ? r[1] : "";
|
|
2520
|
+
this.reset();
|
|
2521
|
+
let a = parsePgnHeader(i), o = "";
|
|
2522
|
+
for (let e in a) e.toLowerCase() === "fen" && (o = a[e]), this.header(e, a[e]);
|
|
2523
|
+
if (!t) o && this.load(o, { preserveHeaders: !0 });
|
|
2524
|
+
else if (a.SetUp === "1") {
|
|
2525
|
+
if (!("FEN" in a)) throw Error("Invalid PGN: FEN tag must be supplied with SetUp tag");
|
|
2526
|
+
this.load(a.FEN, { preserveHeaders: !0 });
|
|
2527
|
+
}
|
|
2528
|
+
function toHex(e) {
|
|
2529
|
+
return Array.from(e).map(function(e) {
|
|
2530
|
+
return e.charCodeAt(0) < 128 ? e.charCodeAt(0).toString(16) : encodeURIComponent(e).replace(/%/g, "").toLowerCase();
|
|
2531
|
+
}).join("");
|
|
2532
|
+
}
|
|
2533
|
+
function fromHex(e) {
|
|
2534
|
+
return e.length == 0 ? "" : decodeURIComponent("%" + (e.match(/.{1,2}/g) || []).join("%"));
|
|
2535
|
+
}
|
|
2536
|
+
let encodeComment = function(e) {
|
|
2537
|
+
return e = e.replace(new RegExp(mask(n), "g"), " "), `{${toHex(e.slice(1, e.length - 1))}}`;
|
|
2538
|
+
}, decodeComment = function(e) {
|
|
2539
|
+
if (e.startsWith("{") && e.endsWith("}")) return fromHex(e.slice(1, e.length - 1));
|
|
2540
|
+
}, s = e.replace(i, "").replace(RegExp(`({[^}]*})+?|;([^${mask(n)}]*)`, "g"), function(e, t, n) {
|
|
2541
|
+
return t === void 0 ? " " + encodeComment(`{${n.slice(1)}}`) : encodeComment(t);
|
|
2542
|
+
}).replace(new RegExp(mask(n), "g"), " "), c = /(\([^()]+\))+?/g;
|
|
2543
|
+
for (; c.test(s);) s = s.replace(c, "");
|
|
2544
|
+
s = s.replace(/\d+\.(\.\.)?/g, ""), s = s.replace(/\.\.\./g, ""), s = s.replace(/\$\d+/g, "");
|
|
2545
|
+
let l = s.trim().split(/* @__PURE__ */ new RegExp(/\s+/));
|
|
2546
|
+
l = l.filter((e) => e !== "");
|
|
2547
|
+
let u = "";
|
|
2548
|
+
for (let e = 0; e < l.length; e++) {
|
|
2549
|
+
let n = decodeComment(l[e]);
|
|
2550
|
+
if (n !== void 0) {
|
|
2551
|
+
this._comments[this.fen()] = n;
|
|
2552
|
+
continue;
|
|
2553
|
+
}
|
|
2554
|
+
let r = this._moveFromSan(l[e], t);
|
|
2555
|
+
if (r == null) if (ee.indexOf(l[e]) > -1) u = l[e];
|
|
2556
|
+
else throw Error(`Invalid move in PGN: ${l[e]}`);
|
|
2557
|
+
else u = "", this._makeMove(r), this._incPositionCount(this.fen());
|
|
2558
|
+
}
|
|
2559
|
+
u && Object.keys(this._header).length && !this._header.Result && this.header("Result", u);
|
|
2560
|
+
}
|
|
2561
|
+
_moveToSan(e, t) {
|
|
2562
|
+
let n = "";
|
|
2563
|
+
if (e.flags & L.KSIDE_CASTLE) n = "O-O";
|
|
2564
|
+
else if (e.flags & L.QSIDE_CASTLE) n = "O-O-O";
|
|
2565
|
+
else {
|
|
2566
|
+
if (e.piece !== "p") {
|
|
2567
|
+
let r = getDisambiguator(e, t);
|
|
2568
|
+
n += e.piece.toUpperCase() + r;
|
|
2569
|
+
}
|
|
2570
|
+
e.flags & (L.CAPTURE | L.EP_CAPTURE) && (e.piece === "p" && (n += algebraic(e.from)[0]), n += "x"), n += algebraic(e.to), e.promotion && (n += "=" + e.promotion.toUpperCase());
|
|
2571
|
+
}
|
|
2572
|
+
return this._makeMove(e), this.isCheck() && (this.isCheckmate() ? n += "#" : n += "+"), this._undoMove(), n;
|
|
2573
|
+
}
|
|
2574
|
+
_moveFromSan(e, t = !1) {
|
|
2575
|
+
let n = strippedSan(e), r = inferPieceType(n), i = this._moves({
|
|
2576
|
+
legal: !0,
|
|
2577
|
+
piece: r
|
|
2578
|
+
});
|
|
2579
|
+
for (let e = 0, t = i.length; e < t; e++) if (n === strippedSan(this._moveToSan(i[e], i))) return i[e];
|
|
2580
|
+
if (t) return null;
|
|
2581
|
+
let a, o, s, c, l, u = !1;
|
|
2582
|
+
if (o = n.match(/([pnbrqkPNBRQK])?([a-h][1-8])x?-?([a-h][1-8])([qrbnQRBN])?/), o ? (a = o[1], s = o[2], c = o[3], l = o[4], s.length == 1 && (u = !0)) : (o = n.match(/([pnbrqkPNBRQK])?([a-h]?[1-8]?)x?-?([a-h][1-8])([qrbnQRBN])?/), o && (a = o[1], s = o[2], c = o[3], l = o[4], s.length == 1 && (u = !0))), r = inferPieceType(n), i = this._moves({
|
|
2583
|
+
legal: !0,
|
|
2584
|
+
piece: a || r
|
|
2585
|
+
}), !c) return null;
|
|
2586
|
+
for (let e = 0, t = i.length; e < t; e++) if (!s) {
|
|
2587
|
+
if (n === strippedSan(this._moveToSan(i[e], i)).replace("x", "")) return i[e];
|
|
2588
|
+
} else if ((!a || a.toLowerCase() == i[e].piece) && R[s] == i[e].from && R[c] == i[e].to && (!l || l.toLowerCase() == i[e].promotion)) return i[e];
|
|
2589
|
+
else if (u) {
|
|
2590
|
+
let t = algebraic(i[e].from);
|
|
2591
|
+
if ((!a || a.toLowerCase() == i[e].piece) && R[c] == i[e].to && (s == t[0] || s == t[1]) && (!l || l.toLowerCase() == i[e].promotion)) return i[e];
|
|
2592
|
+
}
|
|
2593
|
+
return null;
|
|
2594
|
+
}
|
|
2595
|
+
ascii() {
|
|
2596
|
+
let e = " +------------------------+\n";
|
|
2597
|
+
for (let t = R.a8; t <= R.h1; t++) {
|
|
2598
|
+
if (file(t) === 0 && (e += " " + "87654321"[rank(t)] + " |"), this._board[t]) {
|
|
2599
|
+
let n = this._board[t].type, r = this._board[t].color === "w" ? n.toUpperCase() : n.toLowerCase();
|
|
2600
|
+
e += " " + r + " ";
|
|
2601
|
+
} else e += " . ";
|
|
2602
|
+
t + 1 & 136 && (e += "|\n", t += 8);
|
|
2603
|
+
}
|
|
2604
|
+
return e += " +------------------------+\n", e += " a b c d e f g h", e;
|
|
2605
|
+
}
|
|
2606
|
+
perft(e) {
|
|
2607
|
+
let t = this._moves({ legal: !1 }), n = 0, r = this._turn;
|
|
2608
|
+
for (let i = 0, a = t.length; i < a; i++) this._makeMove(t[i]), this._isKingAttacked(r) || (e - 1 > 0 ? n += this.perft(e - 1) : n++), this._undoMove();
|
|
2609
|
+
return n;
|
|
2610
|
+
}
|
|
2611
|
+
turn() {
|
|
2612
|
+
return this._turn;
|
|
2613
|
+
}
|
|
2614
|
+
board() {
|
|
2615
|
+
let e = [], t = [];
|
|
2616
|
+
for (let n = R.a8; n <= R.h1; n++) this._board[n] == null ? t.push(null) : t.push({
|
|
2617
|
+
square: algebraic(n),
|
|
2618
|
+
type: this._board[n].type,
|
|
2619
|
+
color: this._board[n].color
|
|
2620
|
+
}), n + 1 & 136 && (e.push(t), t = [], n += 8);
|
|
2621
|
+
return e;
|
|
2622
|
+
}
|
|
2623
|
+
squareColor(e) {
|
|
2624
|
+
if (e in R) {
|
|
2625
|
+
let t = R[e];
|
|
2626
|
+
return (rank(t) + file(t)) % 2 == 0 ? "light" : "dark";
|
|
2627
|
+
}
|
|
2628
|
+
return null;
|
|
2629
|
+
}
|
|
2630
|
+
history({ verbose: e = !1 } = {}) {
|
|
2631
|
+
let t = [], n = [];
|
|
2632
|
+
for (; this._history.length > 0;) t.push(this._undoMove());
|
|
2633
|
+
for (;;) {
|
|
2634
|
+
let r = t.pop();
|
|
2635
|
+
if (!r) break;
|
|
2636
|
+
e ? n.push(new Move(this, r)) : n.push(this._moveToSan(r, this._moves())), this._makeMove(r);
|
|
2637
|
+
}
|
|
2638
|
+
return n;
|
|
2639
|
+
}
|
|
2640
|
+
_getPositionCount(e) {
|
|
2641
|
+
let t = trimFen(e);
|
|
2642
|
+
return this._positionCount[t] || 0;
|
|
2643
|
+
}
|
|
2644
|
+
_incPositionCount(e) {
|
|
2645
|
+
let t = trimFen(e);
|
|
2646
|
+
this._positionCount[t] === void 0 && (this._positionCount[t] = 0), this._positionCount[t] += 1;
|
|
2647
|
+
}
|
|
2648
|
+
_decPositionCount(e) {
|
|
2649
|
+
let t = trimFen(e);
|
|
2650
|
+
this._positionCount[t] === 1 ? delete this._positionCount[t] : --this._positionCount[t];
|
|
2651
|
+
}
|
|
2652
|
+
_pruneComments() {
|
|
2653
|
+
let e = [], t = {}, copyComment = (e) => {
|
|
2654
|
+
e in this._comments && (t[e] = this._comments[e]);
|
|
2655
|
+
};
|
|
2656
|
+
for (; this._history.length > 0;) e.push(this._undoMove());
|
|
2657
|
+
for (copyComment(this.fen());;) {
|
|
2658
|
+
let t = e.pop();
|
|
2659
|
+
if (!t) break;
|
|
2660
|
+
this._makeMove(t), copyComment(this.fen());
|
|
2661
|
+
}
|
|
2662
|
+
this._comments = t;
|
|
2663
|
+
}
|
|
2664
|
+
getComment() {
|
|
2665
|
+
return this._comments[this.fen()];
|
|
2666
|
+
}
|
|
2667
|
+
setComment(e) {
|
|
2668
|
+
this._comments[this.fen()] = e.replace("{", "[").replace("}", "]");
|
|
2669
|
+
}
|
|
2670
|
+
deleteComment() {
|
|
2671
|
+
return this.removeComment();
|
|
2672
|
+
}
|
|
2673
|
+
removeComment() {
|
|
2674
|
+
let e = this._comments[this.fen()];
|
|
2675
|
+
return delete this._comments[this.fen()], e;
|
|
2676
|
+
}
|
|
2677
|
+
getComments() {
|
|
2678
|
+
return this._pruneComments(), Object.keys(this._comments).map((e) => ({
|
|
2679
|
+
fen: e,
|
|
2680
|
+
comment: this._comments[e]
|
|
2681
|
+
}));
|
|
2682
|
+
}
|
|
2683
|
+
deleteComments() {
|
|
2684
|
+
return this.removeComments();
|
|
2685
|
+
}
|
|
2686
|
+
removeComments() {
|
|
2687
|
+
return this._pruneComments(), Object.keys(this._comments).map((e) => {
|
|
2688
|
+
let t = this._comments[e];
|
|
2689
|
+
return delete this._comments[e], {
|
|
2690
|
+
fen: e,
|
|
2691
|
+
comment: t
|
|
2692
|
+
};
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
setCastlingRights(e, t) {
|
|
2696
|
+
for (let n of ["k", "q"]) t[n] !== void 0 && (t[n] ? this._castling[e] |= X[n] : this._castling[e] &= ~X[n]);
|
|
2697
|
+
this._updateCastlingRights();
|
|
2698
|
+
let n = this.getCastlingRights(e);
|
|
2699
|
+
return (t.k === void 0 || t.k === n.k) && (t.q === void 0 || t.q === n.q);
|
|
2700
|
+
}
|
|
2701
|
+
getCastlingRights(e) {
|
|
2702
|
+
return {
|
|
2703
|
+
k: (this._castling[e] & X.k) !== 0,
|
|
2704
|
+
q: (this._castling[e] & X.q) !== 0
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
moveNumber() {
|
|
2708
|
+
return this._moveNumber;
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
//#endregion
|
|
2712
|
+
//#region src/chess/composables/useChessgroundBounds.ts
|
|
2713
|
+
function useChessgroundBounds(e, t) {
|
|
2714
|
+
let n = null, r = h(() => t.value, (t) => {
|
|
2715
|
+
!t || !e.value || (requestAnimationFrame(() => t.redrawAll()), n = new ResizeObserver(() => t.redrawAll()), n.observe(e.value), r());
|
|
2716
|
+
}, { immediate: !0 });
|
|
2717
|
+
u(() => {
|
|
2718
|
+
n?.disconnect(), n = null;
|
|
2719
|
+
});
|
|
2720
|
+
}
|
|
2721
|
+
//#endregion
|
|
2722
|
+
//#region src/chess/questions/puzzle/puzzle.vue?vue&type=script&lang.ts
|
|
2723
|
+
var parseUciMove = (e) => {
|
|
2724
|
+
if (e.length < 4 || e.length > 5) throw Error(`Invalid UCI move format: ${e}`);
|
|
2725
|
+
return {
|
|
2726
|
+
from: e.substring(0, 2),
|
|
2727
|
+
to: e.substring(2, 4),
|
|
2728
|
+
promotion: e.length === 5 ? e[4] : void 0
|
|
2729
|
+
};
|
|
2730
|
+
}, toDests = (e) => {
|
|
2731
|
+
let t = /* @__PURE__ */ new Map();
|
|
2732
|
+
return I.forEach((n) => {
|
|
2733
|
+
let r = e.moves({
|
|
2734
|
+
square: n,
|
|
2735
|
+
verbose: !0
|
|
2736
|
+
});
|
|
2737
|
+
r.length && t.set(n, r.map((e) => e.to));
|
|
2738
|
+
}), t;
|
|
2739
|
+
}, swapColor = (e) => e === "cg-white" ? "cg-black" : "cg-white", toColor = (e) => e.turn() === "w" ? "cg-white" : "cg-black", te = c({
|
|
2740
|
+
name: "PuzzleView",
|
|
2741
|
+
props: {
|
|
2742
|
+
data: {
|
|
2743
|
+
type: Array,
|
|
2744
|
+
required: !0
|
|
2745
|
+
},
|
|
2746
|
+
modifyDifficulty: {
|
|
2747
|
+
type: Number,
|
|
2748
|
+
required: !1,
|
|
2749
|
+
default: 0
|
|
2750
|
+
}
|
|
2751
|
+
},
|
|
2752
|
+
setup(e, { emit: t }) {
|
|
2753
|
+
let n = v(e, t, "PuzzleView"), r = _(n), a = f(null), o = f(), s = f(), c = f("cg-white"), d = f(!1), p = f(null);
|
|
2754
|
+
useChessgroundBounds(a, s);
|
|
2755
|
+
let m = [
|
|
2756
|
+
{
|
|
2757
|
+
value: "q",
|
|
2758
|
+
name: "Queen",
|
|
2759
|
+
whiteSymbol: "♕",
|
|
2760
|
+
blackSymbol: "♛"
|
|
2761
|
+
},
|
|
2762
|
+
{
|
|
2763
|
+
value: "r",
|
|
2764
|
+
name: "Rook",
|
|
2765
|
+
whiteSymbol: "♖",
|
|
2766
|
+
blackSymbol: "♜"
|
|
2767
|
+
},
|
|
2768
|
+
{
|
|
2769
|
+
value: "b",
|
|
2770
|
+
name: "Bishop",
|
|
2771
|
+
whiteSymbol: "♗",
|
|
2772
|
+
blackSymbol: "♝"
|
|
2773
|
+
},
|
|
2774
|
+
{
|
|
2775
|
+
value: "n",
|
|
2776
|
+
name: "Knight",
|
|
2777
|
+
whiteSymbol: "♘",
|
|
2778
|
+
blackSymbol: "♞"
|
|
2779
|
+
}
|
|
2780
|
+
], h = i(() => {
|
|
2781
|
+
let e = [
|
|
2782
|
+
"a",
|
|
2783
|
+
"b",
|
|
2784
|
+
"c",
|
|
2785
|
+
"d",
|
|
2786
|
+
"e",
|
|
2787
|
+
"f",
|
|
2788
|
+
"g",
|
|
2789
|
+
"h"
|
|
2790
|
+
];
|
|
2791
|
+
return c.value === "cg-white" ? e : e.reverse();
|
|
2792
|
+
}), isPromotionPiece = (e) => e ? [
|
|
2793
|
+
"q",
|
|
2794
|
+
"r",
|
|
2795
|
+
"b",
|
|
2796
|
+
"n"
|
|
2797
|
+
].includes(e) : !1, isUnfinishedPromotion = (e, t, n) => isPromotionPiece(n) ? !1 : o.value?.get(e)?.type === "p" && (t[1] === "8" || t[1] === "1"), updateChessground = () => {
|
|
2798
|
+
!o.value || !s.value || s.value.set({
|
|
2799
|
+
fen: o.value.fen(),
|
|
2800
|
+
turnColor: toColor(o.value),
|
|
2801
|
+
movable: {
|
|
2802
|
+
color: toColor(o.value),
|
|
2803
|
+
dests: toDests(o.value)
|
|
2804
|
+
}
|
|
2805
|
+
});
|
|
2806
|
+
}, handlePromotion = (e) => {
|
|
2807
|
+
if (e !== "q" && e !== "r" && e !== "b" && e !== "n") {
|
|
2808
|
+
n.logger.error(`Invalid promotion piece: ${e}`);
|
|
2809
|
+
return;
|
|
2810
|
+
}
|
|
2811
|
+
p.value && (n.logger.log(`promoting to ${e}`), d.value = !1, checkMove(p.value.from, p.value.to, e));
|
|
2812
|
+
}, checkMove = (e, t, n) => {
|
|
2813
|
+
if (!r.question.value?.moves.length) throw Error("No moves");
|
|
2814
|
+
if (isUnfinishedPromotion(e, t, n)) {
|
|
2815
|
+
p.value = {
|
|
2816
|
+
from: e,
|
|
2817
|
+
to: t
|
|
2818
|
+
}, d.value = !0;
|
|
2819
|
+
return;
|
|
2820
|
+
}
|
|
2821
|
+
r.question.value.moves[0] === (isPromotionPiece(n) ? `${e}${t}${n}` : `${e}${t}`) ? (o.value?.move({
|
|
2822
|
+
from: e,
|
|
2823
|
+
to: t,
|
|
2824
|
+
promotion: isPromotionPiece(n) ? n : void 0
|
|
2825
|
+
}), updateChessground(), r.question.value.moves.shift(), r.question.value.moves.length === 0 ? r.submitAnswer("") : window.setTimeout(() => {
|
|
2826
|
+
if (!r.question.value) return;
|
|
2827
|
+
let e = parseUciMove(r.question.value.moves.shift());
|
|
2828
|
+
o.value?.move(e), updateChessground();
|
|
2829
|
+
}, 300)) : (o.value?.move({
|
|
2830
|
+
from: e,
|
|
2831
|
+
to: t,
|
|
2832
|
+
promotion: n
|
|
2833
|
+
}), o.value?.isCheckmate() ? r.submitAnswer($.CHECKMATE) : o.value?.undo(), r.submitAnswer(e + t + n), updateChessground());
|
|
2834
|
+
};
|
|
2835
|
+
return l(() => {
|
|
2836
|
+
if (!a.value) return;
|
|
2837
|
+
r.question.value = new $(e.data), o.value = new Chess(r.question.value.fen), c.value = swapColor(toColor(o.value)), s.value = Chessground(a.value, {
|
|
2838
|
+
movable: {
|
|
2839
|
+
free: !1,
|
|
2840
|
+
showDests: !0,
|
|
2841
|
+
dests: toDests(o.value),
|
|
2842
|
+
events: { after: checkMove }
|
|
2843
|
+
},
|
|
2844
|
+
draggable: { showGhost: !0 },
|
|
2845
|
+
fen: o.value.fen(),
|
|
2846
|
+
orientation: c.value,
|
|
2847
|
+
coordinates: !1,
|
|
2848
|
+
animation: {
|
|
2849
|
+
duration: 300,
|
|
2850
|
+
enabled: !0
|
|
2851
|
+
}
|
|
2852
|
+
});
|
|
2853
|
+
let t = r.question.value.moves.shift();
|
|
2854
|
+
s.value.move(t.substring(0, 2), t.substring(2)), o.value.move({
|
|
2855
|
+
from: t.substring(0, 2),
|
|
2856
|
+
to: t.substring(2)
|
|
2857
|
+
}), updateChessground();
|
|
2858
|
+
}), u(() => {
|
|
2859
|
+
s.value?.destroy(), o.value = void 0;
|
|
2860
|
+
}), {
|
|
2861
|
+
boardElement: a,
|
|
2862
|
+
playerColor: c,
|
|
2863
|
+
files: h,
|
|
2864
|
+
showPromotionDialog: d,
|
|
2865
|
+
promotionPieces: m,
|
|
2866
|
+
handlePromotion,
|
|
2867
|
+
...n,
|
|
2868
|
+
...r
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
}), ne = { "data-viewable": "PuzzleView" }, re = { class: "text-h5" }, ie = { class: "puzzle-board-wrapper" }, ae = { class: "puzzle-ranks-labels" }, oe = { class: "puzzle-board-and-files" }, se = {
|
|
2872
|
+
id: "cg",
|
|
2873
|
+
ref: "boardElement"
|
|
2874
|
+
}, ce = { class: "puzzle-files-labels" }, le = {
|
|
2875
|
+
key: 0,
|
|
2876
|
+
class: "puzzle-promotion-dialog"
|
|
2877
|
+
}, ue = ["onClick"];
|
|
2878
|
+
function _sfc_render(e, t, n, i, c, l) {
|
|
2879
|
+
return d(), o("div", ne, [
|
|
2880
|
+
s("p", re, " Make the best move for " + m(e.playerColor === "cg-white" ? "White ♖♘♗♕♔♗♘♖" : "Black ♜♞♝♚♛♝♞♜") + ": ", 1),
|
|
2881
|
+
s("div", ie, [s("div", ae, [(d(), o(r, null, p(8, (t) => s("div", { key: t }, m(e.playerColor === "cg-white" ? 9 - t : t), 1)), 64))]), s("div", oe, [s("div", se, null, 512), s("div", ce, [(d(!0), o(r, null, p(e.files, (e) => (d(), o("div", { key: e }, m(e), 1))), 128))])])]),
|
|
2882
|
+
e.showPromotionDialog ? (d(), o("div", le, [(d(!0), o(r, null, p(e.promotionPieces, (t) => (d(), o("button", {
|
|
2883
|
+
key: t.value,
|
|
2884
|
+
onClick: (n) => e.handlePromotion(t.value)
|
|
2885
|
+
}, m(e.playerColor === "cg-white" ? t.whiteSymbol : t.blackSymbol) + " " + m(t.name), 9, ue))), 128))])) : a("", !0)
|
|
2886
|
+
]);
|
|
2887
|
+
}
|
|
2888
|
+
var de = /* @__PURE__ */ t(te, [["render", _sfc_render]]), $ = class ChessPuzzle extends g {
|
|
2889
|
+
static dataShapes = [{
|
|
2890
|
+
name: y.CHESS_puzzle,
|
|
2891
|
+
fields: [{
|
|
2892
|
+
name: "puzzleData",
|
|
2893
|
+
type: b.CHESS_PUZZLE,
|
|
2894
|
+
validator: {
|
|
2895
|
+
instructions: "insert a valid fen string",
|
|
2896
|
+
test: function(e) {
|
|
2897
|
+
return console.log(`running puzzle validator on ${e}`), e ? e.split(",").length == 10 ? {
|
|
2898
|
+
status: x.ok,
|
|
2899
|
+
msg: ""
|
|
2900
|
+
} : {
|
|
2901
|
+
status: x.error,
|
|
2902
|
+
msg: "puzzleData must have 8 comma-separated fields"
|
|
2903
|
+
} : {
|
|
2904
|
+
status: x.error,
|
|
2905
|
+
msg: "no defined input"
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
},
|
|
2909
|
+
tagger: () => ["test"]
|
|
2910
|
+
}]
|
|
2911
|
+
}];
|
|
2912
|
+
static views = [de];
|
|
2913
|
+
static acceptsUserData = !0;
|
|
2914
|
+
static CHECKMATE = "CHECKMATE";
|
|
2915
|
+
fen;
|
|
2916
|
+
id;
|
|
2917
|
+
moves;
|
|
2918
|
+
rating;
|
|
2919
|
+
themes;
|
|
2920
|
+
constructor(e) {
|
|
2921
|
+
super(e);
|
|
2922
|
+
let [t, n, r, i, , , , a] = e[0].puzzleData.split(",");
|
|
2923
|
+
this.id = t, this.fen = n, this.moves = r.split(" "), this.rating = parseInt(i, 10), this.themes = a.split(" ");
|
|
2924
|
+
}
|
|
2925
|
+
checkMove = (e, t) => (alert("checkMove"), console.log("checkMove", e, t), console.log("this.moves[0]", this.moves[0]), this.moves[0] === t);
|
|
2926
|
+
evaluate(e, t) {
|
|
2927
|
+
return {
|
|
2928
|
+
isCorrect: this.isCorrect(e),
|
|
2929
|
+
performance: this.displayedSkill(e, t)
|
|
2930
|
+
};
|
|
2931
|
+
}
|
|
2932
|
+
displayedSkill(e, t) {
|
|
2933
|
+
return this.isCorrect(e) ? t < 5e3 ? 1 : 1 - Math.min(1, (t - 5e3) / 1e4) : 0;
|
|
2934
|
+
}
|
|
2935
|
+
dataShapes() {
|
|
2936
|
+
return ChessPuzzle.dataShapes;
|
|
2937
|
+
}
|
|
2938
|
+
views() {
|
|
2939
|
+
return ChessPuzzle.views;
|
|
2940
|
+
}
|
|
2941
|
+
isCorrect(e) {
|
|
2942
|
+
let t = this.moves.length === 0;
|
|
2943
|
+
return e === ChessPuzzle.CHECKMATE || t;
|
|
2944
|
+
}
|
|
2945
|
+
}, fe = new n("chess", [$]);
|
|
2946
|
+
//#endregion
|
|
2947
|
+
export { fe as t };
|
|
2948
|
+
|
|
2949
|
+
//# sourceMappingURL=chess-BbHATAzk.js.map
|