- inline Bitboard forward_white(Bitboard b) { return b << 8; }
- inline Bitboard forward_right_white(Bitboard b) { return b << 9; }
- inline Bitboard forward_left_white(Bitboard b) { return b << 7; }
-
- inline Bitboard forward_black(Bitboard b) { return b >> 8; }
- inline Bitboard forward_right_black(Bitboard b) { return b >> 7; }
- inline Bitboard forward_left_black(Bitboard b) { return b >> 9; }
-
- struct PawnOffsets {
-
- Bitboard Rank3BB, Rank8BB;
- Rank RANK_8;
- SquareDelta DELTA_N, DELTA_NE, DELTA_NW;
- Color us, them;
- typedef Bitboard (*Shift_fn)(Bitboard b);
- Shift_fn forward, forward_left, forward_right;
- };
-
- const PawnOffsets WhitePawnOffsets = { Rank3BB, Rank8BB, RANK_8, DELTA_N, DELTA_NE, DELTA_NW, WHITE, BLACK,
- &forward_white, forward_left_white, forward_right_white };
-
- const PawnOffsets BlackPawnOffsets = { Rank6BB, Rank1BB, RANK_1, DELTA_S, DELTA_SE, DELTA_SW, BLACK, WHITE,
- &forward_black, &forward_left_black, &forward_right_black };
-
- int generate_pawn_captures(const PawnOffsets&, const Position&, MoveStack*);
- int generate_pawn_noncaptures(const PawnOffsets&, const Position&, MoveStack*);
- int generate_pawn_checks(const PawnOffsets&, const Position&, Bitboard, Square, MoveStack*, int);
- int generate_piece_checks(PieceType, const Position&, Bitboard, Bitboard, Square, MoveStack*, int);
- int generate_piece_moves(PieceType, const Position&, MoveStack*, Color, Bitboard);
- int generate_castle_moves(const Position&, MoveStack*, Color);
- int generate_piece_blocking_evasions(PieceType, const Position&, Bitboard, Bitboard, MoveStack*, int);
- int generate_pawn_blocking_evasions(const PawnOffsets&, const Position&, Bitboard, Bitboard, MoveStack*, int);
-}
-
-
-////
-//// 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(WhitePawnOffsets, pos, mlist);
- else
- n = generate_pawn_captures(BlackPawnOffsets, pos, mlist);
-
- for (PieceType pce = KNIGHT; pce <= KING; pce++)
- n += generate_piece_moves(pce, pos, mlist+n, us, 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(WhitePawnOffsets, pos, mlist);
- else
- n = generate_pawn_noncaptures(BlackPawnOffsets, pos, mlist);
-
- for (PieceType pce = KNIGHT; pce <= KING; pce++)
- n += generate_piece_moves(pce, pos, mlist+n, us, target);
-
- n += generate_castle_moves(pos, mlist+n, us);
- 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.