A small Python script that reads a JSON list of positions and their known Perft node counts to a certain depth, then invokes the Perft program for each position and validates the output. Peter Ellis Jones shared such a JSON list on GitHub. Import that file.
80 lines
1.7 KiB
Python
Executable file
80 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, expected_nodes_count):
|
|
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'expected-nodes={expected_nodes_count}')
|
|
|
|
nodes_count = run_perft(fen, depth, expected_nodes_count)
|
|
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))
|