X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=2a6b8989fcc8148b29037bd026562e433535ed15;hp=05a02f158948e73513b33e62e24ef095377c3e4e;hb=e05c80a08859f6c4f0f599ca0b262ced00ad66fe;hpb=a6e0f62a4f83bf4303e920d5f689de7cbc0467e8 diff --git a/src/position.cpp b/src/position.cpp index 05a02f15..2a6b8989 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -46,11 +46,16 @@ Value PieceValue[PHASE_NB][PIECE_NB] = { { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg }, { VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } }; -Key Zobrist::psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; -Key Zobrist::enpassant[FILE_NB]; -Key Zobrist::castle[CASTLE_RIGHT_NB]; -Key Zobrist::side; -Key Zobrist::exclusion; +namespace Zobrist { + + Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; + Key enpassant[FILE_NB]; + Key castle[CASTLE_RIGHT_NB]; + Key side; + Key exclusion; +} + +Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion;} namespace { @@ -1327,7 +1332,7 @@ Key Position::compute_material_key() const { for (Color c = WHITE; c <= BLACK; c++) for (PieceType pt = PAWN; pt <= QUEEN; pt++) - for (int cnt = 0; cnt < piece_count(c, pt); cnt++) + for (int cnt = 0; cnt < pieceCount[c][pt]; cnt++) k ^= Zobrist::psq[c][pt][cnt]; return k; @@ -1363,7 +1368,7 @@ Value Position::compute_non_pawn_material(Color c) const { Value value = VALUE_ZERO; for (PieceType pt = KNIGHT; pt <= QUEEN; pt++) - value += piece_count(c, pt) * PieceValue[MG][pt]; + value += pieceCount[c][pt] * PieceValue[MG][pt]; return value; } @@ -1536,11 +1541,9 @@ bool Position::pos_is_ok(int* failedStep) const { return false; if ((*step)++, debugNonPawnMaterial) - { if ( st->npMaterial[WHITE] != compute_non_pawn_material(WHITE) || st->npMaterial[BLACK] != compute_non_pawn_material(BLACK)) return false; - } if ((*step)++, debugPieceCounts) for (Color c = WHITE; c <= BLACK; c++) @@ -1552,14 +1555,10 @@ bool Position::pos_is_ok(int* failedStep) const { for (Color c = WHITE; c <= BLACK; c++) for (PieceType pt = PAWN; pt <= KING; pt++) for (int i = 0; i < pieceCount[c][pt]; i++) - { - if (piece_on(piece_list(c, pt)[i]) != make_piece(c, pt)) + if ( board[pieceList[c][pt][i]] != make_piece(c, pt) + || index[pieceList[c][pt][i]] != i) return false; - if (index[piece_list(c, pt)[i]] != i) - return false; - } - if ((*step)++, debugCastleSquares) for (Color c = WHITE; c <= BLACK; c++) for (CastlingSide s = KING_SIDE; s <= QUEEN_SIDE; s = CastlingSide(s + 1)) @@ -1569,10 +1568,8 @@ bool Position::pos_is_ok(int* failedStep) const { if (!can_castle(cr)) continue; - if ((castleRightsMask[king_square(c)] & cr) != cr) - return false; - - if ( piece_on(castleRookSquare[c][s]) != make_piece(c, ROOK) + if ( (castleRightsMask[king_square(c)] & cr) != cr + || piece_on(castleRookSquare[c][s]) != make_piece(c, ROOK) || castleRightsMask[castleRookSquare[c][s]] != cr) return false; }