]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Revert C++11 merge
[stockfish] / src / position.cpp
index 8d4b9f4f3c53de66f382dee30529aa46986ae91e..eda26014c32c49330a57cbdd996102a555011b0d 100644 (file)
@@ -690,10 +690,10 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
 void Position::do_move(Move m, StateInfo& newSt) {
 
   CheckInfo ci(*this);
-  do_move(m, newSt, ci, gives_check(m, ci));
+  do_move(m, newSt, gives_check(m, ci));
 }
 
-void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
+void Position::do_move(Move m, StateInfo& newSt, bool moveIsCheck) {
 
   assert(is_ok(m));
   assert(&newSt != st);
@@ -856,30 +856,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   // Update the key with the final value
   st->key = k;
 
-  // Update checkers bitboard: piece must be already moved due to attacks_from()
-  st->checkersBB = 0;
-
-  if (moveIsCheck)
-  {
-      if (type_of(m) != NORMAL)
-          st->checkersBB = attackers_to(king_square(them)) & pieces(us);
-      else
-      {
-          // Direct checks
-          if (ci.checkSq[pt] & to)
-              st->checkersBB |= to;
-
-          // Discovered checks
-          if (ci.dcCandidates && (ci.dcCandidates & from))
-          {
-              if (pt != ROOK)
-                  st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(us, QUEEN, ROOK);
-
-              if (pt != BISHOP)
-                  st->checkersBB |= attacks_from<BISHOP>(king_square(them)) & pieces(us, QUEEN, BISHOP);
-          }
-      }
-  }
+  // Calculate checkers bitboard (if move is check)
+  st->checkersBB = moveIsCheck ? attackers_to(king_square(them)) & pieces(us) : 0;
 
   sideToMove = ~sideToMove;
 
@@ -1098,11 +1076,21 @@ Value Position::see(Move m) const {
 
       // Locate and remove the next least valuable attacker
       captured = min_attacker<PAWN>(byTypeBB, to, stmAttackers, occupied, attackers);
+
+      // Stop before processing a king capture
+      if (captured == KING)
+      {
+          if (stmAttackers == attackers)
+              ++slIndex;
+
+          break;
+      }
+
       stm = ~stm;
       stmAttackers = attackers & pieces(stm);
       ++slIndex;
 
-  } while (stmAttackers && (captured != KING || (--slIndex, false))); // Stop before a king capture
+  } while (stmAttackers);
 
   // Having built the swap list, we negamax through it to find the best
   // achievable score from the point of view of the side to move.
@@ -1137,6 +1125,10 @@ bool Position::is_draw() const {
 /// Position::flip() flips position with the white and black sides reversed. This
 /// is only useful for debugging e.g. for finding evaluation symmetry bugs.
 
+static char toggle_case(char c) {
+  return char(islower(c) ? toupper(c) : tolower(c));
+}
+
 void Position::flip() {
 
   string f, token;
@@ -1154,8 +1146,7 @@ void Position::flip() {
   ss >> token; // Castling availability
   f += token + " ";
 
-  std::transform(f.begin(), f.end(), f.begin(),
-                 [](char c) { return char(islower(c) ? toupper(c) : tolower(c)); });
+  std::transform(f.begin(), f.end(), f.begin(), toggle_case);
 
   ss >> token; // En passant square
   f += (token == "-" ? token : token.replace(1, 1, token[1] == '3' ? "6" : "3"));