- b = checkers & pos.pieces(ROOK, QUEEN);
- while (b)
- {
- from = pop_1st_bit(&b);
- checkersAttacks |= rook_attacks_bb(from, b_noKing);
- }
-
- // Generate evasions for king
- Bitboard b1 = pos.piece_attacks<KING>(ksq) & ~pos.pieces_of_color(us) & ~checkersAttacks;
- while (b1)
- {
- to = pop_1st_bit(&b1);
- // Note that we can use square_is_attacked() only because we
- // have already removed slider checkers.
- if (!pos.square_is_attacked(to, them))
- (*mlist++).move = make_move(ksq, to);
- }
-
- // Generate evasions for other pieces only if not double check. We use a
- // simple bit twiddling hack here rather than calling count_1s in order to
- // save some time (we know that pos.checkers() has at most two nonzero bits).
- if (!(checkers & (checkers - 1))) // Only one bit set?
- {
- Square checksq = first_1(checkers);
-
- assert(pos.color_of_piece_on(checksq) == them);
-
- // Generate captures of the checking piece
-
- // Pawn captures
- b1 = pos.pawn_attacks(them, checksq) & pos.pieces(PAWN, us) & ~pinned;
- while (b1)
- {
- from = pop_1st_bit(&b1);
- if (relative_rank(us, checksq) == RANK_8)
- {
- (*mlist++).move = make_promotion_move(from, checksq, QUEEN);
- (*mlist++).move = make_promotion_move(from, checksq, ROOK);
- (*mlist++).move = make_promotion_move(from, checksq, BISHOP);
- (*mlist++).move = make_promotion_move(from, checksq, KNIGHT);
- } else
- (*mlist++).move = make_move(from, checksq);
- }
-
- // Pieces captures
- b1 = ( (pos.piece_attacks<KNIGHT>(checksq) & pos.pieces(KNIGHT, us))
- | (pos.piece_attacks<BISHOP>(checksq) & pos.pieces(BISHOP, QUEEN, us))
- | (pos.piece_attacks<ROOK>(checksq) & pos.pieces(ROOK, QUEEN, us)) ) & ~pinned;
-
- while (b1)
- {
- from = pop_1st_bit(&b1);
- (*mlist++).move = make_move(from, checksq);
- }
-
- // Blocking check evasions are possible only if the checking piece is
- // a slider.
- if (checkers & (pos.pieces(BISHOP) | pos.pieces(ROOK) | pos.pieces(QUEEN)))
- {
- Bitboard blockSquares = squares_between(checksq, ksq);
-
- assert((pos.occupied_squares() & blockSquares) == EmptyBoardBB);
-
- if (blockSquares != EmptyBoardBB)
- {
- mlist = generate_piece_moves<PAWN>(pos, mlist, us, blockSquares, pinned);
- mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, blockSquares, pinned);
- mlist = generate_piece_moves<BISHOP>(pos, mlist, us, blockSquares, pinned);
- mlist = generate_piece_moves<ROOK>(pos, mlist, us, blockSquares, pinned);
- mlist = generate_piece_moves<QUEEN>(pos, mlist, us, blockSquares, pinned);
- }
- }
-
- // Finally, the special case of en passant captures. An en passant
- // capture can only be a check evasion if the check is not a discovered
- // check. If pos.ep_square() is set, the last move made must have been
- // a double pawn push. If, furthermore, the checking piece is a pawn,
- // an en passant check evasion may be possible.
- if (pos.ep_square() != SQ_NONE && (checkers & pos.pieces(PAWN, them)))
- {
- to = pos.ep_square();
- b1 = pos.pawn_attacks(them, to) & pos.pieces(PAWN, us);
-
- // The checking pawn cannot be a discovered (bishop) check candidate
- // otherwise we were in check also before last double push move.
- assert(!bit_is_set(pos.discovered_check_candidates(them), checksq));
- assert(count_1s(b1) == 1 || count_1s(b1) == 2);
-
- b1 &= ~pinned;
- while (b1)
- {
- from = pop_1st_bit(&b1);
- // Move is always legal because checking pawn is not a discovered
- // check candidate and our capturing pawn has been already tested
- // against pinned pieces.
- (*mlist++).move = make_ep_move(from, to);
- }
- }
- }
- return mlist;
+ // Direct non-capture checks
+ mlist = generate_direct_checks<PAWN>(pos, mlist, us, dc, ksq);
+ mlist = generate_direct_checks<KNIGHT>(pos, mlist, us, dc, ksq);
+ mlist = generate_direct_checks<BISHOP>(pos, mlist, us, dc, ksq);
+ mlist = generate_direct_checks<ROOK>(pos, mlist, us, dc, ksq);
+ return generate_direct_checks<QUEEN>(pos, mlist, us, dc, ksq);