]> git.sesse.net Git - stockfish/commitdiff
Fix pos.count<ALL_PIECES>()
authorMarco Costalba <mcostalba@gmail.com>
Sun, 20 Oct 2013 21:35:10 +0000 (23:35 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 20 Oct 2013 21:36:46 +0000 (23:36 +0200)
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<ALL_PIECES>()
does not work. This is not obvious and so dangerous.

Thanks to Ronald de Man for spotting this.

bench: 7931424

src/position.h

index 9dd9e79e97f8a7d99f4088e469833ccc766b6366..e73c8ff5d9d3c78406f346f5b7582aef2e4c7f0a 100644 (file)
@@ -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;