X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.cpp;h=65b858613dd8f74ae6ad73674187473e059afe25;hp=e896e778e96aa8347b3f00405c26eddf580f97f5;hb=aecdbfc4a000c72fcc2642f54ce83967913a16ba;hpb=6373e88b5b13d23646ff50944b49b74a96bb5915 diff --git a/src/endgame.cpp b/src/endgame.cpp index e896e778..65b85861 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -89,10 +89,7 @@ namespace { Endgames::Endgames() { - add("KK"); add("KPK"); - add("KBK"); - add("KNK"); add("KNNK"); add("KBNK"); add("KRKP"); @@ -134,13 +131,11 @@ Value Endgame::operator()(const Position& pos) const { assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO); assert(!pos.count(weakerSide)); + assert(!pos.checkers()); // Eval is never called when in check // Stalemate detection with lone king - if ( pos.side_to_move() == weakerSide - && !pos.checkers() - && !MoveList(pos).size()) { - return VALUE_DRAW; - } + if (pos.side_to_move() == weakerSide && !MoveList(pos).size()) + return VALUE_DRAW; Square winnerKSq = pos.king_square(strongerSide); Square loserKSq = pos.king_square(weakerSide); @@ -152,9 +147,8 @@ Value Endgame::operator()(const Position& pos) const { if ( pos.count(strongerSide) || pos.count(strongerSide) - || pos.bishop_pair(strongerSide)) { - result += VALUE_KNOWN_WIN; - } + || pos.bishop_pair(strongerSide)) + result += VALUE_KNOWN_WIN; return strongerSide == pos.side_to_move() ? result : -result; } @@ -414,9 +408,6 @@ Value Endgame::operator()(const Position& pos) const { /// Some cases of trivial draws -template<> Value Endgame::operator()(const Position&) const { return VALUE_DRAW; } -template<> Value Endgame::operator()(const Position&) const { return VALUE_DRAW; } -template<> Value Endgame::operator()(const Position&) const { return VALUE_DRAW; } template<> Value Endgame::operator()(const Position&) const { return VALUE_DRAW; } template<> Value Endgame::operator()(const Position&) const { return VALUE_DRAW; } @@ -452,18 +443,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { // The bishop has the wrong color, and the defending king is on the // file of the pawn(s) or the adjacent file. Find the rank of the // frontmost pawn. - Rank rank; - if (strongerSide == WHITE) - { - for (rank = RANK_7; !(rank_bb(rank) & pawns); rank--) {} - assert(rank >= RANK_2 && rank <= RANK_7); - } - else - { - for (rank = RANK_2; !(rank_bb(rank) & pawns); rank++) {} - rank = Rank(rank ^ 7); // HACK to get the relative rank - assert(rank >= RANK_2 && rank <= RANK_7); - } + Rank rank = relative_rank(strongerSide, lsb(weakerSide, pawns)); // If the defending king has distance 1 to the promotion square or // is placed somewhere in front of the pawn, it's a draw. if ( square_distance(kingSq, queeningSq) <= 1 @@ -478,9 +458,8 @@ ScaleFactor Endgame::operator()(const Position& pos) const { && pos.non_pawn_material(weakerSide) == 0 && pos.count(weakerSide) >= 1) { - // Get weaker pawn closest to opponent's queening square - Bitboard wkPawns = pos.pieces(weakerSide, PAWN); - Square weakerPawnSq = strongerSide == WHITE ? msb(wkPawns) : lsb(wkPawns); + // Get weakerSide pawn that is closest to home rank + Square weakerPawnSq = lsb(weakerSide, pos.pieces(weakerSide, PAWN)); Square strongerKingSq = pos.king_square(strongerSide); Square weakerKingSq = pos.king_square(weakerSide);