From de02768af7b37c903e3227b85ec4d81ec79ba69a Mon Sep 17 00:00:00 2001 From: Stefano Cardanobile Date: Tue, 10 Jan 2017 19:03:27 +0100 Subject: [PATCH] Introduce lazy evaluation After we have taken into account all cheap evaluation terms, we check whether the score exceeds a given threshold. If this is the case, we return a scaled down evaluation. STC: LLR: 3.35 (-2.94,2.94) [0.00,5.00] Total: 12575 W: 2316 L: 2122 D: 8137 LTC: LLR: 2.95 (-2.94,2.94) [0.00,5.00] Total: 67480 W: 9016 L: 8677 D: 49787 Current version is the one rewritten by ceebo further edited by me. Bench: 5367704 --- src/evaluate.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 02806cc7..5621c508 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -221,6 +221,8 @@ namespace { 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. @@ -782,6 +784,18 @@ namespace { 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 @@ -813,6 +827,12 @@ Value Eval::evaluate(const Position& pos) { 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(pos.square(WHITE)); -- 2.39.2