X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.cpp;h=cc98de90d4f40f71f900c04c1bbc71bd2322ec11;hp=cff5e6994054699fb40aec7c33404a7fb40a7073;hb=8c2fd2170a0d6dececbe87b0c0353ce718dcd9fd;hpb=cd782c11ec8e765e3a323e422cea19d7d053a07c diff --git a/src/endgame.cpp b/src/endgame.cpp index cff5e699..cc98de90 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -89,7 +89,10 @@ namespace { Endgames::Endgames() { + add("KK"); add("KPK"); + add("KBK"); + add("KNK"); add("KNNK"); add("KBNK"); add("KRKP"); @@ -131,13 +134,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); @@ -149,9 +150,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; } @@ -410,17 +410,13 @@ Value Endgame::operator()(const Position& pos) const { } -/// K and two minors vs K and one or two minors or K and two knights against -/// king alone are always draw. -template<> -Value Endgame::operator()(const Position&) const { - return VALUE_DRAW; -} +/// 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; } -template<> -Value Endgame::operator()(const Position&) const { - return VALUE_DRAW; -} /// K, bishop and one or more pawns vs K. It checks for draws with rook pawns and /// a bishop of the wrong color. If such a draw is detected, SCALE_FACTOR_DRAW @@ -704,7 +700,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { // Does the defending king block the pawns? if ( square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1 || ( file_of(ksq) == FILE_A - && !(in_front_bb(strongerSide, ksq) & pawns))) + && !(in_front_bb(strongerSide, rank_of(ksq)) & pawns))) return SCALE_FACTOR_DRAW; } // Are all pawns on the 'h' file? @@ -713,7 +709,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { // Does the defending king block the pawns? if ( square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1 || ( file_of(ksq) == FILE_H - && !(in_front_bb(strongerSide, ksq) & pawns))) + && !(in_front_bb(strongerSide, rank_of(ksq)) & pawns))) return SCALE_FACTOR_DRAW; } return SCALE_FACTOR_NONE;