]> git.sesse.net Git - stockfish/blobdiff - src/movepick.cpp
Micro optimize and rename move_promotion()
[stockfish] / src / movepick.cpp
index 60fcbaa53364d1ecadd8363908f3163f3ea1db6d..cea4efb4bebd1a00deb723e4920d7306db09aa42 100644 (file)
@@ -63,24 +63,25 @@ namespace {
 /// search captures, promotions and some checks) and about how important good
 /// move ordering is at the current node.
 
-MovePicker::MovePicker(const Position& p, bool pv, Move ttm,
-                       const SearchStack& ss, Depth d) : pos(p) {
-  pvNode = pv;
+MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
+                       const History& h, SearchStack* ss) : pos(p), H(h) {
   ttMove = ttm;
-  mateKiller = (ss.mateKiller == ttm)? MOVE_NONE : ss.mateKiller;
-  killer1 = ss.killers[0];
-  killer2 = ss.killers[1];
-  depth = d;
-  movesPicked = 0;
-  numOfMoves = 0;
-  numOfBadCaptures = 0;
-  checkKillers = checkLegal = false;
+  if (ss)
+  {
+      mateKiller = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller;
+      killer1 = ss->killers[0];
+      killer2 = ss->killers[1];
+  } else
+      mateKiller = killer1 = killer2 = MOVE_NONE;
+
+  movesPicked = numOfMoves = numOfBadCaptures = 0;
+  checkKillers = checkLegal = finished = false;
 
   if (p.is_check())
       phaseIndex = EvasionsPhaseIndex;
-  else if (depth > Depth(0))
+  else if (d > Depth(0))
       phaseIndex = MainSearchPhaseIndex;
-  else if (depth == Depth(0))
+  else if (d == Depth(0))
       phaseIndex = QsearchWithChecksPhaseIndex;
   else
       phaseIndex = QsearchWithoutChecksPhaseIndex;
@@ -162,7 +163,9 @@ Move MovePicker::get_next_move() {
         break;
 
     case PH_BAD_CAPTURES:
-        // It's probably a good idea to use SEE move ordering here. FIXME
+        // Bad captures SEE value is already calculated by score_captures()
+        // so just sort them to get SEE move ordering.
+        std::sort(badCaptures, badCaptures + numOfBadCaptures);
         movesPicked = 0;
         break;
 
@@ -244,7 +247,7 @@ void MovePicker::score_captures() {
       seeValue = pos.see(m);
       if (seeValue >= 0)
       {
-          if (move_promotion(m))
+          if (move_is_promotion(m))
               moves[i].score = QueenValueMidgame;
           else
               moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))
@@ -304,7 +307,7 @@ void MovePicker::score_qcaptures() {
   for (int i = 0; i < numOfMoves; i++)
   {
       Move m = moves[i].move;
-      if (move_promotion(m))
+      if (move_is_promotion(m))
           moves[i].score = QueenValueMidgame;
       else
           moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m)))