Play against computer almost OK: need to fix Board component
[vchess.git] / client / src / playCompMove.js
1 // TODO: https://github.com/webpack-contrib/worker-loader
2 // https://stackoverflow.com/questions/48713072/how-to-get-js-function-into-webworker-via-importscripts
3 // For asynchronous computer move search
4
5 //self.addEventListener('message', (e) =>
6 onmessage = async function(e)
7 {
8 switch (e.data[0])
9 {
10 case "scripts":
11 const vModule = await import("@/variants/" + e.data[1] + ".js");
12 self.V = vModule.VariantRules;
13 break;
14 case "init":
15 const fen = e.data[1];
16 self.vr = new self.V(fen);
17 break;
18 case "newmove":
19 self.vr.play(e.data[1]);
20 break;
21 case "askmove":
22 const compMove = self.vr.getComputerMove();
23 postMessage(compMove);
24 break;
25 }
26 }