+ isCheck = pos.is_check();
+
+ // Calculate depth dependant futility pruning parameters
+ const int FutilityMoveCountMargin = 3 + (1 << (3 * int(depth) / 8));
+
+ // 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 + FutilityMargins[int(depth)]; //FIXME: Remove me, only for split
+ staticValue = refine_eval(tte, staticValue, ply); // Enhance accuracy with TT value if possible
+ update_gains(pos, ss[ply - 1].currentMove, ss[ply - 1].eval, ss[ply].eval);
+ }
+
+ // Static null move pruning. We're betting that the opponent doesn't have
+ // a move that will reduce the score by more than FutilityMargins[int(depth)]
+ // if we do a null move.
+ if ( !isCheck
+ && allowNullmove
+ && depth < RazorDepth
+ && staticValue - FutilityMargins[int(depth)] >= beta)
+ return staticValue - FutilityMargins[int(depth)];
+
+ // Null move search
+ if ( allowNullmove
+ && depth > OnePly
+ && !isCheck
+ && !value_is_mate(beta)
+ && ok_to_do_nullmove(pos)
+ && staticValue >= beta - NullMoveMargin)
+ {
+ ss[ply].currentMove = MOVE_NULL;
+
+ pos.do_null_move(st);
+
+ // Null move dynamic reduction based on depth
+ int R = 3 + (depth >= 5 * OnePly ? depth / 8 : 0);
+
+ // Null move dynamic reduction based on value
+ if (staticValue - beta > PawnValueMidgame)
+ R++;