diff options
| author | Adam <adammegarules1@gmail.com> | 2026-08-18 12:27:29 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-08-18 12:27:29 +0200 |
| commit | 56cbe07135f1b235747ea90f7308948fdd08abd0 (patch) | |
| tree | 61b187eedc541c2e805a9ece2bd5b198e3145b30 | |
| parent | d2fdbb23bb56d9e06b1f11623c6475e6928f98e1 (diff) | |
fix(book): making engine turn caslting moves into uci perpesentation only if there is a king
| -rw-r--r-- | src/book.cpp | 28 | ||||
| -rw-r--r-- | src/book.hpp | 3 | ||||
| -rw-r--r-- | src/bot.cpp | 2 |
3 files changed, 17 insertions, 16 deletions
diff --git a/src/book.cpp b/src/book.cpp index 2d499ca..900f94a 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -76,21 +76,21 @@ void InitBook(const std::string &path) { std::cerr << "info string " << path << ": " << book.size() << " entries\n"; } -static uint16_t PolyglotToMono(uint16_t polyglotMove) { +static uint16_t PolyglotToMono(uint16_t polyglotMove, const Game &g) { uint8_t to = polyglotMove & 63; 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 + if (g.pieces[from].type == KING) { + 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; @@ -114,7 +114,7 @@ static uint16_t PolyglotToMono(uint16_t polyglotMove) { return CreateMove(from, to, promotion); } -std::optional<uint16_t> ProbeBook(uint64_t key) { +std::optional<uint16_t> ProbeBook(uint64_t key, const Game &g) { if (book.empty()) { return {}; } @@ -147,9 +147,9 @@ std::optional<uint16_t> ProbeBook(uint64_t key) { for (const auto *e : matches) { r -= e->weight; if (r < 0) { - return PolyglotToMono(e->move); + return PolyglotToMono(e->move, g); } } - return PolyglotToMono(matches.back()->move); + return PolyglotToMono(matches.back()->move, g); } diff --git a/src/book.hpp b/src/book.hpp index bc08782..4b0eb88 100644 --- a/src/book.hpp +++ b/src/book.hpp @@ -1,7 +1,8 @@ #pragma once +#include "board/board.hpp" #include <cstdint> #include <optional> #include <string> void InitBook(const std::string &path); -std::optional<uint16_t> ProbeBook(uint64_t key);
\ No newline at end of file +std::optional<uint16_t> ProbeBook(uint64_t key, const Game &g);
\ No newline at end of file diff --git a/src/bot.cpp b/src/bot.cpp index 99f60aa..e9b0b4d 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -325,7 +325,7 @@ uint16_t GetBestMove(Game *b, int maxDepth, move_options options) { uint64_t hash = GenerateZobristKey(b); if (b->MoveClock <= BOOK_DEPTH) { - std::optional<uint16_t> bookMove = ProbeBook(hash); + std::optional<uint16_t> bookMove = ProbeBook(hash, *b); if (bookMove.has_value()) { return bookMove.value(); } |
