1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Position::is_ok()give more info on failed test

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-10-19 10:41:24 +01:00
parent 6b8a07eccc
commit 3f38cca072
2 changed files with 21 additions and 3 deletions

View file

@ -2116,7 +2116,7 @@ void Position::flipped_copy(const Position &pos) {
/// Position::is_ok() performs some consitency checks for the position object. /// Position::is_ok() performs some consitency checks for the position object.
/// This is meant to be helpful when debugging. /// This is meant to be helpful when debugging.
bool Position::is_ok() const { bool Position::is_ok(int* failedStep) const {
// What features of the position should be verified? // What features of the position should be verified?
static const bool debugBitboards = false; static const bool debugBitboards = false;
@ -2131,23 +2131,30 @@ bool Position::is_ok() const {
static const bool debugPieceCounts = false; static const bool debugPieceCounts = false;
static const bool debugPieceList = false; static const bool debugPieceList = false;
if (failedStep) *failedStep = 1;
// Side to move OK? // Side to move OK?
if(!color_is_ok(side_to_move())) if(!color_is_ok(side_to_move()))
return false; return false;
// Are the king squares in the position correct? // Are the king squares in the position correct?
if (failedStep) (*failedStep)++;
if(piece_on(king_square(WHITE)) != WK) if(piece_on(king_square(WHITE)) != WK)
return false; return false;
if (failedStep) (*failedStep)++;
if(piece_on(king_square(BLACK)) != BK) if(piece_on(king_square(BLACK)) != BK)
return false; return false;
// Castle files OK? // Castle files OK?
if (failedStep) (*failedStep)++;
if(!file_is_ok(initialKRFile)) if(!file_is_ok(initialKRFile))
return false; return false;
if(!file_is_ok(initialQRFile)) if(!file_is_ok(initialQRFile))
return false; return false;
// Do both sides have exactly one king? // Do both sides have exactly one king?
if (failedStep) (*failedStep)++;
if(debugKingCount) { if(debugKingCount) {
int kingCount[2] = {0, 0}; int kingCount[2] = {0, 0};
for(Square s = SQ_A1; s <= SQ_H8; s++) for(Square s = SQ_A1; s <= SQ_H8; s++)
@ -2158,6 +2165,7 @@ bool Position::is_ok() const {
} }
// Can the side to move capture the opponent's king? // Can the side to move capture the opponent's king?
if (failedStep) (*failedStep)++;
if(debugKingCapture) { if(debugKingCapture) {
Color us = side_to_move(); Color us = side_to_move();
Color them = opposite_color(us); Color them = opposite_color(us);
@ -2167,10 +2175,12 @@ bool Position::is_ok() const {
} }
// Is there more than 2 checkers? // Is there more than 2 checkers?
if (failedStep) (*failedStep)++;
if(debugCheckerCount && count_1s(checkersBB) > 2) if(debugCheckerCount && count_1s(checkersBB) > 2)
return false; return false;
// Bitboards OK? // Bitboards OK?
if (failedStep) (*failedStep)++;
if(debugBitboards) { if(debugBitboards) {
// The intersection of the white and black pieces must be empty: // The intersection of the white and black pieces must be empty:
if((pieces_of_color(WHITE) & pieces_of_color(BLACK)) if((pieces_of_color(WHITE) & pieces_of_color(BLACK))
@ -2191,6 +2201,7 @@ bool Position::is_ok() const {
} }
// En passant square OK? // En passant square OK?
if (failedStep) (*failedStep)++;
if(ep_square() != SQ_NONE) { if(ep_square() != SQ_NONE) {
// The en passant square must be on rank 6, from the point of view of the // The en passant square must be on rank 6, from the point of view of the
// side to move. // side to move.
@ -2199,18 +2210,22 @@ bool Position::is_ok() const {
} }
// Hash key OK? // Hash key OK?
if (failedStep) (*failedStep)++;
if(debugKey && key != compute_key()) if(debugKey && key != compute_key())
return false; return false;
// Pawn hash key OK? // Pawn hash key OK?
if (failedStep) (*failedStep)++;
if(debugPawnKey && pawnKey != compute_pawn_key()) if(debugPawnKey && pawnKey != compute_pawn_key())
return false; return false;
// Material hash key OK? // Material hash key OK?
if (failedStep) (*failedStep)++;
if(debugMaterialKey && materialKey != compute_material_key()) if(debugMaterialKey && materialKey != compute_material_key())
return false; return false;
// Incremental eval OK? // Incremental eval OK?
if (failedStep) (*failedStep)++;
if(debugIncrementalEval) { if(debugIncrementalEval) {
if(mgValue != compute_mg_value()) if(mgValue != compute_mg_value())
return false; return false;
@ -2219,6 +2234,7 @@ bool Position::is_ok() const {
} }
// Non-pawn material OK? // Non-pawn material OK?
if (failedStep) (*failedStep)++;
if(debugNonPawnMaterial) { if(debugNonPawnMaterial) {
if(npMaterial[WHITE] != compute_non_pawn_material(WHITE)) if(npMaterial[WHITE] != compute_non_pawn_material(WHITE))
return false; return false;
@ -2227,12 +2243,14 @@ bool Position::is_ok() const {
} }
// Piece counts OK? // Piece counts OK?
if (failedStep) (*failedStep)++;
if(debugPieceCounts) if(debugPieceCounts)
for(Color c = WHITE; c <= BLACK; c++) for(Color c = WHITE; c <= BLACK; c++)
for(PieceType pt = PAWN; pt <= KING; pt++) for(PieceType pt = PAWN; pt <= KING; pt++)
if(pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt))) if(pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt)))
return false; return false;
if (failedStep) (*failedStep)++;
if(debugPieceList) { if(debugPieceList) {
for(Color c = WHITE; c <= BLACK; c++) for(Color c = WHITE; c <= BLACK; c++)
for(PieceType pt = PAWN; pt <= KING; pt++) for(PieceType pt = PAWN; pt <= KING; pt++)
@ -2244,6 +2262,6 @@ bool Position::is_ok() const {
return false; return false;
} }
} }
if (failedStep) *failedStep = 0;
return true; return true;
} }

View file

@ -298,7 +298,7 @@ public:
void reset_game_ply(); void reset_game_ply();
// Position consistency check, for debugging // Position consistency check, for debugging
bool is_ok() const; bool is_ok(int* failedStep = NULL) const;
// Static member functions: // Static member functions:
static void init_zobrist(); static void init_zobrist();