]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Simplify wait_for_stop_or_ponderhit()
[stockfish] / src / search.cpp
index a2424ddc3ddb05886dee4af9a8c06c64972dddc6..061bbafca0cd1a4b7e0885407ce76a68938c1b23 100644 (file)
@@ -300,7 +300,6 @@ namespace {
   bool connected_threat(const Position& pos, Move m, Move threat);
   Value refine_eval(const TTEntry* tte, Value defaultEval, int ply);
   void update_history(const Position& pos, Move move, Depth depth, Move movesSearched[], int moveCount);
-  void update_killers(Move m, Move killers[]);
   void update_gains(const Position& pos, Move move, Value before, Value after);
 
   int current_search_time();
@@ -515,7 +514,7 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[
 
   // Do we have to play with skill handicap? In this case enable MultiPV that
   // we will use behind the scenes to retrieve a set of possible moves.
-  MultiPV = (SkillLevel < 10 ? Max(UCIMultiPV, 4) : UCIMultiPV);
+  MultiPV = (SkillLevel < 20 ? Max(UCIMultiPV, 4) : UCIMultiPV);
 
   // Set the number of active threads
   ThreadsMgr.read_uci_options();
@@ -756,9 +755,9 @@ namespace {
         }
     }
 
-    // When playing with strength handicap choose best move among the MultiPV
-    // set using a statistical rule dependent on SkillLevel.
-    if (SkillLevel < 10)
+    // When playing with strength handicap choose best move among the MultiPV set
+    // using a statistical rule dependent on SkillLevel. Idea by Heinz van Saanen.
+    if (SkillLevel < 20)
     {
         assert(MultiPV > 1);
 
@@ -768,7 +767,7 @@ namespace {
         int size = Min(MultiPV, (int)Rml.size());
         int max = Rml[0].pv_score;
         int var = Min(max - Rml[size - 1].pv_score, PawnValueMidgame);
-        int wk = 128 - 8 * SkillLevel;
+        int wk = 120 - 2 * SkillLevel;
 
         // PRNG sequence should be non deterministic
         for (int i = abs(get_system_time() % 50); i > 0; i--)
@@ -1347,8 +1346,12 @@ split_point_start: // At split points actual search starts from here
         if (    bestValue >= beta
             && !pos.move_is_capture_or_promotion(move))
         {
+            if (move != ss->killers[0])
+            {
+                ss->killers[1] = ss->killers[0];
+                ss->killers[0] = move;
+            }
             update_history(pos, move, depth, movesSearched, playedMoveCount);
-            update_killers(move, ss->killers);
         }
     }
 
@@ -1867,19 +1870,6 @@ split_point_start: // At split points actual search starts from here
   }
 
 
-  // update_killers() add a good move that produced a beta-cutoff
-  // among the killer moves of that ply.
-
-  void update_killers(Move m, Move killers[]) {
-
-    if (m != killers[0])
-    {
-        killers[1] = killers[0];
-        killers[0] = m;
-    }
-  }
-
-
   // update_gains() updates the gains table of a non-capture move given
   // the static position evaluation before and after the move.
 
@@ -1893,6 +1883,7 @@ split_point_start: // At split points actual search starts from here
         H.update_gain(pos.piece_on(move_to(m)), move_to(m), -(before + after));
   }
 
+
   // current_search_time() returns the number of milliseconds which have passed
   // since the beginning of the current search.
 
@@ -1953,10 +1944,7 @@ split_point_start: // At split points actual search starts from here
         // We are line oriented, don't read single chars
         std::string command;
 
-        if (!std::getline(std::cin, command))
-            command = "quit";
-
-        if (command == "quit")
+        if (!std::getline(std::cin, command) || command == "quit")
         {
             // Quit the program as soon as possible
             Pondering = false;
@@ -2034,20 +2022,12 @@ split_point_start: // At split points actual search starts from here
 
     std::string command;
 
-    while (true)
-    {
-        // Wait for a command from stdin
-        if (!std::getline(std::cin, command))
-            command = "quit";
+    // Wait for a command from stdin
+    while (   std::getline(std::cin, command)
+           && command != "ponderhit" && command != "stop" && command != "quit") {};
 
-        if (command == "quit")
-        {
-            QuitRequest = true;
-            break;
-        }
-        else if (command == "ponderhit" || command == "stop")
-            break;
-    }
+    if (command != "ponderhit" && command != "stop")
+        QuitRequest = true; // Must be "quit" or getline() returned false
   }