]> git.sesse.net Git - stockfish/commitdiff
Fix a crash when reaching PLY_MAX in a check position
authorMarco Costalba <mcostalba@gmail.com>
Mon, 12 Oct 2009 14:19:29 +0000 (15:19 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 12 Oct 2009 14:32:50 +0000 (15:32 +0100)
In this case we call evaluate() being in check and this
is not allowed.

Bug found testing with reduced PLY_MAX value as suggested
by Miguel A. Ballicora on talkchess.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/evaluate.cpp
src/search.cpp

index ba3ea9fb4def53ac2351033c3227d3cf7b1455f4..a03f7ddb7a5d3cda8956a73c6b001099efe77985 100644 (file)
@@ -309,6 +309,7 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
 
   assert(pos.is_ok());
   assert(threadID >= 0 && threadID < THREAD_MAX);
+  assert(!pos.is_check());
 
   memset(&ei, 0, sizeof(EvalInfo));
 
index 719fc0eac47fc9ac3ccbcf7dc75071670f9fa10b..c0b6507ce9ecddeffac44bc2bea2df64ed7d2de7 100644 (file)
@@ -1048,7 +1048,7 @@ namespace {
     EvalInfo ei;
 
     if (ply >= PLY_MAX - 1)
-        return evaluate(pos, ei, threadID);
+        return pos.is_check() ? quick_evaluate(pos) : evaluate(pos, ei, threadID);
 
     // Mate distance pruning
     Value oldAlpha = alpha;
@@ -1238,7 +1238,7 @@ namespace {
     EvalInfo ei;
 
     if (ply >= PLY_MAX - 1)
-        return evaluate(pos, ei, threadID);
+        return pos.is_check() ? quick_evaluate(pos) : evaluate(pos, ei, threadID);
 
     // Mate distance pruning
     if (value_mated_in(ply) >= beta)
@@ -1529,8 +1529,8 @@ namespace {
     else
         staticValue = evaluate(pos, ei, threadID);
 
-    if (ply == PLY_MAX - 1)
-        return evaluate(pos, ei, threadID);
+    if (ply >= PLY_MAX - 1)
+        return pos.is_check() ? quick_evaluate(pos) : evaluate(pos, ei, threadID);
 
     // Initialize "stand pat score", and return it immediately if it is
     // at least beta.