mirror of
https://github.com/sockspls/badfish
synced 2025-07-12 03:59:15 +00:00
Simplify KBNK endgame implementation
We do not need to change the winnerKSq variable, so we can simplify a little bit the logic of the code by changing only the loserKSq variable when it is necessary. Also consolidate and clarify comments. See the pull request thread for a proof that the code is correct: https://github.com/official-stockfish/Stockfish/pull/1854 No functional change
This commit is contained in:
parent
0f2df4e4af
commit
b54bcfddaa
1 changed files with 4 additions and 10 deletions
|
@ -120,7 +120,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
|
|
||||||
/// Mate with KBN vs K. This is similar to KX vs K, but we have to drive the
|
/// Mate with KBN vs K. This is similar to KX vs K, but we have to drive the
|
||||||
/// defending king towards a corner square of the right color.
|
/// defending king towards a corner square that our bishop attacks.
|
||||||
template<>
|
template<>
|
||||||
Value Endgame<KBNK>::operator()(const Position& pos) const {
|
Value Endgame<KBNK>::operator()(const Position& pos) const {
|
||||||
|
|
||||||
|
@ -131,18 +131,12 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
|
||||||
Square loserKSq = pos.square<KING>(weakSide);
|
Square loserKSq = pos.square<KING>(weakSide);
|
||||||
Square bishopSq = pos.square<BISHOP>(strongSide);
|
Square bishopSq = pos.square<BISHOP>(strongSide);
|
||||||
|
|
||||||
// kbnk_mate_table() tries to drive toward corners A1 or H8. If we have a
|
// If our Bishop does not attack A1/H8, we flip the enemy king square
|
||||||
// bishop that cannot reach the above squares, we flip the kings in order
|
// to drive to opposite corners (A8/H1).
|
||||||
// to drive the enemy toward corners A8 or H1.
|
|
||||||
if (opposite_colors(bishopSq, SQ_A1))
|
|
||||||
{
|
|
||||||
winnerKSq = ~winnerKSq;
|
|
||||||
loserKSq = ~loserKSq;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value result = VALUE_KNOWN_WIN
|
Value result = VALUE_KNOWN_WIN
|
||||||
+ PushClose[distance(winnerKSq, loserKSq)]
|
+ PushClose[distance(winnerKSq, loserKSq)]
|
||||||
+ PushToCorners[loserKSq];
|
+ PushToCorners[opposite_colors(bishopSq, SQ_A1) ? ~loserKSq : loserKSq];
|
||||||
|
|
||||||
return strongSide == pos.side_to_move() ? result : -result;
|
return strongSide == pos.side_to_move() ? result : -result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue