/// Position::is_ok() performs some consitency checks for the position object.
/// This is meant to be helpful when debugging.
/// Position::is_ok() performs some consitency checks for the position object.
/// This is meant to be helpful when debugging.
if(!file_is_ok(initialKRFile))
return false;
if(!file_is_ok(initialQRFile))
return false;
// Do both sides have exactly one king?
if(!file_is_ok(initialKRFile))
return false;
if(!file_is_ok(initialQRFile))
return false;
// Do both sides have exactly one king?
if(debugKingCount) {
int kingCount[2] = {0, 0};
for(Square s = SQ_A1; s <= SQ_H8; s++)
if(debugKingCount) {
int kingCount[2] = {0, 0};
for(Square s = SQ_A1; s <= SQ_H8; s++)
if(debugBitboards) {
// The intersection of the white and black pieces must be empty:
if((pieces_of_color(WHITE) & pieces_of_color(BLACK))
if(debugBitboards) {
// The intersection of the white and black pieces must be empty:
if((pieces_of_color(WHITE) & pieces_of_color(BLACK))
if(ep_square() != SQ_NONE) {
// The en passant square must be on rank 6, from the point of view of the
// side to move.
if(ep_square() != SQ_NONE) {
// The en passant square must be on rank 6, from the point of view of the
// side to move.
if(debugPieceCounts)
for(Color c = WHITE; c <= BLACK; c++)
for(PieceType pt = PAWN; pt <= KING; pt++)
if(pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt)))
return false;
if(debugPieceCounts)
for(Color c = WHITE; c <= BLACK; c++)
for(PieceType pt = PAWN; pt <= KING; pt++)
if(pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt)))
return false;