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 BA |
3 | // For asynchronous computer move search |
4 | onmessage = function(e) | |
5 | { | |
6 | switch (e.data[0]) | |
7 | { | |
8 | case "scripts": | |
9 | self.importScripts( | |
24340cae BA |
10 | '@/base_rules.js', |
11 | '@/utils/array.js', | |
12 | '@/variants/' + e.data[1] + '.js'); | |
13 | self.V = eval("VariantRules"); | |
643479f8 BA |
14 | break; |
15 | case "init": | |
16 | const fen = e.data[1]; | |
8d7e2786 | 17 | self.vr = new VariantRules(fen); |
643479f8 BA |
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 | } |