]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Silence idiotic warning on two's complement of an unsigned
[stockfish] / src / search.cpp
index 3617853e5f23d2f3589b7af48da9decbf48e4593..806a9be135e40237c1865987258b008f48efe19a 100644 (file)
@@ -258,7 +258,7 @@ namespace {
                 Depth depth, int ply, int threadID);
   void sp_search(SplitPoint *sp, int threadID);
   void sp_search_pv(SplitPoint *sp, int threadID);
-  void init_node(const Position &pos, SearchStack ss[], int ply, int threadID);
+  void init_node(SearchStack ss[], int ply, int threadID);
   void update_pv(SearchStack ss[], int ply);
   void sp_update_pv(SearchStack *pss, SearchStack ss[], int ply);
   bool connected_moves(const Position &pos, Move m1, Move m2);
@@ -959,7 +959,7 @@ namespace {
 
     // Initialize, and make an early exit in case of an aborted search,
     // an instant draw, maximum ply reached, etc.
-    init_node(pos, ss, ply, threadID);
+    init_node(ss, ply, threadID);
 
     // After init_node() that calls poll()
     if (AbortSearch || thread_should_stop(threadID))
@@ -1155,7 +1155,7 @@ namespace {
 
     // Initialize, and make an early exit in case of an aborted search,
     // an instant draw, maximum ply reached, etc.
-    init_node(pos, ss, ply, threadID);
+    init_node(ss, ply, threadID);
 
     // After init_node() that calls poll()
     if (AbortSearch || thread_should_stop(threadID))
@@ -1424,7 +1424,7 @@ namespace {
 
     // Initialize, and make an early exit in case of an aborted search,
     // an instant draw, maximum ply reached, etc.
-    init_node(pos, ss, ply, threadID);
+    init_node(ss, ply, threadID);
 
     // After init_node() that calls poll()
     if (AbortSearch || thread_should_stop(threadID))
@@ -1451,6 +1451,7 @@ namespace {
     EvalInfo ei;
     Value staticValue;
     bool isCheck = pos.is_check();
+    ei.futilityMargin = Value(0); // Manually initialize futilityMargin
 
     if (isCheck)
         staticValue = -VALUE_INFINITE;
@@ -1462,7 +1463,6 @@ namespace {
         assert(ei.futilityMargin == Value(0));
 
         staticValue = tte->value();
-        ei.futilityMargin = Value(0); // manually initialize futilityMargin
     }
     else
         staticValue = evaluate(pos, ei, threadID);
@@ -1475,15 +1475,12 @@ namespace {
     Value bestValue = staticValue;
 
     if (bestValue >= beta)
-    {
-        // Update transposition table before to leave
-        TT.store(pos, value_to_tt(bestValue, ply), depth, MOVE_NONE, VALUE_TYPE_EXACT);
-        return bestValue;
-    }
-    else if (!isCheck && !tte && ei.futilityMargin == 0)
     {
         // Store the score to avoid a future costly evaluation() call
-        TT.store(pos, value_to_tt(bestValue, ply), Depth(-127*OnePly), MOVE_NONE, VALUE_TYPE_EVAL);
+        if (!isCheck && !tte && ei.futilityMargin == 0)
+            TT.store(pos, value_to_tt(bestValue, ply), Depth(-127*OnePly), MOVE_NONE, VALUE_TYPE_EVAL);
+
+        return bestValue;
     }
 
     if (bestValue > alpha)
@@ -1568,6 +1565,16 @@ namespace {
 
     assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
 
+    // Update transposition table
+    if (!pvNode)
+    {
+        Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
+        if (bestValue < beta)
+            TT.store(pos, value_to_tt(bestValue, ply), d, MOVE_NONE, VALUE_TYPE_UPPER);
+        else
+            TT.store(pos, value_to_tt(bestValue, ply), d, MOVE_NONE, VALUE_TYPE_LOWER);
+    }
+
     // Update killers only for good check moves
     Move m = ss[ply].currentMove;
     if (alpha >= beta && ok_to_history(pos, m)) // Only non capture moves are considered
@@ -2018,7 +2025,7 @@ namespace {
   // NodesBetweenPolls nodes, init_node() also calls poll(), which polls
   // for user input and checks whether it is time to stop the search.
 
-  void init_node(const Position &pos, SearchStack ss[], int ply, int threadID) {
+  void init_node(SearchStack ss[], int ply, int threadID) {
     assert(ply >= 0 && ply < PLY_MAX);
     assert(threadID >= 0 && threadID < ActiveThreads);