- template<> FORCE_INLINE
- MoveStack* generate_moves<KING, false>(const Position& pos, MoveStack* mlist, Color us,
- Bitboard target, const CheckInfo*) {
- Square from = pos.king_square(us);
- Bitboard b = pos.attacks_from<KING>(from) & target;
- SERIALIZE(b);
- return mlist;
+
+ template<Color Us, GenType Type>
+ ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
+
+ constexpr CastlingRights OO = Us & KING_SIDE;
+ constexpr CastlingRights OOO = Us & QUEEN_SIDE;
+ constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
+
+ moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
+ moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
+ moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target);
+ moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target);
+ moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target);
+
+ if (Type != QUIET_CHECKS && Type != EVASIONS)
+ {
+ Square ksq = pos.square<KING>(Us);
+ Bitboard b = pos.attacks_from<KING>(ksq) & target;
+ while (b)
+ *moveList++ = make_move(ksq, pop_lsb(&b));
+
+ if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO)))
+ {
+ if (!pos.castling_impeded(OO) && pos.can_castle(OO))
+ *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OO));
+
+ if (!pos.castling_impeded(OOO) && pos.can_castle(OOO))
+ *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OOO));
+ }
+ }
+
+ return moveList;