+ template<PieceType Piece>
+ MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) {
+
+ Square from, to;
+ Bitboard b;
+
+ for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
+ {
+ from = pos.piece_list(us, Piece, i);
+ b = pos.piece_attacks<Piece>(from) & target;
+ while (b)
+ {
+ to = pop_1st_bit(&b);
+ (*mlist++).move = make_move(from, to);
+ }
+ }
+ return mlist;
+ }
+
+ template<>
+ MoveStack* generate_piece_moves<KING>(const Position& pos, MoveStack* mlist, Color us, Bitboard target) {
+
+ Bitboard b;
+ Square to, from = pos.king_square(us);
+
+ b = pos.piece_attacks<KING>(from) & target;
+ while (b)
+ {
+ to = pop_1st_bit(&b);
+ (*mlist++).move = make_move(from, to);
+ }
+ return mlist;
+ }
+
+ template<PieceType Piece>
+ MoveStack* generate_piece_blocking_evasions(const Position& pos, Bitboard b,
+ Bitboard blockSquares, MoveStack* mlist) {
+ while (b)
+ {
+ Square from = pop_1st_bit(&b);
+ Bitboard bb = pos.piece_attacks<Piece>(from) & blockSquares;
+ while (bb)
+ {
+ Square to = pop_1st_bit(&bb);
+ (*mlist++).move = make_move(from, to);
+ }
+ }
+ return mlist;
+ }
+