template<Color Us, GenType Type>
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
- constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
+ constexpr Color Them = ~Us;
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
constexpr Direction Up = pawn_push(Us);
template<Color Us, GenType Type>
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
-
- constexpr CastlingRights OO = Us & KING_SIDE;
- constexpr CastlingRights OOO = Us & QUEEN_SIDE;
constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
while (b)
*moveList++ = make_move(ksq, pop_lsb(&b));
- if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO)))
- {
- if (!pos.castling_impeded(OO) && pos.can_castle(OO))
- *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OO));
-
- if (!pos.castling_impeded(OOO) && pos.can_castle(OOO))
- *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OOO));
- }
+ if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING))
+ for(CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
+ if (!pos.castling_impeded(cr) && pos.can_castle(cr))
+ *moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(cr));
}
return moveList;
assert(!pos.checkers());
Color us = pos.side_to_move();
- Bitboard dc = pos.blockers_for_king(~us) & pos.pieces(us);
+ Bitboard dc = pos.blockers_for_king(~us) & pos.pieces(us) & ~pos.pieces(PAWN);
while (dc)
{
Square from = pop_lsb(&dc);
PieceType pt = type_of(pos.piece_on(from));
- if (pt == PAWN)
- continue; // Will be generated together with direct checks
-
Bitboard b = pos.attacks_from(pt, from) & ~pos.pieces();
if (pt == KING)
// the king evasions in order to skip known illegal moves, which avoids any
// useless legality checks later on.
while (sliders)
- {
- Square checksq = pop_lsb(&sliders);
- sliderAttacks |= LineBB[checksq][ksq] ^ checksq;
- }
+ sliderAttacks |= LineBB[ksq][pop_lsb(&sliders)] & ~pos.checkers();
// Generate evasions for king, capture and non capture moves
Bitboard b = pos.attacks_from<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;