f58f99878ffed907f76481543a009ca028357e77
[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 onmessage = function(e)
5 {
6 switch (e.data[0])
7 {
8 case "scripts":
9 self.importScripts(
10 '@/base_rules.js',
11 '@/utils/array.js',
12 '@/variants/' + e.data[1] + '.js');
13 self.V = eval("VariantRules");
14 break;
15 case "init":
16 const fen = e.data[1];
17 self.vr = new VariantRules(fen);
18 break;
19 case "newmove":
20 self.vr.play(e.data[1]);
21 break;
22 case "askmove":
23 const compMove = self.vr.getComputerMove();
24 postMessage(compMove);
25 break;
26 }
27 }