From d2fdbb23bb56d9e06b1f11623c6475e6928f98e1 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 18 Aug 2026 12:08:20 +0200 Subject: fix(book): fixing critical castling bug --- src/book.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/book.cpp b/src/book.cpp index abf9693..2d499ca 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -81,6 +81,18 @@ static uint16_t PolyglotToMono(uint16_t polyglotMove) { uint8_t from = (polyglotMove >> 6) & 63; uint8_t promo = (polyglotMove >> 12) & 7; + // Polyglot encodes castling as king moving to the rook's square. + // Convert to king-moves-two-squares form that the engine expects. + if (from == 4 && to == 7) { + to = 6; // white kingside: e1h1 -> e1g1 + } else if (from == 4 && to == 0) { + to = 2; // white queenside: e1a1 -> e1c1 + } else if (from == 60 && to == 63) { + to = 62; // black kingside: e8h8 -> e8g8 + } else if (from == 60 && to == 56) { + to = 58; // black queenside: e8a8 -> e8c8 + } + PieceType promotion = NONEPIECE; switch (promo) { case 0: -- cgit v1.2.3