Play against computer almost OK: need to fix Board component
[vchess.git] / client / src / playCompMove.js
index f58f998..ddaeba3 100644 (file)
@@ -1,20 +1,19 @@
 // TODO: https://github.com/webpack-contrib/worker-loader
 // https://stackoverflow.com/questions/48713072/how-to-get-js-function-into-webworker-via-importscripts
 // For asynchronous computer move search
-onmessage = function(e)
+
+//self.addEventListener('message', (e) =>
+onmessage = async function(e)
 {
        switch (e.data[0])
        {
                case "scripts":
-                       self.importScripts(
-                               '@/base_rules.js',
-                               '@/utils/array.js',
-                               '@/variants/' + e.data[1] + '.js');
-                       self.V = eval("VariantRules");
+      const vModule = await import("@/variants/" + e.data[1] + ".js");
+                       self.V = vModule.VariantRules;
                        break;
                case "init":
                        const fen = e.data[1];
-                       self.vr = new VariantRules(fen);
+                       self.vr = new self.V(fen);
                        break;
                case "newmove":
                        self.vr.play(e.data[1]);