-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperft.ts
42 lines (34 loc) · 1.44 KB
/
perft.ts
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
import {parseArgs} from "std/cli/parse_args.ts";
import {format} from "std/fmt/duration.ts";
import {green} from "std/fmt/colors.ts";
import { PerftRunner } from "./src/Perft/PerftRunner.ts";
const args = parseArgs(Deno.args, {
string: ['depth','fen','parallel'],
boolean: ['help']
})
if (args.help) {
console.log(`
Usage: perft [options]
Options:
--depth <number> Set the depth for the perft run (default: 1)
--fen <string> Specify the FEN string for the starting position
--parallel <count> Run in parallel threads. <count> (optional) sets the maximum concurrency
Examples:
perft --depth 3 --fen "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
perft --position initial --depth 2
`);
Deno.exit(0);
}
const depth = parseInt(args.depth ?? '1')
const fen = args.fen ?? null
const parallel: boolean = args.parallel !== undefined
let maxThreads: number|null = typeof args.parallel == 'string' ? parseInt(args.parallel) : null
if(parallel && !maxThreads){
maxThreads = 4
}
const runner = new PerftRunner(fen ?? 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')
const totalNodes = parallel ? await runner.runAsync(depth, maxThreads) : runner.run(depth)
const elapsed = format(runner.getRunTime(), {ignoreZero: true})
console.table(runner.getRootNodes()) // print a table of node counts by root moves, useful for debugging
console.log(`Total Nodes: ${totalNodes}`)
console.log(green(`RunTime: ${elapsed}`))