From 50358e26c77a7c51ea1c17a948c36b09cb18239d Mon Sep 17 00:00:00 2001 From: Tomasz Sobczyk Date: Fri, 13 Nov 2020 22:28:28 +0100 Subject: [PATCH] Fix searching terminal nodes in gensfen. --- src/search.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 436e11fd..1aa86bf3 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1976,7 +1976,7 @@ namespace Search // Initialization for learning. // Called from Learner::search(),Learner::qsearch(). - static void init_for_search(Position& pos, Stack* ss) + static bool init_for_search(Position& pos, Stack* ss) { // RootNode requires ss->ply == 0. @@ -2026,7 +2026,10 @@ namespace Search for (auto m: MoveList(pos)) rootMoves.push_back(Search::RootMove(m)); - assert(!rootMoves.empty()); + // Check if we're at a terminal node. Otherwise we end up returning + // malformed PV later on. + if (rootMoves.empty()) + return false; th->UseRule50 = bool(Options["Syzygy50MoveRule"]); th->ProbeDepth = int(Options["SyzygyProbeDepth"]); @@ -2042,6 +2045,8 @@ namespace Search Tablebases::rank_root_moves(pos, rootMoves); } + + return true; } // Stationary search. @@ -2061,7 +2066,9 @@ namespace Search Stack stack[MAX_PLY+10], *ss = stack+7; Move pv[MAX_PLY+1]; - init_for_search(pos, ss); + if (!init_for_search(pos, ss)) + return {}; + ss->pv = pv; // For the time being, it must be a dummy and somewhere with a buffer. if (pos.is_draw(0)) { @@ -2116,7 +2123,8 @@ namespace Search Stack stack[MAX_PLY + 10], * ss = stack + 7; Move pv[MAX_PLY + 1]; - init_for_search(pos, ss); + if (!init_for_search(pos, ss)) + return {}; ss->pv = pv; // For the time being, it must be a dummy and somewhere with a buffer.