- struct PawnParams {
- Bitboard Rank3BB, Rank8BB;
- Rank RANK_8;
- SquareDelta DELTA_N, DELTA_NE, DELTA_NW;
- Color us, them;
- };
- const PawnParams WhitePawnParams = { Rank3BB, Rank8BB, RANK_8, DELTA_N, DELTA_NE, DELTA_NW, WHITE, BLACK };
- const PawnParams BlackPawnParams = { Rank6BB, Rank1BB, RANK_1, DELTA_S, DELTA_SE, DELTA_SW, BLACK, WHITE };
-
- int generate_castle_moves(const Position&, MoveStack*);
-
- template<Color>
- int generate_pawn_captures(const Position&, MoveStack*);
-
- template<Color>
- int generate_pawn_noncaptures(const Position&, MoveStack*);
-
- template<Color>
- int generate_pawn_checks(const Position&, Bitboard, Square, MoveStack*);
-
- template<Color>
- int generate_pawn_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*);
-
- template<PieceType>
- int generate_piece_moves(const Position&, MoveStack*, Bitboard);
-
- template<PieceType>
- int generate_piece_checks(const Position&, Bitboard, Bitboard, Square, MoveStack*);
- int generate_piece_checks_king(const Position&, Square, Bitboard, Square, MoveStack*);
-
- template<PieceType>
- int generate_piece_blocking_evasions(const Position&, Bitboard, Bitboard, MoveStack*);
-}
-
-
-////
-//// Functions
-////
-
-
-/// generate_captures generates() all pseudo-legal captures and queen
-/// promotions. The return value is the number of moves generated.
-
-int 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));
- int n;
-
- if (us == WHITE)
- n = generate_pawn_captures<WHITE>(pos, mlist);
- else
- n = generate_pawn_captures<BLACK>(pos, mlist);
-
- n += generate_piece_moves<KNIGHT>(pos, mlist+n, target);
- n += generate_piece_moves<BISHOP>(pos, mlist+n, target);
- n += generate_piece_moves<ROOK>(pos, mlist+n, target);
- n += generate_piece_moves<QUEEN>(pos, mlist+n, target);
- n += generate_piece_moves<KING>(pos, mlist+n, target);
- return n;
-}
-
-
-/// generate_noncaptures() generates all pseudo-legal non-captures and
-/// underpromotions. The return value is the number of moves generated.
-
-int 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();
- int n;
-
- if (us == WHITE)
- n = generate_pawn_noncaptures<WHITE>(pos, mlist);
- else
- n = generate_pawn_noncaptures<BLACK>(pos, mlist);
-
- n += generate_piece_moves<KNIGHT>(pos, mlist+n, target);
- n += generate_piece_moves<BISHOP>(pos, mlist+n, target);
- n += generate_piece_moves<ROOK>(pos, mlist+n, target);
- n += generate_piece_moves<QUEEN>(pos, mlist+n, target);
- n += generate_piece_moves<KING>(pos, mlist+n, target);
- n += generate_castle_moves(pos, mlist+n);
- return n;
-}
-
-
-/// generate_checks() generates all pseudo-legal non-capturing, non-promoting
-/// checks, except castling moves (will add this later). It returns the
-/// number of generated moves.
-
-int generate_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
-
- assert(pos.is_ok());
- assert(!pos.is_check());
-
- int n;
- Color us = pos.side_to_move();
- Square ksq = pos.king_square(opposite_color(us));
-
- assert(pos.piece_on(ksq) == king_of_color(opposite_color(us)));
-
- dc = pos.discovered_check_candidates(us);
-
- // Pawn moves
- if (us == WHITE)
- n = generate_pawn_checks<WHITE>(pos, dc, ksq, mlist);
- else
- n = generate_pawn_checks<BLACK>(pos, dc, ksq, mlist);
-
- // Pieces moves
- Bitboard b = pos.knights(us);
- if (b)
- n += generate_piece_checks<KNIGHT>(pos, b, dc, ksq, mlist+n);
-
- b = pos.bishops(us);
- if (b)
- n += generate_piece_checks<BISHOP>(pos, b, dc, ksq, mlist+n);
-
- b = pos.rooks(us);
- if (b)
- n += generate_piece_checks<ROOK>(pos, b, dc, ksq, mlist+n);
-
- b = pos.queens(us);
- if (b)
- n += generate_piece_checks<QUEEN>(pos, b, dc, ksq, mlist+n);
-
- // Hopefully we always have a king ;-)
- n += generate_piece_checks_king(pos, pos.king_square(us), dc, ksq, mlist+n);
-
- // TODO: Castling moves!
-
- return n;
-}
-
-
-/// generate_evasions() generates all check evasions when the side to move is
-/// in check. Unlike the other move generation functions, this one generates
-/// only legal moves. It returns the number of generated moves. This
-/// function is very ugly, and needs cleaning up some time later. FIXME