- // 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 (if any) is legal
- MoveStack mlist[MOVES_MAX];
- MoveStack* last = generate<MV_LEGAL>(pos, mlist);
- for (MoveStack* cur = mlist; cur != last; cur++)
- if ((int(cur->move) & ~(3 << 14)) == bookMove) // Mask out special flags
- return cur->move;
+ // Castling moves follow "king captures rook" representation. So in case book
+ // move is a promotion we have to convert to our representation, in all the
+ // other cases we can directly compare with a Move after having masked out
+ // the special Move's flags (bit 14-15) that are not supported by PolyGlot.
+ int pt = (move >> 12) & 7;
+ if (pt)
+ move = make<PROMOTION>(from_sq(move), to_sq(move), PieceType(pt + 1));
+
+ // Add 'special move' flags and verify it is legal
+ for (MoveList<LEGAL> it(pos); *it; ++it)
+ if (move == (*it ^ type_of(*it)))
+ return *it;