- enum CastlingSide {
- KING_SIDE,
- QUEEN_SIDE
- };
-
- enum MoveType {
- CAPTURE,
- NON_CAPTURE
- };
-
- // Functions
- bool castling_is_check(const Position&, CastlingSide);
-
- // Helper templates
- template<CastlingSide Side>
- MoveStack* generate_castle_moves(const Position& pos, MoveStack* mlist);
-
- template<Color Us>
- MoveStack* generate_pawn_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*);
-
- template<Color Us>
- MoveStack* generate_pawn_captures(const Position& pos, MoveStack* mlist);
-
- template<Color Us, SquareDelta Diagonal>
- MoveStack* generate_pawn_captures_diagonal(MoveStack* mlist, Bitboard pawns, Bitboard enemyPieces, bool promotion);
-
- template<Color Us>
- MoveStack* generate_pawn_noncaptures(const Position& pos, MoveStack* mlist);
-
- template<Color Us>
- MoveStack* generate_pawn_checks(const Position&, Bitboard, Square, MoveStack*);
-
- template<Color Us, SquareDelta Direction>
- inline Bitboard move_pawns(Bitboard p) {
-
- if (Direction == DELTA_N)
- return Us == WHITE ? p << 8 : p >> 8;
- else if (Direction == DELTA_NE)
- return Us == WHITE ? p << 9 : p >> 7;
- else if (Direction == DELTA_NW)
- return Us == WHITE ? p << 7 : p >> 9;
- else
- return p;
- }
-
- // Template generate_piece_checks() with specializations
- template<PieceType>
- MoveStack* generate_piece_checks(const Position&, MoveStack*, Color, Bitboard, Square);
-
- template<>
- inline MoveStack* generate_piece_checks<PAWN>(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) {
-
- return (us == WHITE ? generate_pawn_checks<WHITE>(p, dc, ksq, m)
- : generate_pawn_checks<BLACK>(p, dc, ksq, m));
- }
-
- // Template generate_piece_moves() with specializations and overloads
- template<PieceType>
- MoveStack* generate_piece_moves(const Position&, MoveStack*, Color us, 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);
-
- if (Type == CAPTURE)
- return (us == WHITE ? generate_pawn_captures<WHITE>(p, m)
- : generate_pawn_captures<BLACK>(p, m));
- else
- return (us == WHITE ? generate_pawn_noncaptures<WHITE>(p, m)
- : generate_pawn_noncaptures<BLACK>(p, m));
- }
-
- template<PieceType>
- MoveStack* generate_piece_moves(const Position&, MoveStack*, Color us, Bitboard, Bitboard);
-
- template<>
- inline MoveStack* generate_piece_moves<PAWN>(const Position& p, MoveStack* m,
- Color us, Bitboard t, Bitboard pnd) {
-
- return (us == WHITE ? generate_pawn_blocking_evasions<WHITE>(p, pnd, t, m)
- : generate_pawn_blocking_evasions<BLACK>(p, pnd, t, m));
- }
-}
-
-
-////
-//// 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-capturing,
-/// non-promoting checks. Returns a pointer to the end of the move list.