Add Tencubed and Omega variants + some fixes (updateCastleFlags()) + cleaner FEN...
[vchess.git] / client / src / playCompMove.js
CommitLineData
4486a21e 1// Logic to play a computer move in a web worker
6808d7a1
BA
2onmessage = async function(e) {
3 switch (e.data[0]) {
4 case "scripts": {
32f6285e
BA
5 await import("@/variants/" + e.data[1] + ".js")
6 .then((vModule) => { self.V = vModule[e.data[1] + "Rules"]; });
1c9f093d 7 break;
6808d7a1
BA
8 }
9 case "init": {
1c9f093d
BA
10 const fen = e.data[1];
11 self.vr = new self.V(fen);
12 break;
6808d7a1 13 }
1c9f093d 14 case "newmove":
e71161fb
BA
15 let move = e.data[1];
16 // Caution: could be a multi-move
17 if (!Array.isArray(move))
18 move = [move];
19 move.forEach(m => self.vr.play(m));
1c9f093d 20 break;
6808d7a1 21 case "askmove": {
1c9f093d
BA
22 const compMove = self.vr.getComputerMove();
23 postMessage(compMove);
24 break;
6808d7a1 25 }
1c9f093d 26 }
6808d7a1 27};