]> git.sesse.net Git - stockfish/commitdiff
Merge default tests in pos_is_ok
authorMarco Costalba <mcostalba@gmail.com>
Sat, 15 Mar 2014 14:26:29 +0000 (15:26 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 15 Mar 2014 14:34:31 +0000 (15:34 +0100)
No functional change.

src/position.cpp
src/position.h

index 41e5eea25ab9ab89d2ae620a772d3f65b90cf4cf..b89c645f9768b77e5974e7a40aef0517f871d0ad 100644 (file)
@@ -1176,9 +1176,7 @@ void Position::flip() {
 /// Position::pos_is_ok() performs some consistency checks for the position object.
 /// This is meant to be helpful when debugging.
 
 /// Position::pos_is_ok() performs some consistency checks for the position object.
 /// This is meant to be helpful when debugging.
 
-bool Position::pos_is_ok(int* failedStep) const {
-
-  int dummy, *step = failedStep ? failedStep : &dummy;
+bool Position::pos_is_ok(int* step) const {
 
   // Which parts of the position should be verified?
   const bool all = false;
 
   // Which parts of the position should be verified?
   const bool all = false;
@@ -1191,19 +1189,17 @@ bool Position::pos_is_ok(int* failedStep) const {
   const bool testPieceList       = all || false;
   const bool testCastlingSquares = all || false;
 
   const bool testPieceList       = all || false;
   const bool testCastlingSquares = all || false;
 
-  if (*step = 1, sideToMove != WHITE && sideToMove != BLACK)
-      return false;
-
-  if ((*step)++, piece_on(king_square(WHITE)) != W_KING)
-      return false;
-
-  if ((*step)++, piece_on(king_square(BLACK)) != B_KING)
-      return false;
+  if (step)
+      *step = 1;
 
 
-  if ((*step)++, ep_square() != SQ_NONE && relative_rank(sideToMove, ep_square()) != RANK_6)
+  if (   (sideToMove != WHITE && sideToMove != BLACK)
+      || piece_on(king_square(WHITE)) != W_KING
+      || piece_on(king_square(BLACK)) != B_KING
+      || (   ep_square() != SQ_NONE
+          && relative_rank(sideToMove, ep_square()) != RANK_6))
       return false;
 
       return false;
 
-  if ((*step)++, testBitboards)
+  if (step && ++*step, testBitboards)
   {
       // The intersection of the white and black pieces must be empty
       if (pieces(WHITE) & pieces(BLACK))
   {
       // The intersection of the white and black pieces must be empty
       if (pieces(WHITE) & pieces(BLACK))
@@ -1221,7 +1217,7 @@ bool Position::pos_is_ok(int* failedStep) const {
                   return false;
   }
 
                   return false;
   }
 
-  if ((*step)++, testState)
+  if (step && ++*step, testState)
   {
       StateInfo si;
       set_state(&si);
   {
       StateInfo si;
       set_state(&si);
@@ -1235,22 +1231,22 @@ bool Position::pos_is_ok(int* failedStep) const {
           return false;
   }
 
           return false;
   }
 
-  if ((*step)++, testKingCount)
+  if (step && ++*step, testKingCount)
       if (   std::count(board, board + SQUARE_NB, W_KING) != 1
           || std::count(board, board + SQUARE_NB, B_KING) != 1)
           return false;
 
       if (   std::count(board, board + SQUARE_NB, W_KING) != 1
           || std::count(board, board + SQUARE_NB, B_KING) != 1)
           return false;
 
-  if ((*step)++, testKingCapture)
+  if (step && ++*step, testKingCapture)
       if (attackers_to(king_square(~sideToMove)) & pieces(sideToMove))
           return false;
 
       if (attackers_to(king_square(~sideToMove)) & pieces(sideToMove))
           return false;
 
-  if ((*step)++, testPieceCounts)
+  if (step && ++*step, testPieceCounts)
       for (Color c = WHITE; c <= BLACK; ++c)
           for (PieceType pt = PAWN; pt <= KING; ++pt)
               if (pieceCount[c][pt] != popcount<Full>(pieces(c, pt)))
                   return false;
 
       for (Color c = WHITE; c <= BLACK; ++c)
           for (PieceType pt = PAWN; pt <= KING; ++pt)
               if (pieceCount[c][pt] != popcount<Full>(pieces(c, pt)))
                   return false;
 
-  if ((*step)++, testPieceList)
+  if (step && ++*step, testPieceList)
       for (Color c = WHITE; c <= BLACK; ++c)
           for (PieceType pt = PAWN; pt <= KING; ++pt)
               for (int i = 0; i < pieceCount[c][pt];  ++i)
       for (Color c = WHITE; c <= BLACK; ++c)
           for (PieceType pt = PAWN; pt <= KING; ++pt)
               for (int i = 0; i < pieceCount[c][pt];  ++i)
@@ -1258,7 +1254,7 @@ bool Position::pos_is_ok(int* failedStep) const {
                       || index[pieceList[c][pt][i]] != i)
                       return false;
 
                       || index[pieceList[c][pt][i]] != i)
                       return false;
 
-  if ((*step)++, testCastlingSquares)
+  if (step && ++*step, testCastlingSquares)
       for (Color c = WHITE; c <= BLACK; ++c)
           for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s + 1))
           {
       for (Color c = WHITE; c <= BLACK; ++c)
           for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s + 1))
           {
@@ -1271,6 +1267,5 @@ bool Position::pos_is_ok(int* failedStep) const {
                   return false;
           }
 
                   return false;
           }
 
-  *step = 0;
   return true;
 }
   return true;
 }
index 34c427d4e21227d6f5903993572f047c2a06a0d3..36d65fb87b5ef11771294b6acc34fef1208a7f5f 100644 (file)
@@ -164,7 +164,7 @@ public:
   bool is_draw() const;
 
   // Position consistency check, for debugging
   bool is_draw() const;
 
   // Position consistency check, for debugging
-  bool pos_is_ok(int* failedStep = NULL) const;
+  bool pos_is_ok(int* step = NULL) const;
   void flip();
 
 private:
   void flip();
 
 private: