]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Fix 'position ..... moves ' parsing bug
[stockfish] / src / search.cpp
index 660fb7ed4f045d85f886b10c3d8687be24fe2368..09b483cfc4143ec056b1ced25620245f9a925672 100644 (file)
@@ -100,7 +100,7 @@ namespace {
     // sorting the moves. A move m1 is considered to be better
     // than a move m2 if it has a higher score, or if the moves
     // have equal score but m1 has the higher node count.
-    bool RootMove::operator<(const RootMove& m) const {
+    bool operator<(const RootMove& m) const {
 
         return score != m.score ? score < m.score : theirBeta <= m.theirBeta;
     }
@@ -288,6 +288,7 @@ namespace {
   bool ok_to_do_nullmove(const Position& pos);
   bool ok_to_prune(const Position& pos, Move m, Move threat);
   bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
+  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, SearchStack& ss);
 
@@ -1360,7 +1361,7 @@ namespace {
         return value_from_tt(tte->value(), ply);
     }
 
-    approximateEval = quick_evaluate(pos);
+    approximateEval = refine_eval(tte, quick_evaluate(pos), ply);
     isCheck = pos.is_check();
 
     // Null move search
@@ -1376,7 +1377,7 @@ namespace {
         pos.do_null_move(st);
 
         // Null move dynamic reduction based on depth
-        int R = (depth >= 5 * OnePly ? 4 : 3);
+        int R = 3 + (depth >= 5 * OnePly ? depth / 8 : 0);
 
         // Null move dynamic reduction based on value
         if (approximateEval - beta > PawnValueMidgame)
@@ -2126,13 +2127,13 @@ namespace {
 
   // RootMoveList simple methods definitions
 
-  inline void RootMoveList::set_move_nodes(int moveNum, int64_t nodes) {
+  void RootMoveList::set_move_nodes(int moveNum, int64_t nodes) {
 
     moves[moveNum].nodes = nodes;
     moves[moveNum].cumulativeNodes += nodes;
   }
 
-  inline void RootMoveList::set_beta_counters(int moveNum, int64_t our, int64_t their) {
+  void RootMoveList::set_beta_counters(int moveNum, int64_t our, int64_t their) {
 
     moves[moveNum].ourBeta = our;
     moves[moveNum].theirBeta = their;
@@ -2152,7 +2153,7 @@ namespace {
   // RootMoveList::sort() sorts the root move list at the beginning of a new
   // iteration.
 
-  inline void RootMoveList::sort() {
+  void RootMoveList::sort() {
 
     sort_multipv(count - 1); // Sort all items
   }
@@ -2474,6 +2475,23 @@ namespace {
   }
 
 
+  // refine_eval() returns the transposition table score if
+  // possible otherwise falls back on static position evaluation.
+
+  Value refine_eval(const TTEntry* tte, Value defaultEval, int ply) {
+
+      if (!tte)
+          return defaultEval;
+
+      Value v = value_from_tt(tte->value(), ply);
+
+      if (   (is_lower_bound(tte->type()) && v >= defaultEval)
+          || (is_upper_bound(tte->type()) && v < defaultEval))
+          return v;
+
+      return defaultEval;
+  }
+
   // update_history() registers a good move that produced a beta-cutoff
   // in history and marks as failures all the other moves of that ply.