Scale down endgames with pawns on one or two adjacent files

This commit is contained in:
shane31
2014-06-25 16:01:00 -04:00
committed by Gary Linscott
parent ab580106fd
commit 6c9f4cf36f
3 changed files with 32 additions and 23 deletions

View File

@@ -197,6 +197,7 @@ namespace {
// scores, indexed by a calculated integer number.
Score KingDanger[128];
const int ScalePawnSpan[2] = { 38, 56 };
// apply_weight() weighs score 'v' by weight 'w' trying to prevent overflow
Score apply_weight(Score v, const Weight& w) {
@@ -726,15 +727,15 @@ namespace {
}
// Scale winning side if position is more drawish than it appears
ScaleFactor sf = eg_value(score) > VALUE_DRAW ? ei.mi->scale_factor(pos, WHITE)
: ei.mi->scale_factor(pos, BLACK);
Color strongSide = eg_value(score) > VALUE_DRAW ? WHITE : BLACK;
ScaleFactor sf = ei.mi->scale_factor(pos, strongSide);
// If we don't already have an unusual scale factor, check for opposite
// colored bishop endgames, and use a lower scale for those.
// If we don't already have an unusual scale factor, check for certain
// types of endgames, and use a lower scale for those.
if ( ei.mi->game_phase() < PHASE_MIDGAME
&& pos.opposite_bishops()
&& (sf == SCALE_FACTOR_NORMAL || sf == SCALE_FACTOR_ONEPAWN))
{
if (pos.opposite_bishops()) {
// Ignoring any pawns, do both sides only have a single bishop and no
// other pieces?
if ( pos.non_pawn_material(WHITE) == BishopValueMg
@@ -749,6 +750,10 @@ namespace {
// Endgame with opposite-colored bishops, but also other pieces. Still
// a bit drawish, but not as drawish as with only the two bishops.
sf = ScaleFactor(50 * sf / SCALE_FACTOR_NORMAL);
} else if ( ei.pi->pawn_span(strongSide) <= 1 &&
!pos.pawn_passed(~strongSide, pos.king_square(~strongSide))) {
sf = ScaleFactor(ScalePawnSpan[ei.pi->pawn_span(strongSide)]);
}
}
// Interpolate between a middlegame and a (scaled by 'sf') endgame score

View File

@@ -204,13 +204,12 @@ namespace {
}
}
b = e->semiopenFiles[Us] ^ 0xFF;
e->pawnSpan[Us] = b ? int(msb(b) - lsb(b)) : 0;
// In endgame it's better to have pawns on both wings. So give a bonus according
// to file distance between left and right outermost pawns.
if (pos.count<PAWN>(Us) > 1)
{
b = e->semiopenFiles[Us] ^ 0xFF;
value += PawnsFileSpan * int(msb(b) - lsb(b));
}
value += PawnsFileSpan * e->pawnSpan[Us];
return value;
}

View File

@@ -45,6 +45,10 @@ struct Entry {
return semiopenFiles[c] & (leftSide ? (1 << f) - 1 : ~((1 << (f + 1)) - 1));
}
int pawn_span(Color c) const {
return pawnSpan[c];
}
int pawns_on_same_color_squares(Color c, Square s) const {
return pawnsOnSquares[c][!!(DarkSquares & s)];
}
@@ -71,6 +75,7 @@ struct Entry {
int minKPdistance[COLOR_NB];
int castlingRights[COLOR_NB];
int semiopenFiles[COLOR_NB];
int pawnSpan[COLOR_NB];
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
};