aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-18 12:08:20 +0200
committerAdam <adammegarules1@gmail.com>2026-08-18 12:08:20 +0200
commitd2fdbb23bb56d9e06b1f11623c6475e6928f98e1 (patch)
treee47b1646ed19e1183731e51d4d10573114b10393
parent419f931a8001ca1c8c5960d68ae6bdef53c76f16 (diff)
fix(book): fixing critical castling bug
-rw-r--r--src/book.cpp12
1 files changed, 12 insertions, 0 deletions
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: