A baseline chess engine in Java (UCI protocol) with a reproducible workflow to:
- build and run the engine,
- validate move legality with perft,
- run engine-vs-engine matches,
- estimate Elo difference from PGN results.
Requirements:
- Java JDK 11+
cutechess-cli(for matches)- A reference engine binary (for example Stockfish)
Build:
./scripts/build.shRun UCI engine:
./scripts/run_engine.shrun_engine.sh behavior:
- terminal mode (
tty): interactiveuci>prompt for manual testing. - pipeline/tool mode: raw UCI protocol mode.
- force raw mode manually:
./scripts/run_engine.sh --rawMain class: com.example.chess.UciMain
Start position checks:
./scripts/perft.sh 1 # expected: 20
./scripts/perft.sh 2 # expected: 400
./scripts/perft.sh 3 # expected: 8902
./scripts/perft.sh 4 # expected: 197281Additional regression positions (known perft values):
./scripts/perft.sh 3 "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1" # expected: 2812
./scripts/perft.sh 3 "r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1" # expected: 9467
./scripts/perft.sh 3 "rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8" # expected: 62379If you need move-by-move perft breakdown:
java -cp build/classes com.example.chess.PerftMain 3 "<fen>" divide./scripts/run_match.sh "/path/to/opponent_engine" 40 "40/5+0.05"Arguments:
opponent_cmd(required)games(even number, default40)tc(default40/5+0.05)- optional output PGN path
./scripts/run_stockfish_match.sh /path/to/stockfish 1500 40 "40/5+0.05"This uses UCI options:
UCI_LimitStrength=trueUCI_Elo=<value>
Recommended calibration loop:
- Start with broad levels in your Stockfish-supported range (common min is 1320), e.g. 1320, 1520, 1720, 1920.
- Run 40-80 games per level.
- Keep levels where your score is around 40-60%.
- Increase games (200+) on those levels for tighter confidence intervals.
One-command automated calibration:
./scripts/assess_elo.sh "$(command -v stockfish)" 40 "40/5+0.05" "1320,1520,1720,1920"This runs matches for each level and prints an engine Elo estimate summary.
Given a PGN generated by the scripts:
./scripts/estimate_elo.py build/matches/your_match.pgn --engine-name JavaBaselineEngineMachine-readable output:
./scripts/estimate_elo.py build/matches/your_match.pgn --engine-name JavaBaselineEngine --tsvOutput includes:
- W/D/L,
- score percentage,
- estimated Elo difference (
engine - opponent), - approximate 95% confidence interval,
- LOS (likelihood engine is stronger).
- Full legal move generation:
- castling,
- en passant,
- promotions,
- check legality filtering.
- Search:
- iterative deepening,
- alpha-beta negamax,
- quiescence search,
- simple time management from UCI clocks.
- Evaluation:
- material + piece-square tables.
This is a baseline, not an optimized top-strength engine yet.
- Add transposition table (Zobrist hash + TT entries).
- Add move ordering heuristics (history, killers, SEE).
- Add repetition/50-move draw detection in search.
- Add tapered eval (middlegame/endgame) and mobility/king safety terms.
- Add opening book and simple endgame tablebase probing.