From: Vizvezdenec Date: Sat, 14 Sep 2019 22:32:39 +0000 (+0200) Subject: Introduce midgame initiative X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=843a6c43053ceb9cc79d29bf7c0d3a5d236e057e Introduce midgame initiative This patch finally introduces something that was tried for years: midgame score dependance on complexity of position. More precisely, if the position is very simplified and the complexity measure calculated in the initiative() function is inferior to -50 by an amount d, then we add this value d to the midgame score. One example of play of this patch will be (again!) 4 vs 3 etc same flank endgames where sides have a lot of non-pawn material: 4 vs 3 draw mostly remains the same draw even if we add a lot of equal material to both sides. STC run was stopped after 200k games (and not converging): LLR: -1.75 (-2.94,2.94) [0.50,4.50] Total: 200319 W: 44197 L: 43310 D: 112812 http://tests.stockfishchess.org/tests/view/5d7cfdb10ebc5902d386572c passed LTC: LLR: 2.95 (-2.94,2.94) [0.00,3.50] Total: 41051 W: 6858 L: 6570 D: 27623 http://tests.stockfishchess.org/tests/view/5d7d14680ebc5902d3866196 This is the first and not really precise version, a lot of other stuff can be tried on top of it (separate complexity for middlegame, some more terms, even simple retuning of values). Bench: 4248476 --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index ad76fc8d..d92239c1 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -169,7 +169,7 @@ namespace { template Score passed() const; template Score space() const; ScaleFactor scale_factor(Value eg) const; - Score initiative(Value eg) const; + Score initiative(Score score) const; const Position& pos; Material::Entry* me; @@ -717,7 +717,10 @@ namespace { // known attacking/defending status of the players. template - Score Evaluation::initiative(Value eg) const { + Score Evaluation::initiative(Score score) const { + + Value mg = mg_value(score); + Value eg = eg_value(score); int outflanking = distance(pos.square(WHITE), pos.square(BLACK)) - distance(pos.square(WHITE), pos.square(BLACK)); @@ -738,15 +741,16 @@ namespace { - 36 * almostUnwinnable -103 ; - // Now apply the bonus: note that we find the attacking side by extracting - // the sign of the endgame value, and that we carefully cap the bonus so - // that the endgame score will never change sign after the bonus. + // Now apply the bonus: note that we find the attacking side by extracting the + // sign of the midgame or endgame values, and that we carefully cap the bonus + // so that the midgame and endgame scores do not change sign after the bonus. + int u = ((mg > 0) - (mg < 0)) * std::max(std::min(complexity + 50, 0), -abs(mg)); int v = ((eg > 0) - (eg < 0)) * std::max(complexity, -abs(eg)); if (T) - Trace::add(INITIATIVE, make_score(0, v)); + Trace::add(INITIATIVE, make_score(u, v)); - return make_score(0, v); + return make_score(u, v); } @@ -822,7 +826,7 @@ namespace { + passed< WHITE>() - passed< BLACK>() + space< WHITE>() - space< BLACK>(); - score += initiative(eg_value(score)); + score += initiative(score); // Interpolate between a middlegame and a (scaled by 'sf') endgame score ScaleFactor sf = scale_factor(eg_value(score));