Started code review + some fixes (unfinished)
[vchess.git] / client / src / playCompMove.js
1 // Logic to play a computer move in a web worker
2 onmessage = async function(e) {
3 switch (e.data[0]) {
4 case "scripts": {
5 const vModule = await import("@/variants/" + e.data[1] + ".js");
6 self.V = vModule.VariantRules;
7 break;
8 }
9 case "init": {
10 const fen = e.data[1];
11 self.vr = new self.V(fen);
12 break;
13 }
14 case "newmove":
15 self.vr.play(e.data[1]);
16 break;
17 case "askmove": {
18 const compMove = self.vr.getComputerMove();
19 postMessage(compMove);
20 break;
21 }
22 }
23 };