At the first level of depth, print the move and the number of nodes counted in the tree underneath that node. This behavior imitates Stockfish, and helps with debugging. Clean up the output of the Perft binary, and update the check-positions script to compensate.
81 lines
1.7 KiB
Python
Executable file
81 lines
1.7 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
'''
|
|
New script.
|
|
'''
|
|
|
|
import argparse
|
|
import json
|
|
import subprocess
|
|
|
|
|
|
def run_perft(fen, depth):
|
|
result = subprocess.run(
|
|
[
|
|
'cargo',
|
|
'run',
|
|
'--',
|
|
'--fen', fen,
|
|
str(depth)
|
|
],
|
|
capture_output=True,
|
|
check=True,
|
|
text=True
|
|
)
|
|
|
|
nodes_count = 0
|
|
for line in result.stdout.splitlines():
|
|
if line.startswith('nodes '):
|
|
(_, nodes_count) = line.split(' ')
|
|
nodes_count = int(nodes_count)
|
|
|
|
return nodes_count
|
|
|
|
|
|
def parse_args(argv, *a, **kw):
|
|
parser = argparse.ArgumentParser(*a, **kw)
|
|
parser.add_argument('-c', '--continue', dest='should_continue',
|
|
action='store_true')
|
|
parser.add_argument('file')
|
|
args = parser.parse_args(argv)
|
|
return args
|
|
|
|
|
|
def main(argv):
|
|
args = parse_args(argv[1:], prog=argv[0])
|
|
|
|
items = []
|
|
with open(args.file, 'r') as f:
|
|
items = json.load(f)
|
|
|
|
should_continue = args.should_continue
|
|
|
|
for item in items:
|
|
fen = item['fen']
|
|
depth = item['depth']
|
|
expected_nodes_count = int(item['nodes'])
|
|
|
|
print('---')
|
|
print(f'fen={fen}')
|
|
print(f'depth={depth}')
|
|
print(f'expected-nodes={expected_nodes_count}')
|
|
|
|
nodes_count = run_perft(fen, depth)
|
|
print(f'nodes={nodes_count}')
|
|
|
|
did_pass = nodes_count == expected_nodes_count
|
|
if did_pass:
|
|
print('result=PASS')
|
|
else:
|
|
print('result=FAIL')
|
|
|
|
if not did_pass and not should_continue:
|
|
return -1
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
sys.exit(main(sys.argv))
|