Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/CYHSM/chess-surprise-analysis
Find surprising moves in chess games
https://github.com/CYHSM/chess-surprise-analysis
Last synced: 2 months ago
JSON representation
Find surprising moves in chess games
- Host: GitHub
- URL: https://github.com/CYHSM/chess-surprise-analysis
- Owner: CYHSM
- License: mit
- Created: 2016-11-01T16:23:52.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-12-16T22:11:02.000Z (about 4 years ago)
- Last Synced: 2024-08-04T04:04:33.403Z (6 months ago)
- Language: Jupyter Notebook
- Homepage:
- Size: 15.1 MB
- Stars: 177
- Watchers: 18
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- starred-awesome - chess-surprise-analysis - Find surprising moves in chess games (Python)
README
[![Build Status](https://travis-ci.org/CYHSM/chess-surprise-analysis.svg?branch=master)](https://travis-ci.org/CYHSM/chess-surprise-analysis)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/CYHSM/chess-surprise-analysis/blob/master/LICENSE.md)
![py35 status](https://img.shields.io/badge/python3.5-supported-green.svg)# Update on Lichess bullet marathon
Unrelated to surprising moves, but related to chess evaluations: [Magnus Carlsen vs. Alireza Firouzja](https://github.com/CYHSM/chess-surprise-analysis/blob/master/csa/examples/alireza_carlsen/alireza_carlsen.md)
# Update on Alpha Zero
All reanalysis of the Alpha Zero vs. Stockfish games can now be found [here](https://github.com/CYHSM/chess-surprise-analysis/tree/master/media/alphazero)
When looking at specific chess games from grandmasters there sometimes comes a point in the game where a lot of people
wonder about a horrible looking move (mostly a sacrifice of a high valued piece) and why it was played this way.Analysing these games with an engine (usually) reveals the genius behind these moves and the advantage this move offers, but from the engine's perspective this move was not *surprising* at all.
This repository implements a Surprise Analysis of Chess Games. The key concept is to compare the evaluations of a chess engine in low depths with the evaluation at high depths, with the idea that a low depth engine may represent a naive observer of the game. It uses the open-source engine [Stockfish](https://stockfishchess.org/) in combination with the [python-chess library](https://github.com/niklasf/python-chess).
## Example Usage
```python
# Load Game from PGN
path_to_pgn = 'wei_yi_bruzon_batista_2015.pgn'
chess_game = csa.load_game_from_pgn(path_to_pgn)
# Evaluate Game
cp, nodes = csa.evaluate_game(chess_game, bln_reset_engine=True,
halfmove_numbers=None, depths=range(1, 35),
verbose=1, async_callback=True)
# Save cp
csa.save_evaluation(cp, nodes, depths, True,
True, 'wei_yi_bruzon_batista_2015')
# Plot heatmap
csa.plot_cp(cp, fn='wei_yi_bruzon_batista_2015.svg', save=True)# Find surprising moves
ss_df, infos = csa.analyse_evaluations(cp, low=12, high=22)
```I evaluated Garry Kasparov's immortal game against Veselin Topalov until depth 32. In this game Kasparov was trailing a bit and in the following position Kasparov decided to go play Rxd4.
Here is a heatmap showing the centipawn evaluation until depth 32. The y-axis has increasing depth values from bottom to top and the x-axis contains the halfmove numbers from left to right. Colors represent the truncated evaluation in centipawns. Surprising moves are characterised as having a different evaluation for low depths in relation to high depths (see blue parts down and red top, around move 48).
## Example 2
The game of Wei Yi playing against Bruzon Batista in 2015. See red parts on top after move 41.
## Limitations
* Using a synchronous calculating approach for each depth will lead to continuous evaluations but with a worse run-time. It can also lead to a high variance in the evaluations at depths < 10.
* Using an asynchronous approach where missing evaluations are filled with the values before and after makes the evaluation much faster. Also missing evaluations are unlikely at depths > 10.