X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.cpp;h=52786cdbe3b58b6166192802f35ab2f3eef674a8;hp=34d9b484712af1c53db7ffe98bd0236cc87f3531;hb=52f3e717fa93c8774f37c249b05aa857993ee8a2;hpb=0586b51f9c398008f264d78a2888c0d68d9561cb diff --git a/src/endgame.cpp b/src/endgame.cpp index 34d9b484..52786cdb 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -100,6 +100,7 @@ Endgames::Endgames() { add("KBBKN"); add("KNPK"); + add("KNPKB"); add("KRPKR"); add("KBPKB"); add("KBPKN"); @@ -904,6 +905,24 @@ ScaleFactor Endgame::operator()(const Position& pos) const { } +/// K, knight and a pawn vs K and bishop. If knight can block bishop from taking +/// pawn, it's a win. Otherwise, drawn. +template<> +ScaleFactor Endgame::operator()(const Position& pos) const { + + Square pawnSq = pos.piece_list(strongerSide, PAWN)[0]; + Square bishopSq = pos.piece_list(weakerSide, BISHOP)[0]; + Square weakerKingSq = pos.king_square(weakerSide); + + // King needs to get close to promoting pawn to prevent knight from blocking. + // Rules for this are very tricky, so just approximate. + if (forward_bb(strongerSide, pawnSq) & pos.attacks_from(bishopSq)) + return ScaleFactor(square_distance(weakerKingSq, pawnSq)); + + return SCALE_FACTOR_NONE; +} + + /// K and a pawn vs K and a pawn. This is done by removing the weakest side's /// pawn and probing the KP vs K bitbase: If the weakest side has a draw without /// the pawn, she probably has at least a draw with the pawn as well. The exception