Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LeanChess

A small chess engine written in Lean 4, with:

  • FEN parsing
  • Legal move generation
  • Alpha-beta search with move ordering
  • Quiescence search, iterative deepening, and a transposition table
  • A UCI interface (so you can test it vs other engines)
  • A perft executable for basic correctness checks

Build

  1. Install Lean 4 + Lake (recommended: elan).
  2. Build:
lake build

Run (UCI)

./.lake/build/bin/leanchess

You can plug it into any UCI-compatible GUI, or run automated matches with tools like cutechess-cli.

Perft (sanity check)

./.lake/build/bin/perft 4

Expected for start position:

  • depth 1: 20
  • depth 2: 400
  • depth 3: 8902
  • depth 4: 197281

Elo testing (practical workflow)

  1. Make the engine speak UCI (this repo already does).
  2. Pick a reference engine with an Elo limiter (easy option: Stockfish with UCI_LimitStrength + UCI_Elo).
  3. Run a match (example with cutechess-cli):
cutechess-cli \
  -engine cmd=./.lake/build/bin/leanchess name=LeanChess proto=uci \
  -engine cmd=stockfish name=SF proto=uci option.UCI_LimitStrength=true option.UCI_Elo=1320 \
  -each tc=10+0.1 \
  -games 200 -rounds 1 -pgnout results.pgn

Then adjust option.UCI_Elo=... until you get ~50% score; that gives a rough “Stockfish-limited Elo equivalent”.

For tighter estimates, run more games (e.g. 500–2000) and/or use a proper Elo tool (BayesElo/ordo) on the PGN.

Helper script

This repo includes scripts/run_match_and_elo.sh to run matches and summarize Elo directly from PGNs.

Run match + summary:

scripts/run_match_and_elo.sh --games 300 --tc 10+0.1 --anchor-elo 1320

Summarize an existing PGN:

scripts/run_match_and_elo.sh --summary-only \
  --pgn matches/match-20260210-090000.pgn \
  --target-name LeanChess \
  --anchor-name Stockfish \
  --anchor-elo 1320

Notes:

  • In run mode, the script overwrites an existing --pgn file by default. Use --append-pgn to keep old games.
  • By default, Elo summary excludes very short games (PlyCount < 6) and time-forfeit/abandoned games.
  • For more reliable strength estimates, prefer at least --tc 10+0.1 (or slower) and start with 40-80 games, then scale up.
  • By default, match runs use matches/openings-mini.pgn with random paired openings to reduce white/black and opening bias.
  • Use --seed N for reproducible randomized opening order, or --no-openings to disable opening randomization.
  • To diagnose raw search strength separately from clock effects, use fixed-depth mode (--engine-depth N).
  • Current engine settings prioritize speed and stable match execution (notably for fixed-depth runs), so use timed mode (--tc ... without fixed depth) for the main Elo estimate and use fixed-depth runs as quick smoke checks.

Show all options:

scripts/run_match_and_elo.sh --help

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages