-
Notifications
You must be signed in to change notification settings - Fork 134
/
startup_tester.js
64 lines (51 loc) · 1.1 KB
/
startup_tester.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var spawn = require("child_process").spawn;
var found_san_moves;
var stockfish = spawn(require("path").join(__dirname, "stockfishjs"));
function good(mixed)
{
console.log("\u001B[32m" + mixed + "\u001B[0m");
}
function warn(mixed)
{
console.warn("\u001B[33m" + mixed + "\u001B[0m");
}
function error(mixed)
{
console.error("\u001B[31m" + mixed + "\u001B[0m");
}
function write(str)
{
warn("STDIN: " + str);
stockfish.stdin.write(str + "\n");
}
stockfish.on("error", function (err)
{
throw err;
});
stockfish.stdout.on("data", function onstdout(data)
{
if (typeof data !== "string") {
data = data.toString();
}
process.stdout.write(data)
if (data.indexOf("uciok") > -1) {
good("**Found uciok**");
process.exit();
}
});
stockfish.on("exit", function (code)
{
if (code) {
error("Exited with code: " + code);
throw new Error("Exited with code: " + code);
}
});
setTimeout(function ()
{
write("uci");
}, 1000);
setTimeout(function ()
{
error("Timeout");
throw new Error("Timedout");
}, 1000 * 60 * 5).unref();