A small C++ chess engine project (UCI) with a perft test harness.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j./build/cplusplus_chessTry (in the engine console):
uci
isready
position startpos moves e2e4 e7e5
go depth 6
CLI:
./build/cplusplus_chess --perft startpos 5
./build/cplusplus_chess --perft "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1" 4Or via UCI (custom command):
perft 5
For meaningful Elo estimates, use a dedicated match runner (e.g. cutechess-cli or fastchess) and an Elo calculator (e.g. Ordo).
Typical workflow:
- Build this engine (
cplusplus_chess) and at least one opponent engine (e.g. Stockfish with strength limited viaUCI_LimitStrength/UCI_Elo). - Run a match at a fixed time control (or fixed depth) with enough games (often 200–2000+).
- Feed the PGN/results to an Elo tool to get an estimate and confidence interval.
This engine supports both go movetime ... and clock-based go wtime/btime/winc/binc ... (so it works with real time controls in match managers).
If you have cutechess-cli and Stockfish in your PATH, you can run a match like:
# 200 games at 10+0.1, Stockfish limited to ~2000 via UCI_Elo
SF_ELO=2000 GAMES=200 TC=10+0.1 bash tools/run_cutechess.sh
# Longer / more accurate (takes much longer)
SF_ELO=2200 GAMES=1000 TC=60+0.6 bash tools/run_cutechess.shThe script uses tools/openings.pgn and writes a PGN to build/cutechess.pgn by default.
It rebuilds the engine by default; set SKIP_BUILD=1 to skip rebuilding.
By default it also forces Stockfish to Threads=1 (override with SF_THREADS=...).
Set SRAND=... to make the opening order deterministic (useful for A/B comparisons).
This repo also builds a tiny match runner on macOS/Linux: uci_match. It plays engine-vs-engine games (UCI), then prints an Elo difference estimate (engineA – engineB) for the chosen settings.
Examples:
# Fixed depth match (engineA vs engineB)
./build/uci_match --engineA ./build/cplusplus_chess --engineB /path/to/stockfish --games 200 --depth 8
# Fixed movetime match (50ms per move)
./build/uci_match --engineA ./build/cplusplus_chess --engineB /path/to/stockfish --games 200 --movetime 50
# Limit Stockfish strength (UCI options), then compare
./build/uci_match \
--engineA ./build/cplusplus_chess \
--engineB /path/to/stockfish \
--optionB UCI_LimitStrength=true \
--optionB UCI_Elo=1600 \
--games 200 \
--movetime 50Notes:
- Elo is relative to the opponent, hardware, and time control; it is not portable between setups.
- For serious testing (larger opening books, adjudication, better statistics), prefer
cutechess-cli/fastchess+ Ordo.
Detailed explanation of what "weights" are and how tuning works is in:
docs/tuning_pipeline.md
Run:
bash tools/tuning/run_pipeline.shThis pipeline will:
- Build binaries.
- Generate training FEN positions using
uci_matchand both engines. - Label positions with Stockfish scores.
- Extract eval feature vectors (
build/eval_dataset). - Fit tuned weights and write a candidate header at
build/tuning/eval_tuned_weights_candidate.h(it does not auto-apply).
Main knobs:
GEN_GAMES/GEN_MOVETIME_MScontrol position generation volume/quality.MAX_POSITIONScaps dataset size.GEN_SF_ELOoptionally limits Stockfish while generating positions.LABEL_DEPTHcontrols label quality.TUNE_RIDGEandTUNE_MAX_DELTAcontrol tuning conservativeness.WEIGHTS_HEADERoverrides candidate output path (set tosrc/eval_tuned_weights.honly when you want direct apply).
After tuning:
# optional: apply candidate weights
cp build/tuning/eval_tuned_weights_candidate.h src/eval_tuned_weights.h
cmake --build build -j
SF_ELO=2350 GAMES=200 TC=60+0.6 bash tools/run_cutechess.sh