- moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
- moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
- moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target);
- moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target);
- moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target);
+ // Skip generating non-king moves when in double check
+ if (Type != EVASIONS || !more_than_one(pos.checkers()))
+ {
+ target = Type == EVASIONS ? between_bb(ksq, lsb(pos.checkers()))
+ : Type == NON_EVASIONS ? ~pos.pieces(Us)
+ : Type == CAPTURES ? pos.pieces(~Us)
+ : ~pos.pieces(); // QUIETS || QUIET_CHECKS
+
+ moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
+ moveList = generate_moves<Us, KNIGHT, Checks>(pos, moveList, target);
+ moveList = generate_moves<Us, BISHOP, Checks>(pos, moveList, target);
+ moveList = generate_moves<Us, ROOK, Checks>(pos, moveList, target);
+ moveList = generate_moves<Us, QUEEN, Checks>(pos, moveList, target);
+ }