]> git.sesse.net Git - stockfish/blobdiff - src/movepick.h
simplify logic for history based pruning
[stockfish] / src / movepick.h
index 6c8d9e10e3d9e05453d34424f123c47103b56b35..ef3be6c240f8d553b42c68756e48fa512b5bdf3d 100644 (file)
@@ -2,7 +2,7 @@
   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
   Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
   Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
-  Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
+  Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
 
   Stockfish is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -39,13 +39,14 @@ struct HistoryStats {
   void clear() { std::memset(table, 0, sizeof(table)); }
   void update(Color c, Move m, Value v) {
 
-    if (abs(int(v)) >= 324)
-        return;
-
     Square from = from_sq(m);
     Square to = to_sq(m);
 
-    table[c][from][to] -= table[c][from][to] * abs(int(v)) / 324;
+    const int denom = 324;
+
+    assert(abs(int(v)) <= denom); // Needed for stability.
+
+    table[c][from][to] -= table[c][from][to] * abs(int(v)) / denom;
     table[c][from][to] += int(v) * 32;
   }
 
@@ -60,18 +61,20 @@ private:
 /// Entries are stored using only the moving piece and destination square, hence
 /// two moves with different origin but same destination and piece will be
 /// considered identical.
-template<typename T, bool CM = false>
+template<typename T>
 struct Stats {
   const T* operator[](Piece pc) const { return table[pc]; }
   T* operator[](Piece pc) { return table[pc]; }
   void clear() { std::memset(table, 0, sizeof(table)); }
+  void fill(const Value& v) { std::fill(&table[0][0], &table[PIECE_NB-1][SQUARE_NB-1]+1, v); };
   void update(Piece pc, Square to, Move m) { table[pc][to] = m; }
   void update(Piece pc, Square to, Value v) {
 
-    if (abs(int(v)) >= 324)
-        return;
+    const int denom = 936;
+
+    assert(abs(int(v)) <= denom); // Needed for stability.
 
-    table[pc][to] -= table[pc][to] * abs(int(v)) / (CM ? 936 : 324);
+    table[pc][to] -= table[pc][to] * abs(int(v)) / denom;
     table[pc][to] += int(v) * 32;
   }
 
@@ -80,7 +83,7 @@ private:
 };
 
 typedef Stats<Move> MoveStats;
-typedef Stats<Value, true> CounterMoveStats;
+typedef Stats<Value> CounterMoveStats;
 typedef Stats<CounterMoveStats> CounterMoveHistoryStats;
 
 
@@ -101,7 +104,7 @@ public:
   MovePicker(const Position&, Move, Depth, Square);
   MovePicker(const Position&, Move, Depth, Search::Stack*);
 
-  Move next_move();
+  Move next_move(bool skipQuiets = false);
 
 private:
   template<GenType> void score();