- if ((*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)
- for (Color c = WHITE; c <= BLACK; ++c)
- for (PieceType pt = PAWN; pt <= KING; ++pt)
- for (int i = 0; i < pieceCount[c][pt]; ++i)
- if ( board[pieceList[c][pt][i]] != make_piece(c, pt)
- || index[pieceList[c][pt][i]] != i)
- return false;
-
- if ((*step)++, testCastlingSquares)
- for (Color c = WHITE; c <= BLACK; ++c)
- for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s + 1))
- {
- if (!can_castle(c | s))
- continue;
+ if ( pieceCount[W_KING] != 1
+ || pieceCount[B_KING] != 1
+ || attackers_to(square<KING>(~sideToMove)) & pieces(sideToMove))
+ assert(0 && "pos_is_ok: Kings");
+
+ if ( (pieces(PAWN) & (Rank1BB | Rank8BB))
+ || pieceCount[W_PAWN] > 8
+ || pieceCount[B_PAWN] > 8)
+ assert(0 && "pos_is_ok: Pawns");
+
+ if ( (pieces(WHITE) & pieces(BLACK))
+ || (pieces(WHITE) | pieces(BLACK)) != pieces()
+ || popcount(pieces(WHITE)) > 16
+ || popcount(pieces(BLACK)) > 16)
+ assert(0 && "pos_is_ok: Bitboards");
+
+ for (PieceType p1 = PAWN; p1 <= KING; ++p1)
+ for (PieceType p2 = PAWN; p2 <= KING; ++p2)
+ if (p1 != p2 && (pieces(p1) & pieces(p2)))
+ assert(0 && "pos_is_ok: Bitboards");
+
+ StateInfo si = *st;
+ ASSERT_ALIGNED(&si, Eval::NNUE::CacheLineSize);
+
+ set_state(&si);
+ if (std::memcmp(&si, st, sizeof(StateInfo)))
+ assert(0 && "pos_is_ok: State");
+
+ for (Piece pc : Pieces)
+ if ( pieceCount[pc] != popcount(pieces(color_of(pc), type_of(pc)))
+ || pieceCount[pc] != std::count(board, board + SQUARE_NB, pc))
+ assert(0 && "pos_is_ok: Pieces");
+
+ for (Color c : { WHITE, BLACK })
+ for (CastlingRights cr : {c & KING_SIDE, c & QUEEN_SIDE})
+ {
+ if (!can_castle(cr))
+ continue;