Commit | Line | Data |
---|---|---|
24340cae BA |
1 | // TODO: https://github.com/webpack-contrib/worker-loader |
2 | // https://stackoverflow.com/questions/48713072/how-to-get-js-function-into-webworker-via-importscripts | |
643479f8 | 3 | // For asynchronous computer move search |
e2732923 BA |
4 | |
5 | //self.addEventListener('message', (e) => | |
6 | onmessage = async function(e) | |
643479f8 BA |
7 | { |
8 | switch (e.data[0]) | |
9 | { | |
10 | case "scripts": | |
e2732923 BA |
11 | const vModule = await import("@/variants/" + e.data[1] + ".js"); |
12 | self.V = vModule.VariantRules; | |
643479f8 BA |
13 | break; |
14 | case "init": | |
15 | const fen = e.data[1]; | |
e2732923 | 16 | self.vr = new self.V(fen); |
643479f8 BA |
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 | } |