From: Marco Costalba Date: Sun, 22 May 2011 07:35:14 +0000 (+0100) Subject: Promotion piece must be empty if is not a promotion X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=90e83fa879ccdba066962ad0a9aa5be7c4cd1956 Promotion piece must be empty if is not a promotion Add a new check in move_is_legal() Avoid useless casting in move.h while there. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/move.h b/src/move.h index 299379e2..8c5ce22a 100644 --- a/src/move.h +++ b/src/move.h @@ -130,7 +130,7 @@ inline T pick_best(T* curMove, T* lastMove) inline Square move_from(Move m) { - return Square((int(m) >> 6) & 0x3F); + return Square((m >> 6) & 0x3F); } inline Square move_to(Move m) { @@ -162,23 +162,23 @@ inline bool move_is_long_castle(Move m) { } inline PieceType move_promotion_piece(Move m) { - return move_is_promotion(m) ? PieceType(((int(m) >> 12) & 3) + 2) : PIECE_TYPE_NONE; + return PieceType(((m >> 12) & 3) + 2); } inline Move make_move(Square from, Square to) { - return Move(int(to) | (int(from) << 6)); + return Move(to | (from << 6)); } inline Move make_promotion_move(Square from, Square to, PieceType promotion) { - return Move(int(to) | (int(from) << 6) | ((int(promotion) - 2) << 12) | (1 << 14)); + return Move(to | (from << 6) | ((promotion - 2) << 12) | (1 << 14)); } inline Move make_ep_move(Square from, Square to) { - return Move(int(to) | (int(from) << 6) | (2 << 14)); + return Move(to | (from << 6) | (2 << 14)); } inline Move make_castle_move(Square from, Square to) { - return Move(int(to) | (int(from) << 6) | (3 << 14)); + return Move(to | (from << 6) | (3 << 14)); } inline bool move_is_ok(Move m) { diff --git a/src/position.cpp b/src/position.cpp index b254d60b..9e5f60a5 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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