Advance on Game.vue
[vchess.git] / client / src / playCompMove.js
1 // Logic to play a computer move in a web worker
2 onmessage = async function(e)
3 {
4 switch (e.data[0])
5 {
6 case "scripts":
7 const vModule = await import("@/variants/" + e.data[1] + ".js");
8 self.V = vModule.VariantRules;
9 break;
10 case "init":
11 const fen = e.data[1];
12 self.vr = new self.V(fen);
13 break;
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 }