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

chess-why3

Starter workspace to build a chess engine in WhyML (Why3), then evaluate it with engine-vs-engine matches and an Elo estimate.

What is already included

  • A minimal WhyML engine core in src/whyml/engine.mlw:
    • board representation
    • pseudo-legal move generation (no castling / en-passant / check legality filtering yet)
    • material evaluation
    • alpha-beta negamax search
  • A benchmark pipeline in Python:
    • scripts/run_elo_benchmark.py
    • scripts/estimate_elo_from_pgn.py
    • scripts/elo_utils.py
  • A runnable UCI engine path from WhyML:
    • extraction + build script: scripts/build_whyml_uci.sh
    • OCaml UCI adapter: src/uci_ocaml/main.ml
    • Dune config: dune-project, src/uci_ocaml/dune
  • The benchmark pipeline runs matches with cutechess-cli and estimates Elo against Stockfish configured with UCI_LimitStrength=true and UCI_Elo=<level>.

Current limitations (engine)

This WhyML engine is intentionally small and not tournament-ready yet:

  • no castling
  • no en-passant
  • no check/checkmate legality filter
  • promotion currently defaults to queen
  • no transposition table, no quiescence, no advanced evaluation

It is a solid base to iterate with verification and incremental strength improvements.

Prerequisites

  • Python 3.10+
  • cutechess-cli
  • stockfish
  • Why3 toolchain (for the WhyML part)

On this machine, cutechess-cli and stockfish are available, while why3 must be installed.

Quick smoke benchmark (already runnable)

Example: run a short sanity check where a weakened Stockfish (as placeholder for your future WhyML engine UCI binary) plays against nearby Stockfish Elo levels.

python3 scripts/run_elo_benchmark.py \
  --engine-name test-sf1300 \
  --engine-cmd /opt/homebrew/bin/stockfish \
  --engine-option UCI_LimitStrength=true \
  --engine-option UCI_Elo=1300 \
  --levels 1320 \
  --games-per-level 2 \
  --tc st=0.1 \
  --tag smoke

Outputs are written under results/:

  • PGN files for each level
  • *-summary.json
  • *-summary.md

To estimate Elo from an existing PGN:

python3 scripts/estimate_elo_from_pgn.py \
  --pgn results/some-match.pgn \
  --engine-name whyml-engine \
  --opponent-rating 1400

Benchmark your own engine

Once you have a UCI executable for your WhyML-based engine:

python3 scripts/run_elo_benchmark.py \
  --engine-name whyml-engine \
  --engine-cmd /absolute/path/to/your_uci_engine \
  --levels 1320,1500,1700 \
  --games-per-level 40 \
  --tc 40/15+0.05 \
  --tag whyml-v1

Note: Stockfish 18 exposes UCI_Elo bounds 1320..3190; lower requested levels are clamped.

For less optimistic and slower runs, disable adjudication shortcuts:

python3 scripts/run_elo_benchmark.py \
  --engine-name whyml-engine \
  --engine-cmd /absolute/path/to/your_uci_engine \
  --levels 1320,1400 \
  --games-per-level 40 \
  --tc 3+0.05 \
  --concurrency 1 \
  --disable-draw-adjudication \
  --disable-resign-adjudication \
  --tag whyml-strict

Build and run the WhyML-derived UCI engine

Build executable:

make build-uci

Run UCI smoke test:

make uci-smoke

Quick Elo run:

make elo-quick

Binary path:

  • build/whyml_uci_engine

WhyML workflow (recommended)

  1. Model and verify core invariants in WhyML (src/whyml/engine.mlw split into modules later).
  2. Extract to OCaml (why3 extract) for execution performance.
  3. Build a thin OCaml UCI adapter that:
    • translates UCI position/move strings into your extracted engine state,
    • calls search,
    • prints bestmove ....
  4. Benchmark with scripts/run_elo_benchmark.py.

Suggested next steps

  • Add full legal move generation and check detection first.
  • Add perft tests before deepening search.
  • Add iterative deepening + aspiration windows + TT.
  • Add simple opening suite and fixed random seed for reproducible Elo runs.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages