- bool useNullMove = ( allowNullmove
- && depth > OnePly
- && !isCheck
- && !value_is_mate(beta)
- && ok_to_do_nullmove(pos)
- && approximateEval >= beta - NullMoveMargin);
+ ss[ply].eval = staticValue;
+ futilityValue = staticValue + PostFutilityValueMargin; //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);
+ }
+
+ // Do a "stand pat". If we are above beta by a good margin then
+ // return immediately.
+ // FIXME: test with added condition 'allowNullmove || depth <= OnePly' and !value_is_mate(beta)
+ // FIXME: test with modified condition 'depth < RazorDepth'
+ if ( !isCheck
+ && depth < SelectiveDepth
+ && staticValue - PostFutilityValueMargin >= beta)
+ return staticValue - PostFutilityValueMargin;
+
+ // 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++;
+
+ nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID);
+
+ pos.undo_null_move();