]> git.sesse.net Git - stockfish/commitdiff
Fix multiPV issue #502
authorjoergoster <osterj165@googlemail.com>
Thu, 4 May 2017 02:46:40 +0000 (19:46 -0700)
committerJoona Kiiski <joona@zoox.com>
Thu, 4 May 2017 02:46:40 +0000 (19:46 -0700)
In general, this patch handles the cases where we don't have a valid score for each PV line in a multiPV search. This can happen if the search has been stopped in an unfortunate moment while still in the aspiration loop. The patch consists of two parts.

Part 1: The new PVIdx was already part of the k-best pv's in the last iteration, and we therefore have a valid pv and score to output from the last iteration. This is taken care of with:

      bool updated = (i <= PVIdx && rootMoves[i].score != -VALUE_INFINITE);

Case 2: The new PVIdx was NOT part of the k-best pv's in the last iteration, and we have no valid pv and score to output. Not from the current nor from the previous iteration. To avoid this, we are now also considering the previous score when sorting, so that the PV lines with no actual but with a valid previous score are pushed up again, and the previous score can be displayed.

  bool operator<(const RootMove& m) const {
    return m.score != score ? m.score < score : m.previousScore < previousScore; } // Descending sort

I also added an assertion in UCI::value() to possibly catch similar issues earlier.

No functional change.

Closes #502
Closes #1074

src/search.cpp
src/search.h
src/uci.cpp

index ffe724aa10a864d8b3fad173c5a91c5fa9bb7e26..2c9240146b32b46791efcb755a46f3236a83f18c 100644 (file)
@@ -1505,7 +1505,7 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
 
   for (size_t i = 0; i < multiPV; ++i)
   {
 
   for (size_t i = 0; i < multiPV; ++i)
   {
-      bool updated = (i <= PVIdx);
+      bool updated = (i <= PVIdx && rootMoves[i].score != -VALUE_INFINITE);
 
       if (depth == ONE_PLY && !updated)
           continue;
 
       if (depth == ONE_PLY && !updated)
           continue;
index ba8a90539e6f7c343dea616136ec95a3ba59915a..1218ef3be223289f10fbb744d3bab771d1b32fb8 100644 (file)
@@ -57,7 +57,8 @@ struct RootMove {
 
   explicit RootMove(Move m) : pv(1, m) {}
 
 
   explicit RootMove(Move m) : pv(1, m) {}
 
-  bool operator<(const RootMove& m) const { return m.score < score; } // Descending sort
+  bool operator<(const RootMove& m) const {
+    return m.score != score ? m.score < score : m.previousScore < previousScore; } // Descending sort
   bool operator==(const Move& m) const { return pv[0] == m; }
   bool extract_ponder_from_tt(Position& pos);
 
   bool operator==(const Move& m) const { return pv[0] == m; }
   bool extract_ponder_from_tt(Position& pos);
 
index 91a2260e28a86c7f519d4204e4c00d689cfb058f..893c7e2f54827e1d43d56db13fb849bcb1b7e1f3 100644 (file)
@@ -18,6 +18,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <cassert>
 #include <iostream>
 #include <sstream>
 #include <string>
 #include <iostream>
 #include <sstream>
 #include <string>
@@ -229,6 +230,8 @@ void UCI::loop(int argc, char* argv[]) {
 
 string UCI::value(Value v) {
 
 
 string UCI::value(Value v) {
 
+  assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);
+
   stringstream ss;
 
   if (abs(v) < VALUE_MATE - MAX_PLY)
   stringstream ss;
 
   if (abs(v) < VALUE_MATE - MAX_PLY)