From: Marco Costalba Date: Sat, 15 Mar 2014 14:26:29 +0000 (+0100) Subject: Merge default tests in pos_is_ok X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=6e4b4c42ed796652d122e2116561e9ad3848c641 Merge default tests in pos_is_ok No functional change. --- diff --git a/src/position.cpp b/src/position.cpp index 41e5eea2..b89c645f 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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. -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; @@ -1191,19 +1189,17 @@ bool Position::pos_is_ok(int* failedStep) const { 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; - if ((*step)++, testBitboards) + if (step && ++*step, testBitboards) { // 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; } - if ((*step)++, testState) + if (step && ++*step, testState) { StateInfo si; set_state(&si); @@ -1235,22 +1231,22 @@ bool Position::pos_is_ok(int* failedStep) const { 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 ((*step)++, testKingCapture) + if (step && ++*step, testKingCapture) 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(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) @@ -1258,7 +1254,7 @@ bool Position::pos_is_ok(int* failedStep) const { || 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)) { @@ -1271,6 +1267,5 @@ bool Position::pos_is_ok(int* failedStep) const { return false; } - *step = 0; return true; } diff --git a/src/position.h b/src/position.h index 34c427d4..36d65fb8 100644 --- a/src/position.h +++ b/src/position.h @@ -164,7 +164,7 @@ public: 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: