]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Use MovePicker's move ordering also at root
[stockfish] / src / search.cpp
index 8c941794bc4f9fbf436e363061acb64e4c630043..68b19cd34b116bf229e26e9e1dee9c1de7d728aa 100644 (file)
@@ -117,7 +117,7 @@ namespace {
 
   struct RootMove {
 
-    RootMove() { nodes = cumulativeNodes = ourBeta = theirBeta = 0ULL; }
+    RootMove() { mp_score = 0; nodes = cumulativeNodes = ourBeta = theirBeta = 0ULL; }
 
     // RootMove::operator<() is the comparison function used when
     // sorting the moves. A move m1 is considered to be better
@@ -125,11 +125,12 @@ namespace {
     // have equal score but m1 has the higher beta cut-off count.
     bool operator<(const RootMove& m) const {
 
-        return score != m.score ? score < m.score : theirBeta <= m.theirBeta;
+        return score != m.score ? score < m.score : mp_score <= m.mp_score;
     }
 
     Move move;
     Value score;
+    int mp_score;
     int64_t nodes, cumulativeNodes, ourBeta, theirBeta;
     Move pv[PLY_MAX_PLUS_2];
   };
@@ -143,6 +144,8 @@ namespace {
   public:
     RootMoveList(Position& pos, Move searchMoves[]);
 
+    void set_mp_scores(const Position &pos);
+
     int move_count() const { return count; }
     Move get_move(int moveNum) const { return moves[moveNum].move; }
     Value get_move_score(int moveNum) const { return moves[moveNum].score; }
@@ -739,6 +742,7 @@ namespace {
     while (1)
     {
         // Sort the moves before to (re)search
+        rml.set_mp_scores(pos);
         rml.sort();
 
         // Step 10. Loop through all moves in the root move list
@@ -996,7 +1000,7 @@ namespace {
 
     // Step 2. Check for aborted search and immediate draw
     if (AbortSearch || ThreadsMgr.thread_should_stop(threadID))
-        return Value(0);
+        return VALUE_ZERO;
 
     if (pos.is_draw() || ply >= PLY_MAX - 1)
         return VALUE_DRAW;
@@ -1179,7 +1183,7 @@ namespace {
                            && tte
                            && tte->move()
                            && !excludedMove // Do not allow recursive singular extension search
-                           && is_lower_bound(tte->type())
+                           && (tte->type() & VALUE_TYPE_LOWER)
                            && tte->depth() >= depth - 3 * ONE_PLY;
 
     // Step 10. Loop through moves
@@ -1493,7 +1497,7 @@ namespace {
       {
           futilityValue =  futilityBase
                          + pos.endgame_value_of_piece_on(move_to(move))
-                         + (move_is_ep(move) ? PawnValueEndgame : Value(0));
+                         + (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
 
           if (futilityValue < alpha)
           {
@@ -1546,7 +1550,7 @@ namespace {
         return value_mated_in(ply);
 
     // Update transposition table
-    Depth d = (depth == DEPTH_ZERO ? DEPTH_ZERO : Depth(-1));
+    Depth d = (depth == DEPTH_ZERO ? DEPTH_ZERO : DEPTH_ZERO - ONE_PLY);
     ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
     TT.store(pos.get_key(), value_to_tt(bestValue, ply), vt, d, ss->bestMove, ss->eval, ei.kingDanger[pos.side_to_move()]);
 
@@ -1884,7 +1888,7 @@ namespace {
     if (   captureOrPromotion
         && pos.type_of_piece_on(move_to(m)) != PAWN
         && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
-            - pos.midgame_value_of_piece_on(move_to(m)) == Value(0))
+            - pos.midgame_value_of_piece_on(move_to(m)) == VALUE_ZERO)
         && !move_is_promotion(m)
         && !move_is_ep(m))
     {
@@ -1957,8 +1961,8 @@ namespace {
               || v >= Max(value_mate_in(PLY_MAX), beta)
               || v < Min(value_mated_in(PLY_MAX), beta))
 
-          && (   (is_lower_bound(tte->type()) && v >= beta)
-              || (is_upper_bound(tte->type()) && v < beta));
+          && (   ((tte->type() & VALUE_TYPE_LOWER) && v >= beta)
+              || ((tte->type() & VALUE_TYPE_UPPER) && v < beta));
   }
 
 
@@ -1971,8 +1975,8 @@ namespace {
 
       Value v = value_from_tt(tte->value(), ply);
 
-      if (   (is_lower_bound(tte->type()) && v >= defaultEval)
-          || (is_upper_bound(tte->type()) && v < defaultEval))
+      if (   ((tte->type() & VALUE_TYPE_LOWER) && v >= defaultEval)
+          || ((tte->type() & VALUE_TYPE_UPPER) && v < defaultEval))
           return v;
 
       return defaultEval;
@@ -2777,6 +2781,26 @@ namespace {
   }
 
 
+  void RootMoveList::set_mp_scores(const Position &pos)
+  {
+      MovePicker mp = MovePicker(pos, MOVE_NONE, ONE_PLY, H);
+      Move move;
+
+      int moveCount = 0;
+      while ((move = mp.get_next_move()) != MOVE_NONE)
+      {
+          moveCount++;
+          for (int i = 0; i < count; i++)
+          {
+              if (moves[i].move == move)
+              {
+                  moves[i].mp_score = 512 - moveCount;
+                  break;
+              }
+          }
+      }
+  }
+
   // RootMoveList simple methods definitions
 
   void RootMoveList::set_move_nodes(int moveNum, int64_t nodes) {