X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbook.cpp;h=85a88fcb801e3499376d3038a8087bebbc2bdc4f;hp=9528e47c8c9e99c383e22838371723f9e1a09e6f;hb=d9b96f0e492583bfb461e7e3c9510ddeae1e3fce;hpb=97a6e1559e78dd31a5ecec9f3b35181f82942823 diff --git a/src/book.cpp b/src/book.cpp index 9528e47c..85a88fcb 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -30,6 +30,7 @@ //// #include +#include #include "book.h" #include "movegen.h" @@ -434,11 +435,27 @@ Move Book::get_move(const Position& pos, bool findBestMove) { if (!bookMove) return MOVE_NONE; + // A PolyGlot book move is encoded as follows: + // + // bit 0- 5: destination square (from 0 to 63) + // bit 6-11: origin square (from 0 to 63) + // bit 12-13-14: promotion piece (from KNIGHT == 1 to QUEEN == 4) + // + // Castling moves follow "king captures rook" representation. So in case + // book move is a promotion we have to convert to our representation, in + // all other cases we can directly compare with a Move after having + // masked out special Move's flags that are not supported by PolyGlot. + int p = (bookMove >> 12) & 7; + + if (p) + bookMove = int(make_promotion_move(move_from(Move(bookMove)), + move_to(Move(bookMove)), PieceType(p + 1))); + // Verify the book move is legal MoveStack mlist[MOVES_MAX]; - MoveStack* last = generate_moves(pos, mlist); + MoveStack* last = generate(pos, mlist); for (MoveStack* cur = mlist; cur != last; cur++) - if ((int(cur->move) & 07777) == bookMove) + if ((int(cur->move) & ~(3 << 14)) == bookMove) // Mask out special flags return cur->move; return MOVE_NONE;