- enum CastlingSide {
- KING_SIDE,
- QUEEN_SIDE
- };
-
- enum MoveType {
- CAPTURE,
- NON_CAPTURE,
- CHECK,
- EVASION
- };
-
- // Helper templates
- template<CastlingSide Side>
- MoveStack* generate_castle_moves(const Position&, MoveStack*);
-
- template<Color Us, MoveType Type>
- MoveStack* generate_pawn_moves(const Position&, MoveStack*, Bitboard = EmptyBoardBB,
- Square = SQ_NONE, Bitboard = EmptyBoardBB);
-
- // Template generate_piece_moves (captures and non-captures) with specializations and overloads
- template<PieceType>
- MoveStack* generate_piece_moves(const Position&, MoveStack*, Color, Bitboard);
-
- template<>
- MoveStack* generate_piece_moves<KING>(const Position&, MoveStack*, Color, Bitboard);
-
- template<PieceType Piece, MoveType Type>
- inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us) {
-
- assert(Piece == PAWN);
- assert(Type == CAPTURE || Type == NON_CAPTURE);
-
- return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m)
- : generate_pawn_moves<BLACK, Type>(p, m));
- }
-
- // Templates for non-capture checks generation
-
- template<PieceType Piece>
- MoveStack* generate_discovered_checks(const Position& pos, Square from, MoveStack* mlist);
-
- template<PieceType>
- MoveStack* generate_direct_checks(const Position&, MoveStack*, Color, Bitboard, Square);
-
- template<>
- inline MoveStack* generate_direct_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
-
- return (us == WHITE ? generate_pawn_moves<WHITE, CHECK>(p, m, dc, ksq)
- : generate_pawn_moves<BLACK, CHECK>(p, m, dc, ksq));
- }
-
- // Template generate_piece_evasions with specializations
- template<PieceType>
- MoveStack* generate_piece_evasions(const Position&, MoveStack*, Color, Bitboard, Bitboard);
-
- template<>
- inline MoveStack* generate_piece_evasions<PAWN>(const Position& p, MoveStack* m,
- Color us, Bitboard t, Bitboard pnd) {
-
- return (us == WHITE ? generate_pawn_moves<WHITE, EVASION>(p, m, pnd, SQ_NONE, t)
- : generate_pawn_moves<BLACK, EVASION>(p, m, pnd, SQ_NONE, t));
- }
-}
-
-
-////
-//// Functions
-////
-
-
-/// generate_captures() generates all pseudo-legal captures and queen
-/// promotions. Returns a pointer to the end of the move list.
-
-MoveStack* generate_captures(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
- assert(!pos.is_check());
-
- Color us = pos.side_to_move();
- Bitboard target = pos.pieces_of_color(opposite_color(us));
-
- mlist = generate_piece_moves<QUEEN>(pos, mlist, us, target);
- mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
- mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
- mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
- mlist = generate_piece_moves<PAWN, CAPTURE>(pos, mlist, us);
- return generate_piece_moves<KING>(pos, mlist, us, target);
-}
-
-
-/// generate_noncaptures() generates all pseudo-legal non-captures and
-/// underpromotions. Returns a pointer to the end of the move list.
-
-MoveStack* generate_noncaptures(const Position& pos, MoveStack* mlist) {
-
- assert(pos.is_ok());
- assert(!pos.is_check());
-
- Color us = pos.side_to_move();
- Bitboard target = pos.empty_squares();
-
- mlist = generate_piece_moves<PAWN, NON_CAPTURE>(pos, mlist, us);
- mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
- mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
- mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
- mlist = generate_piece_moves<QUEEN>(pos, mlist, us, target);
- mlist = generate_piece_moves<KING>(pos, mlist, us, target);
- mlist = generate_castle_moves<KING_SIDE>(pos, mlist);
- return generate_castle_moves<QUEEN_SIDE>(pos, mlist);
-}
-
-
-/// generate_non_capture_checks() generates all pseudo-legal non-captures and
-/// underpromotions that give check. Returns a pointer to the end of the move list.
-
-MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
-
- assert(pos.is_ok());
- assert(!pos.is_check());