- // Enhance score accuracy with TT value if possible
- ss[ply].eval = staticValue;
- futilityValue = staticValue + FutilityValueMargin;
- staticValue = refine_eval(tte, staticValue, ply);
+ // Evaluate the position statically
+ if (!isCheck)
+ {
+ if (tte && (tte->type() & VALUE_TYPE_EVAL))
+ staticValue = value_from_tt(tte->value(), ply);
+ else
+ {
+ staticValue = evaluate(pos, ei, threadID);
+ ss[ply].evalInfo = &ei;
+ }
+
+ ss[ply].eval = staticValue;
+ futilityValue = staticValue + FutilityValueMargin;
+ staticValue = refine_eval(tte, staticValue, ply); // Enhance accuracy with TT value if possible
+
+ // Store gain statistics
+ Move m = ss[ply - 1].currentMove;
+ if ( m != MOVE_NULL
+ && pos.captured_piece() == NO_PIECE_TYPE
+ && !move_is_castle(m)
+ && !move_is_promotion(m))
+ MG.store(pos.piece_on(move_to(m)), move_from(m), move_to(m), ss[ply - 1].eval, -ss[ply].eval);
+ }
+
+ // Post futility pruning
+ if (staticValue - FutilityValueMargin >= beta)
+ return (staticValue - FutilityValueMargin);