- // Template generate_piece_moves (captures and non-captures) with specializations and overloads
- template<PieceType>
- MoveStack* generate_piece_moves(const Position&, MoveStack*, Color, Bitboard);
+ template<PieceType Piece>
+ inline MoveStack* generate_discovered_checks(const Position& pos, MoveStack* mlist, Square from) {
+
+ assert(Piece != QUEEN);
+
+ Bitboard b = pos.attacks_from<Piece>(from) & pos.empty_squares();
+ if (Piece == KING)
+ {
+ Square ksq = pos.king_square(opposite_color(pos.side_to_move()));
+ b &= ~QueenPseudoAttacks[ksq];
+ }
+ SERIALIZE_MOVES(b);
+ return mlist;
+ }
+
+ template<PieceType Piece>
+ inline MoveStack* generate_direct_checks(const Position& pos, MoveStack* mlist, Color us,
+ Bitboard dc, Square ksq) {
+ assert(Piece != KING);
+
+ Bitboard checkSqs, b;
+ Square from;
+ const Square* ptr = pos.piece_list_begin(us, Piece);
+
+ if ((from = *ptr++) == SQ_NONE)
+ return mlist;
+
+ checkSqs = pos.attacks_from<Piece>(ksq) & pos.empty_squares();
+
+ do
+ {
+ if ( (Piece == QUEEN && !(QueenPseudoAttacks[from] & checkSqs))
+ || (Piece == ROOK && !(RookPseudoAttacks[from] & checkSqs))
+ || (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
+ continue;
+
+ if (dc && bit_is_set(dc, from))
+ continue;
+
+ b = pos.attacks_from<Piece>(from) & checkSqs;
+ SERIALIZE_MOVES(b);
+
+ } while ((from = *ptr++) != SQ_NONE);
+
+ return mlist;
+ }