]> git.sesse.net Git - stockfish/commitdiff
Use two counter moves instead of one
authorJoona Kiiski <joona.kiiski@gmail.com>
Wed, 15 May 2013 19:31:45 +0000 (20:31 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 16 May 2013 14:20:50 +0000 (16:20 +0200)
Very good at long 60"+0.05 TC
LLR: 2.95 (-2.94,2.94)
Total: 5954 W: 1151 L: 1016 D: 3787

[edit: slightly changed form original patch to avoid useless loop
 across killers when killer is MOVE_NONE]

bench: 4327405

src/movepick.cpp
src/movepick.h

index c75526cc81b8b4989ca22fad6c54b3b5178a2c18..a729873677d9385f18159b93aebf45c9b7272e1c 100644 (file)
@@ -90,7 +90,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
       killers[0].move = ss->killers[0];
       killers[1].move = ss->killers[1];
       Square prevSq = to_sq((ss-1)->currentMove);
       killers[0].move = ss->killers[0];
       killers[1].move = ss->killers[1];
       Square prevSq = to_sq((ss-1)->currentMove);
-      killers[2].move = cm[pos.piece_on(prevSq)][prevSq];
+      killers[2].move = cm[pos.piece_on(prevSq)][prevSq].first;
+      killers[3].move = cm[pos.piece_on(prevSq)][prevSq].second;
 
       // Consider sligtly negative captures as good if at low depth and far from beta
       if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
 
       // Consider sligtly negative captures as good if at low depth and far from beta
       if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
@@ -239,7 +240,17 @@ void MovePicker::generate_next() {
 
   case KILLERS_S1:
       cur = killers;
 
   case KILLERS_S1:
       cur = killers;
-      end = cur + 3 - (killers[2].move == killers[0].move || killers[2].move == killers[1].move);
+      end = cur + 2;
+
+      if ((cur+3)->move && (cur+3)->move == (cur+2)->move) // Due to a SMP race
+          (cur+3)->move = MOVE_NONE;
+
+      // Be sure countermoves are different from killers
+      if ((cur+2)->move != cur->move && (cur+2)->move != (cur+1)->move)
+          end++;
+
+      if ((cur+3)->move != cur->move && (cur+3)->move != (cur+1)->move)
+          (end++)->move = (cur+3)->move;
       return;
 
   case QUIETS_1_S1:
       return;
 
   case QUIETS_1_S1:
@@ -332,7 +343,8 @@ Move MovePicker::next_move<false>() {
           if (   move != ttMove
               && move != killers[0].move
               && move != killers[1].move
           if (   move != ttMove
               && move != killers[0].move
               && move != killers[1].move
-              && move != killers[2].move)
+              && move != killers[2].move
+              && move != killers[3].move)
               return move;
           break;
 
               return move;
           break;
 
index fe9e5a7c08ab31f1b58882354054515e49688dd9..8997c93872c46766bf137f1d4cc73cd46194f1a9 100644 (file)
@@ -42,10 +42,18 @@ struct Stats {
 
   static const Value Max = Value(2000);
 
 
   static const Value Max = Value(2000);
 
-  const T* operator[](Piece p) const { return &table[p][0]; }
+  const T* operator[](Piece p) const { return table[p]; }
   void clear() { memset(table, 0, sizeof(table)); }
 
   void clear() { memset(table, 0, sizeof(table)); }
 
-  void update(Piece p, Square to, Move m) { table[p][to] = m; }
+  void update(Piece p, Square to, Move m) {
+
+    if (m == table[p][to].first)
+        return;
+
+    table[p][to].second = table[p][to].first;
+    table[p][to].first = m;
+  }
+
   void update(Piece p, Square to, Value v) {
 
     if (Gain)
   void update(Piece p, Square to, Value v) {
 
     if (Gain)
@@ -61,7 +69,7 @@ private:
 
 typedef Stats< true, Value> GainsStats;
 typedef Stats<false, Value> HistoryStats;
 
 typedef Stats< true, Value> GainsStats;
 typedef Stats<false, Value> HistoryStats;
-typedef Stats<false,  Move> CountermovesStats;
+typedef Stats<false, std::pair<Move, Move> > CountermovesStats;
 
 
 /// MovePicker class is used to pick one pseudo legal move at a time from the
 
 
 /// MovePicker class is used to pick one pseudo legal move at a time from the
@@ -92,7 +100,7 @@ private:
   Search::Stack* ss;
   Depth depth;
   Move ttMove;
   Search::Stack* ss;
   Depth depth;
   Move ttMove;
-  MoveStack killers[3];
+  MoveStack killers[4];
   Square recaptureSquare;
   int captureThreshold, phase;
   MoveStack *cur, *end, *endQuiets, *endBadCaptures;
   Square recaptureSquare;
   int captureThreshold, phase;
   MoveStack *cur, *end, *endQuiets, *endBadCaptures;