-ScaleFactor Endgame<KQKRPs>::apply(const Position& pos) const {
-
- assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
- assert(pos.piece_count(strongerSide, QUEEN) == 1);
- assert(pos.piece_count(strongerSide, PAWN) == 0);
- assert(pos.piece_count(weakerSide, ROOK) == 1);
- assert(pos.piece_count(weakerSide, PAWN) >= 1);
-
- Square kingSq = pos.king_square(weakerSide);
- if ( relative_rank(weakerSide, kingSq) <= RANK_2
- && relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
- && (pos.pieces(ROOK, weakerSide) & rank_bb(relative_rank(weakerSide, RANK_3)))
- && (pos.pieces(PAWN, weakerSide) & rank_bb(relative_rank(weakerSide, RANK_2)))
- && (pos.attacks_from<KING>(kingSq) & pos.pieces(PAWN, weakerSide)))
- {
- Square rsq = pos.piece_list(weakerSide, ROOK)[0];
- if (pos.attacks_from<PAWN>(rsq, strongerSide) & pos.pieces(PAWN, weakerSide))
- return SCALE_FACTOR_ZERO;
- }
+ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const {
+
+ assert(verify_material(pos, strongSide, QueenValueMg, 0));
+ assert(pos.count<ROOK>(weakSide) == 1);
+ assert(pos.count<PAWN>(weakSide) >= 1);
+
+ Square kingSq = pos.king_square(weakSide);
+ Square rsq = pos.list<ROOK>(weakSide)[0];
+
+ if ( relative_rank(weakSide, kingSq) <= RANK_2
+ && relative_rank(weakSide, pos.king_square(strongSide)) >= RANK_4
+ && relative_rank(weakSide, rsq) == RANK_3
+ && ( pos.pieces(weakSide, PAWN)
+ & pos.attacks_from<KING>(kingSq)
+ & pos.attacks_from<PAWN>(rsq, strongSide)))
+ return SCALE_FACTOR_DRAW;
+