forked from keiranking/Phil
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathxw_worker.js
More file actions
29 lines (28 loc) · 936 Bytes
/
xw_worker.js
File metadata and controls
29 lines (28 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module = {};
importScripts('fill.js');
onmessage = function(e) {
let cmd = e.data;
switch (cmd[0]) {
case 'run':
let words = cmd[1].split(/\n/);
let grid = cmd[2];
grid = grid.replace(/\./g, "#");
grid = grid.replace(/ /g, ".");
console.log("fill:\n" + grid);
let wordlist = new module.exports.wordlist(words);
let filler = new module.exports.filler(grid, wordlist);
let result = filler.fill();
console.log("result:\n" + result);
if (result.indexOf(".") == -1) {
result = result.replace(/\./g, " ");
result = result.replace(/#/g, ".");
postMessage(["sat", result + "\n"]);
} else {
postMessage(["unsat"]);
}
break;
case 'cancel':
postMessage(["ack_cancel"]);
break;
}
};