- 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,
+ const CheckInfo* ci = nullptr) {
+
+ const bool Checks = Type == QUIET_CHECKS;
+
+ moveList = generate_pawn_moves<Us, Type>(pos, moveList, target, ci);
+ moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target, ci);
+ moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target, ci);
+ moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci);
+ moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci);
+
+ 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 && Type != EVASIONS && pos.can_castle(Us))
+ {
+ if (pos.is_chess960())
+ {
+ moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
+ moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
+ }
+ else
+ {
+ moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
+ moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
+ }
+ }
+
+ return moveList;