]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Use std::count in pos_is_ok()
[stockfish] / src / position.cpp
index 3fc568eebf93a0e674d748ceee4095c8b92b7551..d00a531c0d5caa1d9e726171d0953ab37ac60f13 100644 (file)
@@ -596,12 +596,11 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
       && !aligned(from, to, ci.ksq))
       return true;
 
-  // Can we skip the ugly special cases?
-  if (type_of(m) == NORMAL)
-      return false;
-
   switch (type_of(m))
   {
+  case NORMAL:
+      return false;
+
   case PROMOTION:
       return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & ci.ksq;
 
@@ -1264,9 +1263,7 @@ bool Position::pos_is_ok(int* failedStep) const {
   const bool debugPieceList       = all || false;
   const bool debugCastlingSquares = all || false;
 
-  *step = 1;
-
-  if (sideToMove != WHITE && sideToMove != BLACK)
+  if (*step = 1, sideToMove != WHITE && sideToMove != BLACK)
       return false;
 
   if ((*step)++, piece_on(king_square(WHITE)) != W_KING)
@@ -1276,16 +1273,9 @@ bool Position::pos_is_ok(int* failedStep) const {
       return false;
 
   if ((*step)++, debugKingCount)
-  {
-      int kingCount[COLOR_NB] = {};
-
-      for (Square s = SQ_A1; s <= SQ_H8; ++s)
-          if (type_of(piece_on(s)) == KING)
-              ++kingCount[color_of(piece_on(s))];
-
-      if (kingCount[0] != 1 || kingCount[1] != 1)
+      if (   std::count(board, board + SQUARE_NB, W_KING) != 1
+          || std::count(board, board + SQUARE_NB, B_KING) != 1)
           return false;
-  }
 
   if ((*step)++, debugKingCapture)
       if (attackers_to(king_square(~sideToMove)) & pieces(sideToMove))