Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

chess-java

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.

1) Build and run

Requirements:

  • Java JDK 11+
  • cutechess-cli (for matches)
  • A reference engine binary (for example Stockfish)

Build:

./scripts/build.sh

Run UCI engine:

./scripts/run_engine.sh

run_engine.sh behavior:

  • terminal mode (tty): interactive uci> prompt for manual testing.
  • pipeline/tool mode: raw UCI protocol mode.
  • force raw mode manually:
./scripts/run_engine.sh --raw

Main class: com.example.chess.UciMain

2) Validate move generation (perft)

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: 197281

Additional 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: 62379

If you need move-by-move perft breakdown:

java -cp build/classes com.example.chess.PerftMain 3 "<fen>" divide

3) Run matches

Generic opponent

./scripts/run_match.sh "/path/to/opponent_engine" 40 "40/5+0.05"

Arguments:

  • opponent_cmd (required)
  • games (even number, default 40)
  • tc (default 40/5+0.05)
  • optional output PGN path

Stockfish at fixed Elo (similar-level sparring)

./scripts/run_stockfish_match.sh /path/to/stockfish 1500 40 "40/5+0.05"

This uses UCI options:

  • UCI_LimitStrength=true
  • UCI_Elo=<value>

Recommended calibration loop:

  1. Start with broad levels in your Stockfish-supported range (common min is 1320), e.g. 1320, 1520, 1720, 1920.
  2. Run 40-80 games per level.
  3. Keep levels where your score is around 40-60%.
  4. 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.

4) Estimate Elo difference

Given a PGN generated by the scripts:

./scripts/estimate_elo.py build/matches/your_match.pgn --engine-name JavaBaselineEngine

Machine-readable output:

./scripts/estimate_elo.py build/matches/your_match.pgn --engine-name JavaBaselineEngine --tsv

Output includes:

  • W/D/L,
  • score percentage,
  • estimated Elo difference (engine - opponent),
  • approximate 95% confidence interval,
  • LOS (likelihood engine is stronger).

5) What this baseline engine currently implements

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

6) Next steps to increase strength

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages