A command-line application written in Go that analyzes chess games from PGN files using the Stockfish engine (or other UCI-compatible engines). The tool evaluates moves, identifies inaccuracies, mistakes, and blunders, calculates centipawn loss, and outputs an annotated PGN with embedded analysis.
- Input: PGN file (single or multi-game)
- Output: Annotated PGN with embedded analysis to standard output
- Output Format: Standard PGN with annotations embedded
- Calculate centipawn loss for each move
- Identify and annotate inaccuracies, mistakes, and blunders
- Calculate average centipawn loss for each player
- Identify and annotate brilliant moves
- Generate summary statistics for each player and game
- Default to Stockfish, with ability to use other UCI-compatible engines
- Configurable engine path via command-line option
- Default to single-threaded analysis with options to use multiple cores
- Dynamic analysis timing similar to Lichess (minimum depth, time per move, additional time for critical positions)
- Inaccuracy: ~20-50 centipawn loss
- Mistake: ~50-100 centipawn loss
- Blunder: >100 centipawn loss
- All thresholds configurable via command-line options
- Go-style flags (e.g.,
-depth 20
) - Support for standard input/output redirection
-pgn
: Path to PGN file (required)-engine
: Path to UCI chess engine executable (optional, default: search in PATH)
-depth
: Minimum analysis depth (optional, default: 18)-time
: Maximum time per move in seconds (optional, default: 3)-threads
: Number of CPU threads (optional, default: 1)-inaccuracy
: Centipawn threshold for inaccuracies (optional, default: 20)-mistake
: Centipawn threshold for mistakes (optional, default: 50)-blunder
: Centipawn threshold for blunders (optional, default: 100)-log
: Log level (info, debug, trace) (optional, default: info)
- Implement UCI protocol for engine communication
- Set appropriate UCI options for Stockfish
- Handle both single-game and multi-game PGN files
- Preserve original PGN headers
- Add new analysis-related headers
- Replace any existing annotations with engine analysis
- Parse PGN file
- Initialize engine
- For each game: a. Process moves sequentially b. For each position: i. Set position in engine ii. Run analysis with configured depth/time iii. Record evaluation and best line iv. Calculate centipawn loss from previous position v. Classify move quality (inaccuracy, mistake, blunder, brilliant) c. Generate summary statistics d. Add annotations and statistics to PGN
- Output annotated PGN to standard out
- Display current move being analyzed
- Show overall percentage complete
- For normal moves: Brief evaluation
- For inaccuracies, mistakes, and blunders:
- Engine evaluation score
- Categorization
- Best engine line
- For brilliant moves: Recognition and evaluation
- Include up to 3 equally strong alternative lines when appropriate
[WhiteInaccuracies "X"]
[WhiteMistakes "X"]
[WhiteBlunders "X"]
[WhiteAverageCentipawnLoss "X.X"]
[BlackInaccuracies "X"]
[BlackMistakes "X"]
[BlackBlunders "X"]
[BlackAverageCentipawnLoss "X.X"]
[WhiteBrilliantMoves "X"]
[BlackBrilliantMoves "X"]
- Exit with clear error messages for corrupt PGN files
- Validate PGN structure before beginning analysis
- Retry engine communication up to 3 times on failure
- Exit with appropriate error message if engine fails to respond within configured time
- Provide clear error messages for engine initialization failures
- Implement tiered logging (info, debug, trace)
- Log engine communication details at trace level
- Log analysis progress at info level
- Log errors at all levels
- PGN Parser: Read and validate PGN files
- UCI Interface: Communicate with the chess engine
- Analysis Engine: Coordinate analysis and evaluation
- PGN Annotator: Add annotations to PGN based on analysis
- Command-line Interface: Parse flags and handle user input
- Logger: Handle logging at different levels
- Read PGN from file
- Parse PGN into internal representation
- Initialize and configure chess engine
- For each position, send position to engine and collect evaluation
- Process evaluations to identify move quality
- Generate annotations and statistics
- Output annotated PGN
- PGN parsing and validation
- UCI communication protocol
- Move evaluation and classification
- Annotation generation
- Command-line argument parsing
- End-to-end processing of sample PGN files
- Testing with different engines
- Testing with various flag combinations
- Verify analysis quality against known benchmarks
- Compare output to Lichess analysis for consistency
- Opening theory recognition
- Move range/position-specific analysis
- Performance metrics output
- Win probability percentage
- Export to CSV or other formats
- Support for chess variants
- Batch processing of multiple files
- Implement UCI communication with Stockfish
- Build PGN parsing and annotation
- Implement move evaluation and classification
- Add summary statistics
- Develop logging and error handling
- Create progress visualization
- Optimize performance
This specification provides a comprehensive guide for developing a Go application that analyzes chess games using the Stockfish engine and outputs annotated PGN files with detailed analysis.