- Value approximateEval = quick_evaluate(pos);
- bool mateThreat = false;
- bool isCheck = pos.is_check();
+ isCheck = pos.is_check();
+
+ // Calculate depth dependant futility pruning parameters
+ const int FutilityMoveCountMargin = 3 + (1 << (3 * int(depth) / 8));
+ const int FutilityValueMargin = 112 * bitScanReverse32(int(depth) * int(depth) / 2);
+
+ // Evaluate the position statically
+ if (isCheck)
+ ss[ply].eval = VALUE_NONE;
+ else
+ {
+ if (tte && (tte->type() & VALUE_TYPE_EVAL))
+ staticValue = value_from_tt(tte->value(), ply);
+ else
+ staticValue = evaluate(pos, ei, threadID);
+
+ ss[ply].eval = staticValue;
+ futilityValue = staticValue + FutilityValueMargin;
+ staticValue = refine_eval(tte, staticValue, ply); // Enhance accuracy with TT value if possible
+ }
+
+ // 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++;