Commit | Line | Data |
---|---|---|
643479f8 BA |
1 | // For asynchronous computer move search |
2 | onmessage = function(e) | |
3 | { | |
4 | switch (e.data[0]) | |
5 | { | |
6 | case "scripts": | |
7 | self.importScripts( | |
8 | '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js', | |
9 | '/javascripts/base_rules.js', | |
10 | '/javascripts/utils/array.js', | |
11 | '/javascripts/variants/' + e.data[1] + '.js'); | |
12 | self.V = VariantRules; | |
13 | break; | |
14 | case "init": | |
15 | const fen = e.data[1]; | |
16 | self.vr = new VariantRules(fen, []); | |
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 | } |