]> git.sesse.net Git - stockfish/commitdiff
Add file distance condition in move_is_legal()
authorMarco Costalba <mcostalba@gmail.com>
Sun, 22 May 2011 08:35:34 +0000 (09:35 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 22 May 2011 08:49:44 +0000 (09:49 +0100)
Found another missed control in move_is_legal() thanks to
brute force testing.

No functional change.

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

index 9e5f60a545f135b5b16476d578749aca8343a44e..ceface349ef375f3359b91531cfc041e87c8389e 100644 (file)
@@ -712,16 +712,20 @@ bool Position::move_is_legal(const Move m, Bitboard pinned) const {
       case DELTA_SE:
       // Capture. The destination square must be occupied by an enemy
       // piece (en passant captures was handled earlier).
-          if (color_of_piece_on(to) != them)
-              return false;
-          break;
+      if (color_of_piece_on(to) != them)
+          return false;
+
+      // From and to files must be one file apart, avoids a7h5
+      if (abs(square_file(from) - square_file(to)) != 1)
+          return false;
+      break;
 
       case DELTA_N:
       case DELTA_S:
       // Pawn push. The destination square must be empty.
-          if (!square_is_empty(to))
-              return false;
-          break;
+      if (!square_is_empty(to))
+          return false;
+      break;
 
       case DELTA_NN:
       // Double white pawn push. The destination square must be on the fourth
@@ -731,17 +735,17 @@ bool Position::move_is_legal(const Move m, Bitboard pinned) const {
           || !square_is_empty(to)
           || !square_is_empty(from + DELTA_N))
           return false;
-          break;
+      break;
 
       case DELTA_SS:
       // Double black pawn push. The destination square must be on the fifth
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
-          if (   square_rank(to) != RANK_5
-              || !square_is_empty(to)
-              || !square_is_empty(from + DELTA_S))
-              return false;
-          break;
+      if (   square_rank(to) != RANK_5
+          || !square_is_empty(to)
+          || !square_is_empty(from + DELTA_S))
+          return false;
+      break;
 
       default:
           return false;