diff --git a/src/learn/learner.cpp b/src/learn/learner.cpp index 4b76e444..998c82eb 100644 --- a/src/learn/learner.cpp +++ b/src/learn/learner.cpp @@ -639,13 +639,21 @@ void MultiThinkGenSfen::thread_worker(size_t thread_id) } // reach leaf - // cout << pos; - - auto v = Eval::evaluate(pos); - // evaluate() returns the evaluation value on the turn side, so - // If it's a turn different from root_color, you must invert v and return it. - if (rootColor != pos.side_to_move()) - v = -v; + Value v; + if (pos.checkers()) { + // Sometime a king is checked. An example is a case that a checkmate is + // found in the search. If Eval::evaluate() is called whne a king is + // checked, classic eval crashes by an assertion. To avoid crashes, return + // value1 instead of the score of the PV leaf. + v = value1; + } + else { + v = Eval::evaluate(pos); + // evaluate() returns the evaluation value on the turn side, so + // If it's a turn different from root_color, you must invert v and return it. + if (rootColor != pos.side_to_move()) + v = -v; + } // Rewind. // Is it C++x14, and isn't there even foreach to turn in reverse?