Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Where Centipawn Loss Misranks Human Difficulty: A Theme-Segmented Analysis of Chess Mistakes

Author: Sushanth Kamabathula (@sushanth-dev)
Full Research Paper: PAPER.md
Application Companion: Kanso Chess (kansochess.app)

This repository contains the complete research paper, replication code, and sampled datasets for an empirical study examining whether chess engine centipawn loss corresponds to human solve difficulty across 5,000 Lichess positions. Everything needed to reproduce the reported figures and tables from the public Lichess puzzle database is included.


Requirements

Component Version Notes
Python 3.11 or newer Managed by uv
Stockfish 19 (released 5 September 2026) Tagged stable release, not a development build
zstd any Only needed to decompress the Lichess database dump

The Stockfish version matters. Evaluations differ between major releases, so a run against a different version will not reproduce the reported figures. Check what you have with:

stockfish --help | head -1

If it does not report 19, download the tagged release from github.com/official-stockfish/Stockfish/releases/tag/sf_19 and point the scripts at that binary (step 2 takes the engine path as its third argument). Stockfish 19 ships universal binaries that auto-detect CPU features, so there is no architecture choice to make.


Setup

git clone https://github.com/sushanth-dev/centipawn-difficulty.git
cd centipawn-difficulty
uv venv
uv pip install -r requirements.txt

uv run uses the project's .venv automatically — there is no activation step in new terminals.

No uv? The standard path works too:

python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt

Then drop the uv run prefix from every command below.

Engine and decompression tools (macOS, Homebrew):

brew install stockfish zstd

Data

The Lichess puzzle database is not committed here — it is several gigabytes and is publicly available under CC0. Download and decompress it into data/:

curl -O https://database.lichess.org/lichess_db_puzzle.csv.zst
zstd -d lichess_db_puzzle.csv.zst -o data/lichess_db_puzzle.csv

Pipeline

Run in order. Step 2 is the long one — a few hours on a laptop.

# 1. Apply inclusion criteria and draw the fixed-seed sample
uv run python build_sample.py data/lichess_db_puzzle.csv data/sample.csv

# 2. Evaluate every position with Stockfish (slow; the engine binary is the
#    third argument, see the Requirements table)
uv run python run_engine.py data/sample.csv data/evals.csv "$(command -v stockfish)"

# 3. Correlations, theme residuals, ranking simulation
uv run python analyze.py data/sample.csv data/evals.csv results/

# 4. Table 1 - theme residuals as CSV, Markdown and LaTeX
uv run python make_table1.py results/theme_residuals.csv results/

# 5. Figure 1 - theme residuals with 95% CIs, as PNG and JPEG
uv run python make_figure1.py results/table1_full.csv results/

The scripts in tests/ re-check the diagnostics reported in the paper (clamp saturation, the zero-loss records, the tercile correlations). Run any of them from the repo root, e.g. uv run python tests/check_zero_cpl.py.

Step 2 records the search depth actually reached for each position. The median and interquartile range it reports are the depth statistics quoted in the Methods section.


Results

All figures below are read from results/results.json and results/theme_residuals.csv, which are committed so the numbers can be checked without rerunning anything. Every figure uses the full sample (n = 5,000).

  • Centipawn loss vs. human difficulty: Spearman rho = -0.064 (95% CI -0.092 to -0.037, p = 5.2e-06). The correlation is effectively zero - centipawn loss alone carries little signal about how hard humans find a position.
  • Solution-sequence length: Spearman rho = 0.315 (p = 3.2e-115) against rating - a much stronger baseline predictor that needs no engine at all.
  • Ranking simulation: when a solver is offered the 10 of 20 puzzles ranked highest by centipawn loss, the overlap with the 10 hardest by rating averages 4.75 (95% CI 4.728 to 4.772), against 5.0 expected for a chance ordering. A centipawn-loss ranking is no better than random at surfacing human difficulty.
  • Search depth: median 24.5 plies, IQR 21.0-32.0 - the depth statistics quoted in the Methods section.
  • Theme residuals (themes with n >= 50): residuals span from -276.6 rating points for mate-in-1 / one-move puzzles to +247.7 for quiet moves. The largest human-difficulty surprises are not the biggest evaluation swings.

Fixed parameters

Every value below was fixed before analysis and is stated in the manuscript's Methods section. This table is here so a reader can check the code against the claims without reading the code.

Sampling

Parameter Value
Source Lichess puzzle database (CC0)
Minimum attempts per position 1,000
Maximum rating deviation 80
Sample size N = 5,000
Random seed 20260919 (SEED in build_sample.py)

Engine

Parameter Value
Engine Stockfish 19 (5 September 2026), tagged release
Search limit 2,000,000 nodes per position (fixed nodes, not time)
Threads 1 per engine process
Hash 256 MB
MultiPV 1

Single-threaded search is a determinism requirement, not a performance choice: multi-threaded Stockfish distributes work across threads whose relative timing varies between runs, so the same position at the same node limit can return different evaluations. Throughput comes from running several single-threaded processes on separate positions concurrently.

Severity measures

Parameter Value
Primary measure Centipawn loss (eval before mistake − eval after, from the mover's perspective)
Clamp ±1000 centipawns
Forced mates Retained, assigned the clamp boundary
Secondary measure Expected-score drop, using the Lichess transform

Expected-score transform:

expected score (%) = 50 + 50 × (2 / (1 + exp(−0.00368208 × centipawns)) − 1)

The secondary measure requires no clamp (a forced mate maps to an expected score of 1) and serves as a robustness check on the clamp threshold.

Analysis

Parameter Value
Correlation Spearman rank
Confidence intervals Bootstrap, 10,000 replicates, 95%
Theme residuals Observed difficulty − difficulty predicted from centipawn loss, aggregated by tactical theme
Alternative predictor Solution sequence length
Ranking simulation Top-of-list overlap between centipawn-loss ordering and human-difficulty ordering

Outputs

Path Contents
data/sample.csv The sampled record identifiers — the exact 5,000 positions analysed
data/evals.csv Per-position engine output: evaluations, centipawn loss, depth reached
results/results.json Headline figures: correlations, confidence intervals, depth statistics, ranking overlap
results/theme_residuals.csv Mean residual, 95% CI and n for each tactical theme
results/merged.csv Sample joined to evaluations — the analysis table
results/table1_main.{csv,md,tex} Table 1, top/bottom 10 themes as data, Markdown and LaTeX
results/table1_full.{csv,md,tex} Table 1, every theme with n >= 50 in all three formats
results/figure1.{png,jpg} Figure 1, mean residual by theme with bootstrap 95% CIs (no title or caption, per JHSS)

data/sample.csv and data/evals.csv are committed. Committing the evaluations means the analysis can be rerun in seconds without repeating the engine run.


Repository layout

centipawn-difficulty/
├── README.md
├── PAPER.md
├── LICENSE
├── requirements.txt
├── .gitignore
├── build_sample.py
├── run_engine.py
├── analyze.py
├── make_table1.py
├── make_figure1.py
├── tests/
│   ├── check_clamp_saturation.py
│   ├── check_cpl_terciles.py
│   └── check_zero_cpl.py
├── data/
│   ├── sample.csv
│   └── evals.csv
└── results/
    ├── results.json
    ├── theme_residuals.csv
    ├── merged.csv
    ├── table1_{main,full}.{csv,md,tex}
    └── figure1.{png,jpg}

Licence

Code is released under the MIT Licence (see LICENSE). Derived data in data/ and results/ is released under CC0, matching the licence of the underlying Lichess puzzle database.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages