This script processes chess PGN (Portable Game Notation) data to compute the average centipawn loss and a mean of volatility-weighted mean and harmonic mean (Accuracy) for both players.
- Python 3.6 or higher
chess
Python library- Stockfish chess engine (compatible version for your system)
- Install Python 3.6+ from python.org.
- Install the
chess
library using pip:pip install python-chess
- Download the Stockfish engine from the official Stockfish website and place it in a known directory.
Basic usage requires specifying the analysis depth, number of threads, and path to the Stockfish engine. You can input PGN data either from a file or directly as a string:
python chess_accuracy.py 16 2 /path/to/stockfish -file=/path/to/game.pgn
python chess_accuracy.py 16 2 /path/to/stockfish -pgn="1.e4 e5 2.Nf3 Nc6 3.Bb5 a6"
You can also pipe PGN data into the script:
cat /path/to/game.pgn | python chess_accuracy.py 18 2 /path/to/stockfish
For detailed output, including move-by-move analysis, add the -verbose
flag at the end:
python chess_accuracy.py 16 2 /path/to/stockfish -file=/path/to/game.pgn -verbose
The script outputs the average centipawn loss and harmonic mean of accuracy for both players, formatted as follows:
Average centipawn loss (White), Accuracy (White), Average centipawn loss (Black), Accuracy (Black):
44, 84, 15, 95
For verbose mode, additional details for each move are printed to the console.
MIT
© 2024 Alexander Stasiv