testsAndMisc-archive/python_pkg/stockfish_analysis
Krzysztof kuhy Rudnicki a0761eccfc refactor(stockfish_analysis): reduce complexity of main() function
Break down monolithic main() into smaller, focused functions:
- _build_argument_parser(): CLI argument setup
- _load_game(): PGN file loading and parsing
- _configure_threads/hash/multipv/nnue(): Engine configuration helpers
- _setup_engine(): Engine initialization orchestration
- _get_best_move(): Engine best move extraction
- _evaluate_position(): Position evaluation wrapper
- _classify_mate_move(): Mate score classification logic
- _analyze_single_move(): Single move analysis
- _log_move_analysis(): Move analysis logging
- _run_analysis(): Analysis loop orchestration
- _analyze_last_move/all_moves(): Specific analysis modes

Add dataclasses MoveAnalysis and AnalysisContext to bundle related
parameters, improving code organization and reducing function signatures.

This removes the need for C901, PLR0912, PLR0915 per-file ignores
as all functions now comply with complexity limits.
2025-11-30 23:23:10 +01:00
..
analyze_chess_game.py refactor(stockfish_analysis): reduce complexity of main() function 2025-11-30 23:23:10 +01:00
README.md refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00
requirements.txt refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00
run.sh refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00

Chess move analysis with Stockfish

This utility parses a PGN (or a log that contains a PGN section) and evaluates each move with a local Stockfish engine, printing a per-move quality rating.

Install

Install python dependencies:

pip install -r PYTHON/stockfish_analysis/requirements.txt

Ensure Stockfish is installed and available in your PATH (or provide the path via --engine). On Linux, you can typically install with your package manager or download a binary.

Run

From the repo root:

python3 PYTHON/analyze_chess_game.py lichess_bot_game_8GSdY3Ci.log

Options:

  • --engine /path/to/stockfish to specify a custom engine path
  • --time 0.2 seconds per evaluation (default)
  • --depth 12 fixed depth instead of time

The script prints a table with, for each ply:

  • side to move, SAN move, eval before/after from mover's POV, delta, classification, and Stockfish best move suggestion.