From: Marco Costalba Date: Sun, 16 Feb 2014 10:37:29 +0000 (+0100) Subject: Fix material key for King X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=d91079d4b02b410702dda082d5c489847f067a35 Fix material key for King Currently king has no material key associated because it can never happen to find a legal position without both kings, so there is no need to keep track of it. The consequence is that a position with only the two kings has material key set at zero and if the material hash table is empty any entry will match and this is wrong. Normally bug is hidden becuase the checking for a draw with pos.is_draw() is done earlier than evaluate() call, so that we never check in gameplay the material key of a position with two kings. Nevertheless the bug is there and can be reproduced setting at startup a position with only two kings and typing 'eval' from prompt. The fix is very simple: add a random key also for the king. Also fixed the condition in material.cpp to avoid asserting when a 'just 2 kings' postion is evaluated. No functional change. --- diff --git a/src/material.cpp b/src/material.cpp index b6e23964..89147352 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -192,7 +192,7 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) { Value npm_w = pos.non_pawn_material(WHITE); Value npm_b = pos.non_pawn_material(BLACK); - if (npm_w + npm_b == VALUE_ZERO) + if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) { if (!pos.count(BLACK)) { diff --git a/src/position.cpp b/src/position.cpp index 6f874763..72681e8d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1176,7 +1176,7 @@ Key Position::compute_material_key() const { Key k = 0; for (Color c = WHITE; c <= BLACK; ++c) - for (PieceType pt = PAWN; pt <= QUEEN; ++pt) + for (PieceType pt = PAWN; pt <= KING; ++pt) for (int cnt = 0; cnt < pieceCount[c][pt]; ++cnt) k ^= Zobrist::psq[c][pt][cnt];