- // Blend optimism with nnue complexity and (semi)classical complexity
- optimism += optimism * (nnueComplexity + abs(psq - nnue)) / 512;
- v = (nnue * (945 + npm) + optimism * (150 + npm)) / 1024;
+ Value v;
+ Color stm = pos.side_to_move();
+ int shuffling = pos.rule50_count();
+ int simpleEval = simple_eval(pos, stm) + (int(pos.key() & 7) - 3);
+
+ bool lazy = abs(simpleEval) >= RookValue + KnightValue
+ + 16 * shuffling * shuffling
+ + abs(pos.this_thread()->bestValue)
+ + abs(pos.this_thread()->rootSimpleEval);
+
+ if (lazy)
+ v = Value(simpleEval);
+ else
+ {
+ int nnueComplexity;
+ Value nnue = NNUE::evaluate(pos, true, &nnueComplexity);
+
+ Value optimism = pos.this_thread()->optimism[stm];
+
+ // Blend optimism and eval with nnue complexity and material imbalance
+ optimism += optimism * (nnueComplexity + abs(simpleEval - nnue)) / 512;
+ nnue -= nnue * (nnueComplexity + abs(simpleEval - nnue)) / 32768;
+
+ int npm = pos.non_pawn_material() / 64;
+ v = ( nnue * (915 + npm + 9 * pos.count<PAWN>())
+ + optimism * (154 + npm )) / 1024;
+ }