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'); | |
ab4f4bf2 | 12 | self.V = eval(e.data[1] + "Rules"); |
643479f8 BA |
13 | break; |
14 | case "init": | |
15 | const fen = e.data[1]; | |
8d7e2786 | 16 | self.vr = new VariantRules(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 | } |