Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
- Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
+ Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
const int BishopCheck = 588;
const int KnightCheck = 924;
+ // Threshold for lazy evaluation
+ const Value LazyEval = Value(1500);
// eval_init() initializes king and attack bitboards for a given color
// adding pawn attacks. To be done at the beginning of the evaluation.
return sf;
}
+
+ Value lazy_eval(Value mg, Value eg) {
+
+ if (mg > LazyEval && eg > LazyEval)
+ return LazyEval + ((mg + eg) / 2 - LazyEval) / 4;
+
+ else if (mg < -LazyEval && eg < -LazyEval)
+ return -LazyEval + ((mg + eg) / 2 + LazyEval) / 4;
+
+ return VALUE_ZERO;
+ }
+
} // namespace
ei.pi = Pawns::probe(pos);
score += ei.pi->pawns_score();
+ // We have taken into account all cheap evaluation terms.
+ // If score exceeds a threshold return a lazy evaluation.
+ Value lazy = lazy_eval(mg_value(score), eg_value(score));
+ if (lazy)
+ return pos.side_to_move() == WHITE ? lazy : -lazy;
+
// Initialize attack and king safety bitboards
ei.attackedBy[WHITE][ALL_PIECES] = ei.attackedBy[BLACK][ALL_PIECES] = 0;
ei.attackedBy[WHITE][KING] = pos.attacks_from<KING>(pos.square<KING>(WHITE));