Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cplusplus-chess

A small C++ chess engine project (UCI) with a perft test harness.

Build

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

Run (UCI)

./build/cplusplus_chess

Try (in the engine console):

uci
isready
position startpos moves e2e4 e7e5
go depth 6

Perft

CLI:

./build/cplusplus_chess --perft startpos 5
./build/cplusplus_chess --perft "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1" 4

Or via UCI (custom command):

perft 5

Elo testing (recommended tooling)

For meaningful Elo estimates, use a dedicated match runner (e.g. cutechess-cli or fastchess) and an Elo calculator (e.g. Ordo).

Typical workflow:

  1. Build this engine (cplusplus_chess) and at least one opponent engine (e.g. Stockfish with strength limited via UCI_LimitStrength / UCI_Elo).
  2. Run a match at a fixed time control (or fixed depth) with enough games (often 200–2000+).
  3. 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).

cutechess-cli (script)

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.sh

The 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).

Quick Elo difference estimate (built-in)

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 50

Notes:

  • 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.

Weight tuning pipeline

Detailed explanation of what "weights" are and how tuning works is in:

  • docs/tuning_pipeline.md

One-command pipeline

Run:

bash tools/tuning/run_pipeline.sh

This pipeline will:

  1. Build binaries.
  2. Generate training FEN positions using uci_match and both engines.
  3. Label positions with Stockfish scores.
  4. Extract eval feature vectors (build/eval_dataset).
  5. 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_MS control position generation volume/quality.
  • MAX_POSITIONS caps dataset size.
  • GEN_SF_ELO optionally limits Stockfish while generating positions.
  • LABEL_DEPTH controls label quality.
  • TUNE_RIDGE and TUNE_MAX_DELTA control tuning conservativeness.
  • WEIGHTS_HEADER overrides candidate output path (set to src/eval_tuned_weights.h only 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages