+/// 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.piece_count(strongerSide, PAWN) == 0);
+ assert(pos.non_pawn_material(weakerSide) == 0);
+ assert(pos.piece_count(weakerSide, PAWN) == 1);
+
+ Square winnerKSq = pos.king_square(strongerSide);
+ Square loserKSq = pos.king_square(weakerSide);
+ Square pawnSq = pos.piece_list(weakerSide, PAWN)[0];
+
+ Value result = QueenValueEg
+ - PawnValueEg
+ + DistanceBonus[square_distance(winnerKSq, loserKSq)];
+
+ if ( square_distance(loserKSq, pawnSq) == 1
+ && relative_rank(weakerSide, pawnSq) == RANK_7)
+ {
+ File f = file_of(pawnSq);
+
+ if (f == FILE_A || f == FILE_C || f == FILE_F || f == FILE_H)
+ result = Value(DistanceBonus[square_distance(winnerKSq, loserKSq)]);
+ }