- Bitboard b = pos.knights(us);
- if (b)
- mlist = generate_piece_checks<KNIGHT>(pos, b, dc, ksq, mlist);
-
- b = pos.bishops(us);
- if (b)
- mlist = generate_piece_checks<BISHOP>(pos, b, dc, ksq, mlist);
-
- b = pos.rooks(us);
- if (b)
- mlist = generate_piece_checks<ROOK>(pos, b, dc, ksq, mlist);
-
- b = pos.queens(us);
- if (b)
- mlist = generate_piece_checks<QUEEN>(pos, b, dc, ksq, mlist);
-
- // Hopefully we always have a king ;-)
- mlist = generate_piece_checks_king(pos, pos.king_square(us), dc, ksq, mlist);
-
- // TODO: Castling moves!
-
- return int(mlist - mlist_start);
+ mlist = generate_piece_checks<PAWN>(pos, mlist, us, dc, ksq);
+ mlist = generate_piece_checks<KNIGHT>(pos, mlist, us, dc, ksq);
+ mlist = generate_piece_checks<BISHOP>(pos, mlist, us, dc, ksq);
+ mlist = generate_piece_checks<ROOK>(pos, mlist, us, dc, ksq);
+ mlist = generate_piece_checks<QUEEN>(pos, mlist, us, dc, ksq);
+ mlist = generate_piece_checks<KING>(pos, mlist, us, dc, ksq);
+
+ // Castling moves that give check. Very rare but nice to have!
+ if ( pos.can_castle_queenside(us)
+ && (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_D)
+ && castling_is_check(pos, QUEEN_SIDE))
+ mlist = generate_castle_moves<QUEEN_SIDE>(pos, mlist);
+
+ if ( pos.can_castle_kingside(us)
+ && (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_F)
+ && castling_is_check(pos, KING_SIDE))
+ mlist = generate_castle_moves<KING_SIDE>(pos, mlist);
+
+ return mlist;