+ void update(T& entry, int bonus, const int D, const int W) {
+
+ assert(abs(bonus) <= D); // Ensure range is [-W * D, W * D]
+ assert(abs(W * D) < (std::numeric_limits<T>::max)()); // Ensure we don't overflow
+
+ entry += bonus * W - entry * abs(bonus) / D;
+
+ assert(abs(entry) <= W * D);
+ }
+};
+
+/// ButterflyBoards are 2 tables (one for each color) indexed by the move's from
+/// and to squares, see chessprogramming.wikispaces.com/Butterfly+Boards
+typedef StatBoards<COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyBoards;
+
+/// PieceToBoards are addressed by a move's [piece][to] information
+typedef StatBoards<PIECE_NB, SQUARE_NB> PieceToBoards;
+
+/// CapturePieceToBoards are addressed by a move's [piece][to][captured piece type] information
+typedef StatCubes<PIECE_NB, SQUARE_NB, PIECE_TYPE_NB> CapturePieceToBoards;
+
+/// ButterflyHistory records how often quiet moves have been successful or
+/// unsuccessful during the current search, and is used for reduction and move
+/// ordering decisions. It uses ButterflyBoards as backing store.
+struct ButterflyHistory : public ButterflyBoards {
+
+ void update(Color c, Move m, int bonus) {
+ StatBoards::update((*this)[c][from_to(m)], bonus, 324);
+ }
+};
+
+/// PieceToHistory is like ButterflyHistory, but is based on PieceToBoards
+struct PieceToHistory : public PieceToBoards {
+
+ void update(Piece pc, Square to, int bonus) {
+ StatBoards::update((*this)[pc][to], bonus, 936);
+ }