From: Marco Costalba Date: Sun, 20 Oct 2013 21:35:10 +0000 (+0200) Subject: Fix pos.count() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=f22a63ce67fecabe14dd4e558af9483b592efcfa Fix pos.count() It was never updated ! Currently it only affects evaluate_passed_pawns() and in particularly the rule to increase the bonus if we have more non-pawn pieces. We could simply use popcount() instead and avoid the little slowdown in put_piece() and remove_piece(), but this would leave a very subtle and tricky hole where people are forced to remember that pos.count() does not work. This is not obvious and so dangerous. Thanks to Ronald de Man for spotting this. bench: 7931424 --- diff --git a/src/position.h b/src/position.h index 9dd9e79e..e73c8ff5 100644 --- a/src/position.h +++ b/src/position.h @@ -405,6 +405,7 @@ inline void Position::put_piece(Square s, Color c, PieceType pt) { byTypeBB[ALL_PIECES] |= s; byTypeBB[pt] |= s; byColorBB[c] |= s; + pieceCount[c][ALL_PIECES]++; index[s] = pieceCount[c][pt]++; pieceList[c][pt][index[s]] = s; } @@ -433,6 +434,7 @@ inline void Position::remove_piece(Square s, Color c, PieceType pt) { byTypeBB[pt] ^= s; byColorBB[c] ^= s; /* board[s] = NO_PIECE; */ // Not needed, will be overwritten by capturing + pieceCount[c][ALL_PIECES]--; Square lastSquare = pieceList[c][pt][--pieceCount[c][pt]]; index[lastSquare] = index[s]; pieceList[c][pt][index[lastSquare]] = lastSquare;