]> git.sesse.net Git - stockfish/blobdiff - src/movepick.cpp
Add psqt ordering when there is no history
[stockfish] / src / movepick.cpp
index a18c46923b60742160816fddb3d9c8ff2734dc35..d0ceaf1c23e8166263e88d10401c035e9cc0d2e5 100644 (file)
@@ -38,6 +38,7 @@ namespace {
 
   /// Variables
 
+  MovePicker::MovegenPhase PhaseTable[32];  
   int MainSearchPhaseIndex;
   int EvasionsPhaseIndex;
   int QsearchWithChecksPhaseIndex;
@@ -45,8 +46,6 @@ namespace {
 
 }
 
-// Static array definition
-MovePicker::MovegenPhase MovePicker::PhaseTable[32];
 
 
 ////
@@ -247,15 +246,36 @@ void MovePicker::score_captures() {
 }
 
 void MovePicker::score_noncaptures() {
-  for(int i = 0; i < numOfMoves; i++) {
-    Move m = moves[i].move;
-    if(m == killer1)
-      moves[i].score = HistoryMax + 2;
-    else if(m == killer2)
-      moves[i].score = HistoryMax + 1;
-    else
-      moves[i].score = H.move_ordering_score(pos->piece_on(move_from(m)), m);
+
+  bool all_zero = true;
+  for (int i = 0; i < numOfMoves; i++)
+  {
+      Move m = moves[i].move;
+      if (m == killer1)
+      {
+          moves[i].score = HistoryMax + 2;
+          all_zero = false;
+      }
+      else if (m == killer2)
+      {
+          moves[i].score = HistoryMax + 1;
+          all_zero = false;
+      }
+      else
+      {
+          moves[i].score = H.move_ordering_score(pos->piece_on(move_from(m)), m);
+          if (all_zero && moves[i].score != 0)
+              all_zero = false;
+      }
   }
+  if (!all_zero)
+      return;
+
+  // If we don't have at least one history score then
+  // try to order using psq tables difference between 
+  // from square and to square.
+  for (int i = 0; i < numOfMoves; i++)
+      moves[i].score = pos->mg_pst_delta(moves[i].move);
 }
 
 void MovePicker::score_evasions() {
@@ -440,6 +460,9 @@ Move MovePicker::pick_move_from_list() {
   return MOVE_NONE;
 }
 
+MovePicker::MovegenPhase MovePicker::current_move_type() const {
+  return PhaseTable[phaseIndex];
+}
 
 /// MovePicker::init_phase_table() initializes the PhaseTable[],
 /// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex