mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 11:39:15 +00:00
Merge default tests in pos_is_ok
No functional change.
This commit is contained in:
parent
142874b058
commit
6e4b4c42ed
2 changed files with 17 additions and 22 deletions
|
@ -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)
|
||||
if (step)
|
||||
*step = 1;
|
||||
|
||||
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)++, piece_on(king_square(WHITE)) != W_KING)
|
||||
return false;
|
||||
|
||||
if ((*step)++, piece_on(king_square(BLACK)) != B_KING)
|
||||
return false;
|
||||
|
||||
if ((*step)++, 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<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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue