X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.cpp;h=4ee515ade71cab5c856f3f6c547d1fd959a8820f;hp=94967c25eac588043e0730eabc2c0da5a4a16745;hb=c0d3010438e9cec2d40dec9e92695b58514497bb;hpb=5f12069cbfc882fdf989d04618ad9c33e603c419 diff --git a/src/endgame.cpp b/src/endgame.cpp index 94967c25..4ee515ad 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -166,6 +166,7 @@ Value Endgame::operator()(const Position& pos) const { if ( pos.count(strongSide) || pos.count(strongSide) + ||(pos.count(strongSide) && pos.count(strongSide)) || pos.bishop_pair(strongSide)) result += VALUE_KNOWN_WIN; @@ -245,13 +246,13 @@ Value Endgame::operator()(const Position& pos) const { // If the stronger side's king is in front of the pawn, it's a win if (wksq < psq && file_of(wksq) == file_of(psq)) - result = RookValueEg - Value(square_distance(wksq, psq)); + result = RookValueEg - square_distance(wksq, psq); // If the weaker side's king is too far from the pawn and the rook, // it's a win. else if ( square_distance(bksq, psq) >= 3 + (pos.side_to_move() == weakSide) && square_distance(bksq, rsq) >= 3) - result = RookValueEg - Value(square_distance(wksq, psq)); + result = RookValueEg - square_distance(wksq, psq); // If the pawn is far advanced and supported by the defending king, // the position is drawish @@ -259,13 +260,12 @@ Value Endgame::operator()(const Position& pos) const { && square_distance(bksq, psq) == 1 && rank_of(wksq) >= RANK_4 && square_distance(wksq, psq) > 2 + (pos.side_to_move() == strongSide)) - result = Value(80 - square_distance(wksq, psq) * 8); + result = Value(80) - 8 * square_distance(wksq, psq); else - result = Value(200) - - Value(square_distance(wksq, psq + DELTA_S) * 8) - + Value(square_distance(bksq, psq + DELTA_S) * 8) - + Value(square_distance(psq, queeningSq) * 8); + result = Value(200) - 8 * ( square_distance(wksq, psq + DELTA_S) + - square_distance(bksq, psq + DELTA_S) + - square_distance(psq, queeningSq)); return strongSide == pos.side_to_move() ? result : -result; } @@ -364,52 +364,27 @@ ScaleFactor Endgame::operator()(const Position& pos) const { // be detected even when the weaker side has some pawns. Bitboard pawns = pos.pieces(strongSide, PAWN); - File pawnFile = file_of(pos.list(strongSide)[0]); + File pawnsFile = file_of(lsb(pawns)); // All pawns are on a single rook file ? - if ( (pawnFile == FILE_A || pawnFile == FILE_H) - && !(pawns & ~file_bb(pawnFile))) + if ( (pawnsFile == FILE_A || pawnsFile == FILE_H) + && !(pawns & ~file_bb(pawnsFile))) { Square bishopSq = pos.list(strongSide)[0]; - Square queeningSq = relative_square(strongSide, make_square(pawnFile, RANK_8)); + Square queeningSq = relative_square(strongSide, make_square(pawnsFile, RANK_8)); Square kingSq = pos.king_square(weakSide); + // If the bishop has the wrong color, and the defending king is on the file + // of the pawn(s) or the neighboring file, then it's potentially a draw. if ( opposite_colors(queeningSq, bishopSq) - && square_distance(queeningSq, kingSq) <= 1) - return SCALE_FACTOR_DRAW; - } - - // If all the pawns are on the same B or G file, then it's potentially a draw - if ( (pawnFile == FILE_B || pawnFile == FILE_G) - && !(pos.pieces(PAWN) & ~file_bb(pawnFile)) - && pos.non_pawn_material(weakSide) == 0 - && pos.count(weakSide) >= 1) - { - // Get weakSide pawn that is closest to the home rank - Square weakPawnSq = backmost_sq(weakSide, pos.pieces(weakSide, PAWN)); - - Square strongKingSq = pos.king_square(strongSide); - Square weakKingSq = pos.king_square(weakSide); - Square bishopSq = pos.list(strongSide)[0]; - - // There's potential for a draw if our pawn is blocked on the 7th rank, - // the bishop cannot attack it or they only have one pawn left - if ( relative_rank(strongSide, weakPawnSq) == RANK_7 - && (pos.pieces(strongSide, PAWN) & (weakPawnSq + pawn_push(weakSide))) - && (opposite_colors(bishopSq, weakPawnSq) || pos.count(strongSide) == 1)) + && file_distance(kingSq, lsb(pawns)) <= 1) { - int strongKingDist = square_distance(weakPawnSq, strongKingSq); - int weakKingDist = square_distance(weakPawnSq, weakKingSq); - - // It's a draw if the weak king is on its back two ranks, within 2 - // squares of the blocking pawn and the strong king is not - // closer. (I think this rule only fails in practically - // unreachable positions such as 5k1K/6p1/6P1/8/8/3B4/8/8 w - // and positions where qsearch will immediately correct the - // problem such as 8/4k1p1/6P1/1K6/3B4/8/8/8 w) - if ( relative_rank(strongSide, weakKingSq) >= RANK_7 - && weakKingDist <= 2 - && weakKingDist <= strongKingDist) + // If the defending king has distance <= 1 to the promotion square or + // is placed somewhere in front of the frontmost pawn, it's a draw. + Rank rank = relative_rank(strongSide, (frontmost_sq(strongSide, pawns))); + + if ( square_distance(kingSq, queeningSq) <= 1 + || relative_rank(strongSide, kingSq) >= rank) return SCALE_FACTOR_DRAW; } }