Skip to content

davidADSP/chess-trap-scorer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Chess Trap Scorer
· Report Bug · Request Feature


Table of Contents

  1. About The Project
  2. Getting Started
  3. License
  4. Contact
  5. Acknowledgements


About The Project

Stafford Gambit

This project allows you to score trappy chess openings, based on two factors:

🎲 Probability

How likely is the player to play the next move in the trap sequence?

A good trap should have a high likelihood that the next move in sequence is commonly chosen.

😵 Potency

How likely is the player to lose after they have fallen into the trap?

A good trap should be deadly once your opponent has fallen into it!


🎯 Trap score

The trap score for a given pgn input is the product of these two scores.

For more information, see the accompanying blog post.

Have fun!


Getting Started

To get a local copy up and running, follow these simple steps.

Installation

  1. Clone the repo
    git clone https://github.com/davidADSP/chess-trap-scorer.git
    cd chess-trap-scorer
  2. Pip install requirements (inside a virtual environment)
    pip install -r requirements.txt

Quickstart

To score a given opening, simply use the following command, with the pgn of your choice.

python3 solver.py --pgn '1. e4 e5 2. Nf3 Nf6 3. Nxe5 Nc6 4. Nxc6 dxc6 5. d3 Bc5 6. Bg5'

The lichess opening API is used to gather data for the analysis. No token is required.

The config.py file allows you to change the variant, speeds and rating range of the analysis, as well as the number of moves to search over to find the best follow up move and the alpha of the potency confidence interval.

Output

The output is the following summary (shown here with descriptive labels):

Black to play <- The colour of the player who will take advantage of the trap
Total moves:	 6 <- Number of moves played by the opponent
	e4:	        64.02% <- The likelihood that the opponent plays this required move
	Nf3:	    66.17%
	Nxe5:	    34.16%
	Nxc6:	    84.17%
	d3:	        38.70%
	Bg5:	    14.63%
Likelihood:	    0.69% <- The product of the likelihoods
Frequency:	    Every 145 games <- 1 / likelihood
Av Move Prob:   43.63% <- Geometric mean of the move probabilities

Continuation:	Nxe4 <- Best move that takes advantage of the trap
Total games:	1670 <- Number of lichess games where this move has been played
Shock:		    +43.21% (52.42% -> 95.63%) <- The delta of the win likelihood before and after this move
Potency:	    95.63% CI ['94.65%', '96.61%'] (95%) <- The % chance of winning after this move with confdience interval

Trap Score:		    41.72% ( = 43.63% * 95.63% ) <- the product of the Av Move Prob and Potency

The higher the trap score, the better the trap!

Jupyter notebook

A jupyter notebook traps.ipynb is also provided, where a view of the board is also rendered.


License

Distributed under the MIT License. See LICENSE for more information.


Contact

David Foster - @davidADSP - david@adsp.ai

Project Link: https://github.com/davidADSP/chess-trap-scorer


Acknowledgements

Thanks to all the great chess content creators out there - here's three of the best:


About

A Python codebase for scoring trappy chess openings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published