- n = generate_pawn_blocking_evasions<BLACK>(pos, not_pinned, blockSquares, mlist, n);
-
- // Pieces moves
- b1 = pos.knights(us) & not_pinned;
- if (b1)
- n = generate_piece_blocking_evasions<KNIGHT>(pos, b1, blockSquares, mlist, n);
-
- b1 = pos.bishops(us) & not_pinned;
- if (b1)
- n = generate_piece_blocking_evasions<BISHOP>(pos, b1, blockSquares, mlist, n);
-
- b1 = pos.rooks(us) & not_pinned;
- if (b1)
- n = generate_piece_blocking_evasions<ROOK>(pos, b1, blockSquares, mlist, n);
-
- b1 = pos.queens(us) & not_pinned;
- if (b1)
- n = generate_piece_blocking_evasions<QUEEN>(pos, b1, blockSquares, mlist, n);
- }
-
- // Finally, the ugly 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.pawns(them)))
- {
- to = pos.ep_square();
- b1 = pos.pawn_attacks(them, to) & pos.pawns(us);
-
- assert(b1 != EmptyBoardBB);
-
- b1 &= not_pinned;
- while (b1)
- {
- from = pop_1st_bit(&b1);
-
- // Before generating the move, we have to make sure it is legal.
- // This is somewhat tricky, because the two disappearing pawns may
- // cause new "discovered checks". We test this by removing the
- // two relevant bits from the occupied squares bitboard, and using
- // the low-level bitboard functions for bishop and rook attacks.
- b2 = pos.occupied_squares();
- clear_bit(&b2, from);
- clear_bit(&b2, checksq);
- if (!( (bishop_attacks_bb(ksq, b2) & pos.bishops_and_queens(them))
- ||(rook_attacks_bb(ksq, b2) & pos.rooks_and_queens(them))))
-
- mlist[n++].move = make_ep_move(from, to);
- }
- }
- }
- return n;
+ sliderAttacks |= BishopPseudoAttacks[checksq] | pos.attacks_from<ROOK>(checksq);
+ default:
+ break;
+ }
+ } while (b);
+
+ // Generate evasions for king, capture and non capture moves
+ b = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
+ from = ksq;
+ SERIALIZE_MOVES(b);
+
+ // Generate evasions for other pieces only if not double check
+ if (checkersCnt > 1)
+ return mlist;
+
+ // Find squares where a blocking evasion or a capture of the
+ // checker piece is possible.
+ target = squares_between(checksq, ksq) | checkers;
+
+ mlist = generate_piece_moves<PAWN, MV_EVASION>(pos, mlist, us, target);
+ mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
+ mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
+ mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
+ return generate_piece_moves<QUEEN>(pos, mlist, us, target);