]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Position: fix a couple of Intel compiler warnings
[stockfish] / src / position.cpp
index f6ad622f2017df066971264a3bd7887e6ef968e9..67ee145c11efecb3500a26843db96ff1acf9c354 100644 (file)
@@ -235,7 +235,7 @@ const std::string Position::to_fen() const {
               fen += (char)skip + '0';
               skip = 0;
           }
-          fen += pieceLetters[piece_on(sq)];         
+          fen += pieceLetters[piece_on(sq)];
       }
       if (skip > 0)
           fen += (char)skip + '0';
@@ -327,7 +327,7 @@ Bitboard Position::hidden_checks(Color c, Square ksq) const {
 
   Square s;
   Bitboard sliders, result = EmptyBoardBB;
-  
+
   if (Piece == ROOK) // Resolved at compile time
       sliders = rooks_and_queens(FindPinned ? opposite_color(c) : c) & RookPseudoAttacks[ksq];
   else
@@ -338,7 +338,7 @@ Bitboard Position::hidden_checks(Color c, Square ksq) const {
        // King blockers are candidate pinned pieces
       Bitboard candidate_pinned = piece_attacks<Piece>(ksq) & pieces_of_color(c);
 
-      // Pinners are sliders, not checkers, that give check when 
+      // Pinners are sliders, not checkers, that give check when
       // candidate pinned are removed.
       Bitboard pinners = (FindPinned ? sliders & ~checkersBB : sliders);
 
@@ -410,7 +410,6 @@ bool Position::piece_attacks_square(Square f, Square t) const {
   case WR: case BR: return piece_attacks_square<ROOK>(f, t);
   case WQ: case BQ: return piece_attacks_square<QUEEN>(f, t);
   case WK: case BK: return piece_attacks_square<KING>(f, t);
-  default:          return false;
   }
   return false;
 }
@@ -456,18 +455,18 @@ void Position::find_checkers() {
 }
 
 
-/// Position::move_is_legal() tests whether a pseudo-legal move is legal.
+/// Position::pl_move_is_legal() tests whether a pseudo-legal move is legal.
 /// There are two versions of this function:  One which takes only a
 /// move as input, and one which takes a move and a bitboard of pinned
 /// pieces. The latter function is faster, and should always be preferred
 /// when a pinned piece bitboard has already been computed.
 
-bool Position::move_is_legal(Move m)  const {
+bool Position::pl_move_is_legal(Move m)  const {
 
-  return move_is_legal(m, pinned_pieces(side_to_move()));
+  return pl_move_is_legal(m, pinned_pieces(side_to_move()));
 }
 
-bool Position::move_is_legal(Move m, Bitboard pinned) const {
+bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
 
   Color us, them;
   Square ksq, from;
@@ -564,14 +563,14 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
   switch (type_of_piece_on(from))
   {
   case PAWN:
-      
+
       if (bit_is_set(pawn_attacks(them, ksq), to)) // Normal check?
           return true;
-      
+
       if (    bit_is_set(dcCandidates, from)      // Discovered check?
           && (direction_between_squares(from, ksq) != direction_between_squares(to, ksq)))
           return true;
-      
+
       if (move_promotion(m)) // Promotion with check?
       {
           Bitboard b = occupied_squares();
@@ -607,7 +606,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
       }
       return false;
 
-  case KNIGHT:    
+  case KNIGHT:
     return   bit_is_set(dcCandidates, from)              // Discovered check?
           || bit_is_set(piece_attacks<KNIGHT>(ksq), to); // Normal check?
 
@@ -621,7 +620,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
 
   case QUEEN:
       // Discovered checks are impossible!
-      assert(!bit_is_set(dcCandidates, from));    
+      assert(!bit_is_set(dcCandidates, from));
       return bit_is_set(piece_attacks<QUEEN>(ksq), to);  // Normal check?
 
   case KING:
@@ -1337,7 +1336,6 @@ void Position::undo_castle_move(Move m) {
   // Position::undo_move.  In particular, the side to move has been switched,
   // so the code below is correct.
   Color us = side_to_move();
-  Color them = opposite_color(us);
 
   // Find source squares for king and rook
   Square kfrom = move_from(m);
@@ -1396,7 +1394,7 @@ void Position::undo_castle_move(Move m) {
 /// Position::do_move, is used to put back the captured piece (if any).
 
 void Position::undo_promotion_move(Move m, const UndoInfo &u) {
+
   Color us, them;
   Square from, to;
   PieceType capture, promotion;
@@ -1629,16 +1627,23 @@ int Position::see(Square from, Square to) const {
              | (pawn_attacks(WHITE, to)    & pawns(BLACK))
              | (pawn_attacks(BLACK, to)    & pawns(WHITE));
 
-  attackers &= occ; // Re-add removed piece
-
   // If the opponent has no attackers, we are finished
   if ((attackers & pieces_of_color(them)) == EmptyBoardBB)
       return seeValues[capture];
 
+  attackers &= occ; // Remove the moving piece
+
+  // If we don't have any attacker but the moving piece (common case)
+  // then we loose our piece and gain the opponent attacked one.
+  // Note that this is not perfect! It does not detect x-rays of
+  // an our piece behind an opposite one. But is a very rare case.
+  if ((attackers & pieces_of_color(us)) == EmptyBoardBB)
+      return seeValues[capture] - seeValues[piece];
+
   // The destination square is defended, which makes things rather more
   // difficult to compute. We proceed by building up a "swap list" containing
   // the material gain or loss at each stop in a sequence of captures to the
-  // destianation square, where the sides alternately capture, and always
+  // destination square, where the sides alternately capture, and always
   // capture with the least valuable piece. After each capture, we look for
   // new X-ray attacks from behind the capturing piece.
   int lastCapturingPieceValue = seeValues[piece];
@@ -2249,7 +2254,7 @@ bool Position::is_ok(int* failedStep) const {
   {
       if (mgValue != compute_mg_value())
           return false;
-  
+
       if (egValue != compute_eg_value())
           return false;
   }