Skip to content

Commit

Permalink
Introduce midgame initiative
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Vizvezdenec authored and snicolet committed Sep 14, 2019
1 parent e5cfa14 commit 843a6c4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/evaluate.cpp
Expand Up @@ -169,7 +169,7 @@ namespace {
template<Color Us> Score passed() const;
template<Color Us> 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;
Expand Down Expand Up @@ -717,7 +717,10 @@ namespace {
// known attacking/defending status of the players.

template<Tracing T>
Score Evaluation<T>::initiative(Value eg) const {
Score Evaluation<T>::initiative(Score score) const {

Value mg = mg_value(score);
Value eg = eg_value(score);

int outflanking = distance<File>(pos.square<KING>(WHITE), pos.square<KING>(BLACK))
- distance<Rank>(pos.square<KING>(WHITE), pos.square<KING>(BLACK));
Expand All @@ -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);
}


Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 843a6c4

Please sign in to comment.