Skip to content

CYHSM/chess-surprise-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status license py35 status

Update on Lichess bullet marathon

Unrelated to surprising moves, but related to chess evaluations: Magnus Carlsen vs. Alireza Firouzja

Update on Alpha Zero

All reanalysis of the Alpha Zero vs. Stockfish games can now be found here

The -What The Hell- Moment

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 in combination with the python-chess library.

Example Usage

# 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)

Example 1

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.

About

Find surprising moves in chess games

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published