- to = pop_1st_bit(&b3);
- mlist[n++].move = make_move(to - DELTA_S - DELTA_S, to);
- }
- }
-
- // Knight moves
- b1 = pos.knights(us);
- if (b1)
- n += generate_piece_checks(KNIGHT, pos, b1, dc, ksq, mlist);
-
- // Bishop moves
- b1 = pos.bishops(us);
- if (b1)
- n += generate_piece_checks(BISHOP, pos, b1, dc, ksq, mlist);
-
- // Rook moves
- b1 = pos.rooks(us);
- if (b1)
- n += generate_piece_checks(ROOK, pos, b1, dc, ksq, mlist);
-
- // Queen moves
- b1 = pos.queens(us);
- if (b1)
- n += generate_piece_checks(QUEEN, pos, b1, dc, ksq, mlist);
-
- // King moves
- from = pos.king_square(us);
- if (bit_is_set(dc, from))
- {
- b1 = pos.king_attacks(from) & empty & ~QueenPseudoAttacks[ksq];
- while (b1)
- {
- to = pop_1st_bit(&b1);
- mlist[n++].move = make_move(from, to);
- }
- }
-
- // TODO: Castling moves!
-
- return n;
-}
-
-
-/// generate_evasions() generates all check evasions when the side to move is
-/// in check. Unlike the other move generation functions, this one generates
-/// only legal moves. It returns the number of generated moves. This
-/// function is very ugly, and needs cleaning up some time later. FIXME
-
-int generate_evasions(const Position &pos, MoveStack *mlist) {
-
- assert(pos.is_ok());
- assert(pos.is_check());
-
- Color us, them;
- Bitboard checkers = pos.checkers();
- Bitboard pinned, b1, b2;
- Square ksq, from, to;
- int n = 0;
-
- us = pos.side_to_move();
- them = opposite_color(us);
-
- ksq = pos.king_square(us);
- assert(pos.piece_on(ksq) == king_of_color(us));
-
- // Generate evasions for king:
- b1 = pos.king_attacks(ksq) & ~pos.pieces_of_color(us);
- b2 = pos.occupied_squares();
- clear_bit(&b2, ksq);
- while(b1) {
- to = pop_1st_bit(&b1);
-
- // Make sure to is not attacked by the other side. This is a bit ugly,
- // because we can't use Position::square_is_attacked. Instead we use
- // the low-level bishop_attacks_bb and rook_attacks_bb with the bitboard
- // b2 (the occupied squares with the king removed) in order to test whether
- // the king will remain in check on the destination square.
- if(((pos.pawn_attacks(us, to) & pos.pawns(them)) == EmptyBoardBB) &&
- ((pos.knight_attacks(to) & pos.knights(them)) == EmptyBoardBB) &&
- ((pos.king_attacks(to) & pos.kings(them)) == EmptyBoardBB) &&
- ((bishop_attacks_bb(to, b2) & pos.bishops_and_queens(them))
- == EmptyBoardBB) &&
- ((rook_attacks_bb(to, b2) & pos.rooks_and_queens(them)) == EmptyBoardBB))
- mlist[n++].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))) {
- Square checksq = first_1(checkers);
- assert(pos.color_of_piece_on(checksq) == them);
-
- // Find pinned pieces:
- pinned = pos.pinned_pieces(us);
-
- // Generate captures of the checking piece:
-
- // Pawn captures:
- b1 = pos.pawn_attacks(them, checksq) & pos.pawns(us) & ~pinned;
- while(b1) {
- from = pop_1st_bit(&b1);
- if(relative_rank(us, checksq) == RANK_8) {
- mlist[n++].move = make_promotion_move(from, checksq, QUEEN);
- mlist[n++].move = make_promotion_move(from, checksq, ROOK);
- mlist[n++].move = make_promotion_move(from, checksq, BISHOP);
- mlist[n++].move = make_promotion_move(from, checksq, KNIGHT);
- }
- else
- mlist[n++].move = make_move(from, checksq);
- }