]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Promotion piece must be empty if is not a promotion
[stockfish] / src / position.cpp
index b254d60b2020bc9632d2f20e002699d8bb4b8e98..9e5f60a545f135b5b16476d578749aca8343a44e 100644 (file)
@@ -676,9 +676,13 @@ bool Position::move_is_legal(const Move m, Bitboard pinned) const {
   if (move_is_special(m))
       return move_is_legal(m);
 
+  // Is not a promotion, so promotion piece must be empty
+  if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE)
+      return false;
+
   // If the from square is not occupied by a piece belonging to the side to
   // move, the move is obviously not legal.
-  if (color_of_piece(pc) != us)
+  if (pc == PIECE_NONE || color_of_piece(pc) != us)
       return false;
 
   // The destination square cannot be occupied by a friendly piece