X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2FplayCompMove.js;h=d8dd2d470bd06eab8eb6c4514ac0851db5403f20;hb=8a0f881d7d2729cb421c6c1efcf51e6820ef005d;hp=d6b0cea94dd402d97326a9eedcb4b9f2bd88b9e8;hpb=5b020e732156ee77d3b15b127aef2df57c2562ad;p=vchess.git diff --git a/client/src/playCompMove.js b/client/src/playCompMove.js index d6b0cea9..d8dd2d47 100644 --- a/client/src/playCompMove.js +++ b/client/src/playCompMove.js @@ -1,25 +1,23 @@ -// For asynchronous computer move search -onmessage = function(e) -{ - switch (e.data[0]) - { - case "scripts": - self.importScripts( - '/javascripts/base_rules.js', - '/javascripts/utils/array.js', - '/javascripts/variants/' + e.data[1] + '.js'); - self.V = eval(e.data[1] + "Rules"); - break; - case "init": - const fen = e.data[1]; - self.vr = new VariantRules(fen); - break; - case "newmove": - self.vr.play(e.data[1]); - break; - case "askmove": - const compMove = self.vr.getComputerMove(); - postMessage(compMove); - break; - } -} +// Logic to play a computer move in a web worker +onmessage = async function(e) { + switch (e.data[0]) { + case "scripts": { + const vModule = await import("@/variants/" + e.data[1] + ".js"); + self.V = vModule.VariantRules; + break; + } + case "init": { + const fen = e.data[1]; + self.vr = new self.V(fen); + break; + } + case "newmove": + self.vr.play(e.data[1]); + break; + case "askmove": { + const compMove = self.vr.getComputerMove(); + postMessage(compMove); + break; + } + } +};