Skip to content

Commit

Permalink
Simplify KBPKB endgame with opposite bishops
Browse files Browse the repository at this point in the history
When we reach a position with only two opposite colored bishops and
one pawn on the board, current master would give it a scale factor
of 9/64=0.14 in about one position out of 7200, and a scale factor
of 0.0 in the 7199 others. The patch gives a scale factor of 0.0 in
100% of the cases.

STC:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 55845 W: 11467 L: 11410 D: 32968
http://tests.stockfishchess.org/tests/view/5abc585f0ebc5902926cf15e

LTC:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 11915 W: 1852 L: 1719 D: 8344
http://tests.stockfishchess.org/tests/view/5abc7f750ebc5902926cf18c

We also have exhaustive coverage analysis of this patch effect by
Alain Savard, comparing the perfect evaluation given by the Syzygy
tablebase with the heuristic play after this patch for the set of
all legal positions of the KBPKP endgame with opposite bishops, in
the comments thread for this pull request:
#1520

Alain's conclusion:
> According to this definition and the data, I consider this PR is
> identical to master to "solve for draw" and slightly better than
> master to solve earlier for "wins".

Note: this patch is a side effect of an ongoing effort to improve
the evaluation of positions involving a pair of opposite bishops.
See the GitHub diff of this LTC test which almost passed at sprt[0..5]
for a discussion:
http://tests.stockfishchess.org/tests/view/5ab9030b0ebc5902932cbf93

No functional change (at small bench depths)
  • Loading branch information
snicolet committed Apr 1, 2018
1 parent f268123 commit d9cac9a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
23 changes: 1 addition & 22 deletions src/endgame.cpp
Expand Up @@ -631,29 +631,8 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {

// Case 2: Opposite colored bishops
if (opposite_colors(strongBishopSq, weakBishopSq))
{
// We assume that the position is drawn in the following three situations:
//
// a. The pawn is on rank 5 or further back.
// b. The defending king is somewhere in the pawn's path.
// c. The defending bishop attacks some square along the pawn's path,
// and is at least three squares away from the pawn.
//
// These rules are probably not perfect, but in practice they work
// reasonably well.

if (relative_rank(strongSide, pawnSq) <= RANK_5)
return SCALE_FACTOR_DRAW;

Bitboard path = forward_file_bb(strongSide, pawnSq);

if (path & pos.pieces(weakSide, KING))
return SCALE_FACTOR_DRAW;
return SCALE_FACTOR_DRAW;

if ( (pos.attacks_from<BISHOP>(weakBishopSq) & path)
&& distance(weakBishopSq, pawnSq) >= 3)
return SCALE_FACTOR_DRAW;
}
return SCALE_FACTOR_NONE;
}

Expand Down
5 changes: 2 additions & 3 deletions src/evaluate.cpp
Expand Up @@ -800,11 +800,10 @@ namespace {
{
if (pos.opposite_bishops())
{
// Endgame with opposite-colored bishops and no other pieces (ignoring pawns)
// is almost a draw, in case of KBP vs KB, it is even more a draw.
// Endgame with opposite-colored bishops and no other pieces is almost a draw
if ( pos.non_pawn_material(WHITE) == BishopValueMg
&& pos.non_pawn_material(BLACK) == BishopValueMg)
sf = more_than_one(pos.pieces(PAWN)) ? 31 : 9;
sf = 31;

// Endgame with opposite-colored bishops, but also other pieces. Still
// a bit drawish, but not as drawish as with only the two bishops.
Expand Down

0 comments on commit d9cac9a

Please sign in to comment.