-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperft.js
68 lines (58 loc) · 1.67 KB
/
perft.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
65
66
67
68
// Import the necessary module to work with command line arguments
const process = require("process");
require("./board-pieces.js");
require("./board-moves.js");
const { History } = require("./history.js");
const BoardData = require("./board-data.js");
let data = undefined;
let fen_hash = undefined;
function stats(depth, stat) {
setTimeout(function stats2() {
console.log("" + depth + ": " + stat);
}, 100);
}
// Function to extract command line arguments
function getCommandLineArguments() {
const args = process.argv.slice(2); // This removes the first two default arguments
if (args.length !== 2) {
console.error("Usage: node program.js <depth> <fen>");
process.exit(1);
}
const depth = parseInt(args[0]);
const fen = args[1];
fen_hash = fen;
if (isNaN(depth)) {
console.error("Depth must be an integer.");
process.exit(1);
}
return { depth, fen };
}
function testMoves(depth, callbackStats) {
console.log("Start test move calculation:");
maxDepth = depth;
for (let depth = 1; depth < maxDepth + 1; depth++) {
const startTime = performance.now();
const numPositions = data.testMoves(depth);
const diffTime = Math.round(performance.now() - startTime);
console.log(
"Depth: " +
depth +
" ply Result: " +
numPositions +
" Time " +
diffTime +
" ms"
);
callbackStats(depth, numPositions);
}
}
// Main function to execute the program logic
function main() {
const { depth, fen } = getCommandLineArguments();
console.log(`Depth: ${depth}`);
console.log(`FEN: ${fen}`);
data = new BoardData(new History(), fen);
testMoves(stats);
}
// Run the main function
main();