-int generate_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
-
- assert(pos.is_ok());
- assert(!pos.is_check());
-
- int n;
- Color us = pos.side_to_move();
- Square ksq = pos.king_square(opposite_color(us));
-
- assert(pos.piece_on(ksq) == king_of_color(opposite_color(us)));
-
- dc = pos.discovered_check_candidates(us);
-
- // Pawn moves
- if (us == WHITE)
- n = generate_pawn_checks<WHITE>(pos, dc, ksq, mlist, 0);
- else
- n = generate_pawn_checks<BLACK>(pos, dc, ksq, mlist, 0);
-
- // Pieces moves
- Bitboard b = pos.knights(us);
- if (b)
- n = generate_piece_checks<KNIGHT>(pos, b, dc, ksq, mlist, n);
-
- b = pos.bishops(us);
- if (b)
- n = generate_piece_checks<BISHOP>(pos, b, dc, ksq, mlist, n);
-
- b = pos.rooks(us);
- if (b)
- n = generate_piece_checks<ROOK>(pos, b, dc, ksq, mlist, n);
-
- b = pos.queens(us);
- if (b)
- n = generate_piece_checks<QUEEN>(pos, b, dc, ksq, mlist, n);
-
- // Hopefully we always have a king ;-)
- n = generate_piece_checks<KING>(pos, b, dc, pos.king_square(us), mlist, n);
-
- // 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 = pos.side_to_move();
- Color them = opposite_color(us);
- Square ksq = pos.king_square(us);
- Square from, to;
- int n = 0;
-
- assert(pos.piece_on(ksq) == king_of_color(us));
-
- // Generate evasions for king
- Bitboard b1 = pos.piece_attacks<KING>(ksq) & ~pos.pieces_of_color(us);
- Bitboard b2 = pos.occupied_squares();
- clear_bit(&b2, ksq);
-
- while (b1)
- {
- Square 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 (!( (bishop_attacks_bb(to, b2) & pos.bishops_and_queens(them))
- || (rook_attacks_bb(to, b2) & pos.rooks_and_queens(them))
- || (pos.piece_attacks<KNIGHT>(to) & pos.knights(them))
- || (pos.pawn_attacks(us, to) & pos.pawns(them))
- || (pos.piece_attacks<KING>(to) & pos.kings(them))))
-
- mlist[n++].move = make_move(ksq, to);