+ // update_stats() updates killers, history, countermoves and followupmoves stats after a fail-high
+ // of a quiet move.
+
+ void update_stats(Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt) {
+
+ if (ss->killers[0] != move)
+ {
+ ss->killers[1] = ss->killers[0];
+ ss->killers[0] = move;
+ }
+
+ // Increase history value of the cut-off move and decrease all the other
+ // played quiet moves.
+ Value bonus = Value(int(depth) * int(depth));
+ History.update(pos.moved_piece(move), to_sq(move), bonus);
+ for (int i = 0; i < quietsCnt; ++i)
+ {
+ Move m = quiets[i];
+ History.update(pos.moved_piece(m), to_sq(m), -bonus);
+ }
+
+ if (is_ok((ss-1)->currentMove))
+ {
+ Square prevMoveSq = to_sq((ss-1)->currentMove);
+ Countermoves.update(pos.piece_on(prevMoveSq), prevMoveSq, move);
+ }
+
+ if (is_ok((ss-2)->currentMove) && (ss-1)->currentMove == (ss-1)->ttMove)
+ {
+ Square prevOwnMoveSq = to_sq((ss-2)->currentMove);
+ Followupmoves.update(pos.piece_on(prevOwnMoveSq), prevOwnMoveSq, move);
+ }
+ }
+
+