- eval = ss->staticEval = evaluate(pos);
- TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval);
+ eval = ss->staticEval = evaluate(pos, ss->evalMargin);
+ TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE,
+ ss->staticEval, ss->evalMargin);
+ }
+
+ // Update gain for the parent non-capture move given the static position
+ // evaluation before and after the move.
+ if ( !pos.captured_piece_type()
+ && ss->staticEval != VALUE_NONE
+ && (ss-1)->staticEval != VALUE_NONE
+ && (move = (ss-1)->currentMove) != MOVE_NULL
+ && type_of(move) == NORMAL)
+ {
+ Square to = to_sq(move);
+ Gains.update(pos.piece_on(to), to, -(ss-1)->staticEval - ss->staticEval);