- 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)++, ep_square() != SQ_NONE && relative_rank(sideToMove, ep_square()) != RANK_6)
- return false;
-
- if ((*step)++, testBitboards)
- {
- // The intersection of the white and black pieces must be empty
- if (pieces(WHITE) & pieces(BLACK))
- return false;
-
- // The union of the white and black pieces must be equal to all
- // occupied squares
- if ((pieces(WHITE) | pieces(BLACK)) != pieces())
- return false;
-
- // Separate piece type bitboards must have empty intersections
- for (PieceType p1 = PAWN; p1 <= KING; ++p1)
- for (PieceType p2 = PAWN; p2 <= KING; ++p2)
- if (p1 != p2 && (pieces(p1) & pieces(p2)))
- return false;
- }
-
- if ((*step)++, testState)
- {
- StateInfo si;
- set_state(&si);
- if ( st->key != si.key
- || st->pawnKey != si.pawnKey
- || st->materialKey != si.materialKey
- || st->npMaterial[WHITE] != si.npMaterial[WHITE]
- || st->npMaterial[BLACK] != si.npMaterial[BLACK]
- || st->psq != si.psq
- || st->checkersBB != si.checkersBB)
- return false;
- }
-
- if ((*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 (attackers_to(king_square(~sideToMove)) & pieces(sideToMove))
- return false;