]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
History Pruning: Don't prune the main killer move.
[stockfish] / src / search.cpp
index 58a52831a729c9f69cd15fd9e72210c7fea6decc..4a0302e51f9e7087d72892bdc23e84339ddef191 100644 (file)
@@ -220,11 +220,11 @@ uint64_t Search::perft(Position& pos, Depth depth) {
 template uint64_t Search::perft<true>(Position&, Depth);
 
 
-/// MainThread::think() is called by the main thread when the program receives
+/// MainThread::search() is called by the main thread when the program receives
 /// the UCI 'go' command. It searches from root position and at the end prints
 /// the "bestmove" to output.
 
-void MainThread::think() {
+void MainThread::search() {
 
   Color us = rootPos.side_to_move();
   Time.init(Limits, us, rootPos.game_ply());
@@ -299,15 +299,7 @@ void MainThread::think() {
           }
       }
 
-      search(true); // Let's start searching!
-
-      // Stop the threads
-      Signals.stop = true;
-
-      // Wait until all threads have finished
-      for (Thread* th : Threads)
-          if (th != this)
-              th->wait_while(th->searching);
+      Thread::search(); // Let's start searching!
   }
 
   // When playing in 'nodes as time' mode, subtract the searched nodes from
@@ -326,6 +318,14 @@ void MainThread::think() {
       wait(Signals.stop);
   }
 
+  // Stop the threads if not already stopped
+  Signals.stop = true;
+
+  // Wait until all threads have finished
+  for (Thread* th : Threads)
+      if (th != this)
+          th->join();
+
   // Check if there are threads with a better score than main thread.
   Thread* bestThread = this;
   for (Thread* th : Threads)
@@ -351,11 +351,12 @@ void MainThread::think() {
 // repeatedly with increasing depth until the allocated thinking time has been
 // consumed, user stops the search, or the maximum search depth is reached.
 
-void Thread::search(bool isMainThread) {
+void Thread::search() {
 
   Stack stack[MAX_PLY+4], *ss = stack+2; // To allow referencing (ss-2) and (ss+2)
   Value bestValue, alpha, beta, delta;
   Move easyMove = MOVE_NONE;
+  bool isMainThread = (this == Threads.main());
 
   std::memset(ss-2, 0, 5 * sizeof(Stack));
 
@@ -532,9 +533,6 @@ void Thread::search(bool isMainThread) {
       }
   }
 
-  searching = false;
-  notify_one(); // Wake up main thread if is sleeping waiting for us
-
   if (!isMainThread)
       return;
 
@@ -583,15 +581,15 @@ namespace {
     ss->ply = (ss-1)->ply + 1;
 
     // Check for available remaining time
-    if (thisThread->resetCallsCnt.load(std::memory_order_relaxed))
+    if (thisThread->resetCalls.load(std::memory_order_relaxed))
     {
-        thisThread->resetCallsCnt = false;
+        thisThread->resetCalls = false;
         thisThread->callsCnt = 0;
     }
     if (++thisThread->callsCnt > 4096)
     {
         for (Thread* th : Threads)
-            th->resetCallsCnt = true;
+            th->resetCalls = true;
 
         check_time();
     }
@@ -923,7 +921,8 @@ moves_loop: // When in check search starts from here
               continue;
 
           // History based pruning
-          if (   depth <= 3 * ONE_PLY
+          if (   depth <= 4 * ONE_PLY
+              && move != ss->killers[0]
               && thisThread->history[pos.moved_piece(move)][to_sq(move)] < VALUE_ZERO
               && cmh[pos.moved_piece(move)][to_sq(move)] < VALUE_ZERO)
               continue;