]> git.sesse.net Git - stockfish/commitdiff
Promotion piece must be empty if is not a promotion
authorMarco Costalba <mcostalba@gmail.com>
Sun, 22 May 2011 07:35:14 +0000 (08:35 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 22 May 2011 07:48:19 +0000 (08:48 +0100)
Add a new check in  move_is_legal()

Avoid useless casting in move.h while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/move.h
src/position.cpp

index 299379e2003b57f8375435e90e7fbf7059148ff5..8c5ce22acc33154d1d0986a78f145c42365c68bf 100644 (file)
@@ -130,7 +130,7 @@ inline T pick_best(T* curMove, T* lastMove)
 
 
 inline Square move_from(Move m) {
 
 
 inline Square move_from(Move m) {
-  return Square((int(m) >> 6) & 0x3F);
+  return Square((m >> 6) & 0x3F);
 }
 
 inline Square move_to(Move m) {
 }
 
 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) {
 }
 
 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) {
 }
 
 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) {
 }
 
 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) {
 }
 
 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) {
 }
 
 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) {
 }
 
 inline bool move_is_ok(Move m) {
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);
 
   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 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
       return false;
 
   // The destination square cannot be occupied by a friendly piece