- int d = square_distance(defendingKSq, nSq);
- Value result = Value(10)
- + mate_table(defendingKSq)
- + krkn_king_knight_distance_penalty(d);
+/// KQ vs KP. In general, a win for the stronger side, however, there are a few
+/// important exceptions. Pawn on 7th rank, A,C,F or H file, with king next can
+/// be a draw, so we scale down to distance between kings only.
+template<>
+Value Endgame<KQKP>::operator()(const Position& pos) const {
+
+ assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
+ assert(pos.non_pawn_material(weakerSide ) == VALUE_ZERO);
+ assert(pos.count<PAWN>(strongerSide) == 0);
+ assert(pos.count<PAWN>(weakerSide ) == 1);
+
+ Square winnerKSq = pos.king_square(strongerSide);
+ Square loserKSq = pos.king_square(weakerSide);
+ Square pawnSq = pos.list<PAWN>(weakerSide)[0];
+
+ Value result = Value(PushClose[square_distance(winnerKSq, loserKSq)]);
+
+ if ( relative_rank(weakerSide, pawnSq) != RANK_7
+ || square_distance(loserKSq, pawnSq) != 1
+ || !((FileABB | FileCBB | FileFBB | FileHBB) & pawnSq))
+ result += QueenValueEg - PawnValueEg;