- // Verify the book move (if any) is legal
- MoveStack mlist[MAX_MOVES];
- 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;
+ if (promotion)
+ bookMove = make_promotion_move(move_from(Move(bookMove)),
+ move_to(Move(bookMove)),
+ PieceType(promotion + 1));
+ // Verify the book move is legal
+ for (MoveList<MV_LEGAL> ml(pos); !ml.end(); ++ml)
+ if (unsigned(ml.move() & ~(3 << 14)) == bookMove) // Mask out special flags
+ return ml.move();