-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from pkrisz99/development
- Loading branch information
Showing
22 changed files
with
1,271 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
perft.json | ||
perft.json | ||
wac.epd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7c25a2a9", | ||
"metadata": {}, | ||
"source": [ | ||
"### Automated accuracy testing\n", | ||
"\n", | ||
"This is script is made for testing Renegade with various suites. \n", | ||
"Particularly: http://www.bergbomconsulting.se/chess/epdfiles/wac.epd\n", | ||
"\n", | ||
"As long as the engine returns `bestmove ....` and then sends a stopping message (in this case `Stopping engine.`), it should be easy to adapt it to other engines as well.\n", | ||
"\n", | ||
"Requires the `python-chess` library for converting the algebraic notation to uci string." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b5c71f52", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Set the path to executable and json here\n", | ||
"path = \"../x64/Release/Renegade.exe\"\n", | ||
"epd = \"wac.epd\"\n", | ||
"\n", | ||
"parameters = \"movetime 1000\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "11062104", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import subprocess\n", | ||
"import json\n", | ||
"import time\n", | ||
"import chess\n", | ||
"\n", | ||
"tests = []\n", | ||
"with open(epd) as file:\n", | ||
" lines = [line.rstrip().split() for line in file]\n", | ||
" for line in lines:\n", | ||
" fen = line[0] + \" \" + line[1] + \" \" + line[2] + \" \" + line[3] + \" 0 1\"\n", | ||
" moves = []\n", | ||
" i = line.index(\"bm\")\n", | ||
" while True:\n", | ||
" i += 1\n", | ||
" best_move = line[i]\n", | ||
" if best_move.endswith(\";\"):\n", | ||
" best_move = best_move[:-1]\n", | ||
" moves.append(best_move)\n", | ||
" break\n", | ||
" moves.append(best_move)\n", | ||
" tests.append({\"fen\": fen, \"bm\": moves})\n", | ||
" \n", | ||
"def run():\n", | ||
" print(\"Started.\\n\")\n", | ||
" good = 0\n", | ||
" total = 0\n", | ||
" for test in tests:\n", | ||
" total += 1\n", | ||
" board = chess.Board(test['fen'])\n", | ||
" bm_uci = []\n", | ||
" for bm in test['bm']:\n", | ||
" bm_uci.append(board.parse_san(bm).uci())\n", | ||
" output = runtest(test['fen'])\n", | ||
" if str(output, 'ascii') in bm_uci:\n", | ||
" good += 1\n", | ||
" print('%3d. %-68s ' % (total, test['fen']), ' -> ', output, '(correct: ', bm_uci, ')')\n", | ||
" print(\"\\nCompleted.\")\n", | ||
" print(\"Constraints: '%s', correct: %d/%d\" % (parameters, good, total))\n", | ||
"\n", | ||
"def runtest(fen):\n", | ||
" proc = subprocess.Popen([path, '-l', ''], stdout=subprocess.PIPE, stdin=subprocess.PIPE)\n", | ||
" proc.stdin.write(('position fen ' + fen + '\\n').encode())\n", | ||
" proc.stdin.write(('go %s\\n' % parameters).encode())\n", | ||
" proc.stdin.close()\n", | ||
" i = 0\n", | ||
" start = time.time_ns()\n", | ||
" lastline = \"\"\n", | ||
" while True:\n", | ||
" out = proc.stdout.readline().strip()\n", | ||
" if out == b'Stopping engine.': break\n", | ||
" lastline = out\n", | ||
" return lastline.split()[1]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "949a62a7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"run()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.