Skip to content

Commit

Permalink
Work on KRPvKBP. Bench: 4823093
Browse files Browse the repository at this point in the history
  • Loading branch information
vondele committed Mar 8, 2020
1 parent 37e3863 commit 44e4192
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/endgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ namespace Endgames {
add<KNPKB>("KNPKB");
add<KRPKR>("KRPKR");
add<KRPKB>("KRPKB");
add<KRPKBP>("KRPKBP");
add<KBPKB>("KBPKB");
add<KBPKN>("KBPKN");
add<KBPPKB>("KBPPKB");
Expand Down Expand Up @@ -524,7 +525,7 @@ ScaleFactor Endgame<KRPKB>::operator()(const Position& pos) const {
assert(verify_material(pos, weakSide, BishopValueMg, 0));

// Test for a rook pawn
if (pos.pieces(PAWN) & (FileABB | FileHBB))
if (pos.pieces(strongSide, PAWN) & (FileABB | FileHBB))
{
Square ksq = pos.square<KING>(weakSide);
Square bsq = pos.square<BISHOP>(weakSide);
Expand Down Expand Up @@ -561,6 +562,37 @@ ScaleFactor Endgame<KRPKB>::operator()(const Position& pos) const {
return SCALE_FACTOR_NONE;
}

template<>
ScaleFactor Endgame<KRPKBP>::operator()(const Position& pos) const {

Square sksq = pos.square<KING>(strongSide);
Square spsq = pos.square<PAWN>(strongSide);
Square sqsq = relative_square(strongSide, make_square(file_of(spsq), RANK_8));
Square wksq = pos.square<KING>(weakSide);
Square wpsq = pos.square<PAWN>(weakSide);
Square bsq = pos.square<BISHOP>(weakSide);

if (distance(wksq, wpsq) - distance(sksq, wpsq) <= -1)
if (distance(spsq, sqsq) <= 5)
if (opposite_colors(bsq, wpsq))
return ScaleFactor(16);
else
if (distance(sksq, wpsq) - distance(wksq, spsq) <= 0)
return ScaleFactor(44);
else
return ScaleFactor(23);
else
return ScaleFactor(47);
else
if (pos.attacks_from<PAWN>(wpsq, weakSide) & bsq)
return ScaleFactor(21);
else
if (distance(sksq, wpsq) - distance(wksq, spsq) <= -2)
return ScaleFactor(47);
else
return ScaleFactor(37);
}

/// KRPP vs KRP. There is just a single rule: if the stronger side has no passed
/// pawns and the defending king is actively placed, the position is drawish.
template<>
Expand Down
3 changes: 2 additions & 1 deletion src/endgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ enum EndgameCode {
KBPKN, // KBP vs KN
KNPK, // KNP vs K
KNPKB, // KNP vs KB
KPKP // KP vs KP
KPKP, // KP vs KP
KRPKBP // KRP vs KBP
};


Expand Down

8 comments on commit 44e4192

@joergoster
Copy link

@joergoster joergoster commented on 44e4192 Mar 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are simplification bounds intentional, even with endgame book?

@vondele
Copy link
Owner Author

@vondele vondele commented on 44e4192 Mar 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm working on it, I just want to make sure it doesn't regress. I guess it is the common problem, one single endgame doesn't contribute much to overall Elo playing games, but it can be very significant if the endgame itself is reached. For example, on a book with just KRPvKBP (50/50 win draw positions), this version of the patch (at TC: 1+0.01) has a nice result:

Score of patch vs master: 3270 - 2747 - 3983  [0.526] 10000
Elo difference: 18.2 +/- 5.3, LOS: 100.0 %, DrawRatio: 39.8 %

@joergoster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Nice result, btw.

@protonspring
Copy link

@protonspring protonspring commented on 44e4192 Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to test the eg book at a little longer tc. i have seen big differences between 1+0.01 and 5+0.05. Looks good though!

@adentong
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should test endgame improvements as a nonregression on the whole book and elo gainer on the eg book.

@protonspring
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we add this to the repository? I think it should be added if it doesn't regress in normal games, but demonstrates clear improvement in any single end game.

@vondele
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we did not add this... I think we need something a strategy for this, I propose we discuss that in the endgame issue official-stockfish#2288

Note that just playing the particular endgame better doesn't imply it is actually leading to playing better games. For example, you might be able to add a constant to an endgame eval, and it should influence how you play the endgame, yet might be unbalanced (e.g. add incorrectly the constant VALUE_KNOWN_WIN to KNNvKP doesn't change search as soon as you're in the endgame, but would wrongly attract play to this endgame). So at the very least, even if one shows to be better in the endgame itself, it needs some testing in games.

@protonspring
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't regress in normal games and is demonstrably better in a specific endgame, overall it's better and IMHO should be added.

Please sign in to comment.