Commit | Line | Data |
---|---|---|
4486a21e | 1 | // Logic to play a computer move in a web worker |
6808d7a1 BA |
2 | onmessage = async function(e) { |
3 | switch (e.data[0]) { | |
4 | case "scripts": { | |
e2732923 | 5 | const vModule = await import("@/variants/" + e.data[1] + ".js"); |
1c9f093d BA |
6 | self.V = vModule.VariantRules; |
7 | break; | |
6808d7a1 BA |
8 | } |
9 | case "init": { | |
1c9f093d BA |
10 | const fen = e.data[1]; |
11 | self.vr = new self.V(fen); | |
12 | break; | |
6808d7a1 | 13 | } |
1c9f093d BA |
14 | case "newmove": |
15 | self.vr.play(e.data[1]); | |
16 | break; | |
6808d7a1 | 17 | case "askmove": { |
1c9f093d BA |
18 | const compMove = self.vr.getComputerMove(); |
19 | postMessage(compMove); | |
20 | break; | |
6808d7a1 | 21 | } |
1c9f093d | 22 | } |
6808d7a1 | 23 | }; |