- int generate_white_pawn_captures(const Position&, MoveStack*);
- int generate_black_pawn_captures(const Position&, MoveStack*);
- int generate_white_pawn_noncaptures(const Position&, MoveStack*);
- int generate_black_pawn_noncaptures(const Position&, MoveStack*);
- int generate_piece_moves(PieceType, const Position&, MoveStack*, Color side, Bitboard t);
- int generate_king_moves(const Position&, MoveStack*, Square from, Bitboard t);
- int generate_castle_moves(const Position&, MoveStack*, Color us);
+ template<Color>
+ int generate_pawn_checks(const Position&, Bitboard, Square, MoveStack*, int);
+
+ template<Color>
+ int generate_pawn_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*, int);
+
+ template<PieceType>
+ int generate_piece_moves(const Position&, MoveStack*, Color, Bitboard);
+
+ template<PieceType>
+ int generate_piece_checks(const Position&, Bitboard, Bitboard, Square, MoveStack*, int);
+
+ template<PieceType>
+ int generate_piece_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*, int);
+
+
+ /// Templates are defined here to avoid lookup issues with specializations
+
+ template<PieceType Piece>
+ int generate_piece_moves(const Position &pos, MoveStack *mlist,
+ Color side, Bitboard target) {
+ int n = 0;
+ for (int i = 0; i < pos.piece_count(side, Piece); i++)
+ {
+ Square from = pos.piece_list(side, Piece, i);
+ Bitboard b = pos.piece_attacks<Piece>(from) & target;
+ while (b)
+ {
+ Square to = pop_1st_bit(&b);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ return n;
+ }
+
+
+ template<PieceType Piece>
+ int generate_piece_checks(const Position& pos, Bitboard target, Bitboard dc,
+ Square ksq, MoveStack* mlist, int n) {
+ // Discovered checks
+ Bitboard b = target & dc;
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = pos.piece_attacks<Piece>(from) & pos.empty_squares();
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ // Direct checks
+ b = target & ~dc;
+ Bitboard checkSqs = pos.piece_attacks<Piece>(ksq) & pos.empty_squares();
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = pos.piece_attacks<Piece>(from) & checkSqs;
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ mlist[n++].move = make_move(from, to);
+ }
+ }
+ return n;
+ }
+
+
+ template<> // Special case the King
+ int generate_piece_checks<KING>(const Position& pos, Bitboard, Bitboard dc,
+ Square ksq, MoveStack* mlist, int n) {
+ if (bit_is_set(dc, ksq))
+ {
+ Bitboard bb = pos.piece_attacks<KING>(ksq)
+ & pos.empty_squares()
+ & ~QueenPseudoAttacks[ksq];
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ mlist[n++].move = make_move(ksq, to);
+ }
+ }
+ return n;
+ }