]> git.sesse.net Git - stockfish/commitdiff
In qsearch store the cut move in TT
authorMarco Costalba <mcostalba@gmail.com>
Sat, 18 Apr 2009 13:03:33 +0000 (14:03 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 18 Apr 2009 13:04:00 +0000 (14:04 +0100)
And upon reentering the same position try it as first.

Normally qsearch moves order is already very good, first move
is the cut off in almost 90% of cases. With this patch, we get
a cut off on TT move of 98%.

Another good side effect is that we don't generate captures
and/or checks when we already have a TT move.

Unfortunatly we found a TT move only in 1% of cases. So real
impact of this patch is relatively low.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/movepick.cpp
src/movepick.h
src/search.cpp

index 4eb842a0e3e7d9eda96a7bf1e7a1ff1c599bb013..fb218f3d6c26a7a52bdc43744f4d8a5365026ff6 100644 (file)
@@ -50,7 +50,6 @@ namespace {
 }
 
 
-
 ////
 //// Functions
 ////
@@ -445,9 +444,9 @@ Move MovePicker::pick_move_from_list() {
           bestIndex = (movesPicked < 4 ? find_best_index() : movesPicked);
           move = moves[bestIndex].move;
           moves[bestIndex] = moves[movesPicked++];
-          // Remember to change the line below if we decide to hash the qsearch!
-          // Maybe also postpone the legality check until after futility pruning?
-          if (/* move != ttMove && */ pos.pl_move_is_legal(move, pinned))
+          // Maybe postpone the legality check until after futility pruning?
+          if (   move != ttMove
+              && pos.pl_move_is_legal(move, pinned))
               return move;
       }
       break;
@@ -460,8 +459,8 @@ Move MovePicker::pick_move_from_list() {
       while (movesPicked < numOfMoves)
       {
           move = moves[movesPicked++].move;
-          // Remember to change the line below if we decide to hash the qsearch!
-          if (/* move != ttMove && */ pos.pl_move_is_legal(move, pinned))
+          if (   move != ttMove
+              && pos.pl_move_is_legal(move, pinned))
               return move;
       }
       break;
@@ -473,20 +472,10 @@ Move MovePicker::pick_move_from_list() {
 }
 
 
-/// MovePicker::current_move_type() returns the type of the just
-/// picked next move. It can be used in search to further differentiate
-/// according to the current move type: capture, non capture, escape, etc.
-MovePicker::MovegenPhase MovePicker::current_move_type() const {
-
-  return PhaseTable[phaseIndex];
-}
-
-
 /// MovePicker::init_phase_table() initializes the PhaseTable[],
 /// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex
-/// QsearchNoCapturesPhaseIndex, QsearchWithoutChecksPhaseIndex and
-/// NoMovesPhaseIndex variables. It is only called once during program
-/// startup, and never again while the program is running.
+/// and QsearchWithoutChecksPhaseIndex. It is only called once during
+/// program startup, and never again while the program is running.
 
 void MovePicker::init_phase_table() {
 
@@ -511,12 +500,14 @@ void MovePicker::init_phase_table() {
 
   // Quiescence search with checks
   QsearchWithChecksPhaseIndex = i - 1;
+  PhaseTable[i++] = PH_TT_MOVE;
   PhaseTable[i++] = PH_QCAPTURES;
   PhaseTable[i++] = PH_QCHECKS;
   PhaseTable[i++] = PH_STOP;
 
   // Quiescence search without checks
   QsearchWithoutChecksPhaseIndex = i - 1;
+  PhaseTable[i++] = PH_TT_MOVE;
   PhaseTable[i++] = PH_QCAPTURES;
   PhaseTable[i++] = PH_STOP;
 
index a5403e096a834d2d9538ae29827109d2d1d828f8..4ae40685a86e9811061fb6eec5ea5e4104857107 100644 (file)
@@ -70,7 +70,6 @@ public:
   Move get_next_move(Lock &lock);
   int number_of_moves() const;
   int current_move_score() const;
-  MovegenPhase current_move_type() const;
   Bitboard discovered_check_candidates() const;
 
   static void init_phase_table();
index 21aa4f92069dbcbbf7997b73364b641444fc9ed2..cc49311692567ea5bcc2ef38f526863402d296e9 100644 (file)
@@ -1516,6 +1516,7 @@ namespace {
             return value_from_tt(tte->value(), ply);
         }
     }
+    Move ttMove = (tte ? tte->move() : MOVE_NONE);
 
     // Evaluate the position statically
     EvalInfo ei;
@@ -1559,7 +1560,7 @@ namespace {
     // Initialize a MovePicker object for the current position, and prepare
     // to search the moves.  Because the depth is <= 0 here, only captures,
     // queen promotions and checks (only if depth == 0) will be generated.
-    MovePicker mp = MovePicker(pos, pvNode, MOVE_NONE, EmptySearchStack, depth);
+    MovePicker mp = MovePicker(pos, pvNode, ttMove, EmptySearchStack, depth);
     Move move;
     int moveCount = 0;
     Bitboard dcCandidates = mp.discovered_check_candidates();
@@ -1636,22 +1637,20 @@ namespace {
     assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
 
     // Update transposition table
+    Move m = ss[ply].pv[ply];
     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);
+            TT.store(pos, value_to_tt(bestValue, ply), d, m, 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
-    {
-        // Wrong to update history when depth is <= 0
         update_killers(m, ss[ply]);
-    }
+
     return bestValue;
   }