+ // From and to files must be one file apart, avoids a7h5
+ if (abs(square_file(from) - square_file(to)) != 1)
+ return false;
+ break;
+
+ case DELTA_N:
+ case DELTA_S:
+ // Pawn push. The destination square must be empty.
+ if (!square_is_empty(to))
+ return false;
+ break;
+
+ case DELTA_NN:
+ // Double white pawn push. The destination square must be on the fourth
+ // rank, and both the destination square and the square between the
+ // source and destination squares must be empty.
+ if ( square_rank(to) != RANK_4
+ || !square_is_empty(to)
+ || !square_is_empty(from + DELTA_N))
+ return false;
+ break;
+
+ case DELTA_SS:
+ // Double black pawn push. The destination square must be on the fifth
+ // rank, and both the destination square and the square between the
+ // source and destination squares must be empty.
+ if ( square_rank(to) != RANK_5
+ || !square_is_empty(to)
+ || !square_is_empty(from + DELTA_S))
+ return false;
+ break;
+
+ default:
+ return false;
+ }
+ }
+ else if (!bit_is_set(attacks_from(pc, from), to))
+ return false;
+
+ if (in_check())
+ {
+ // In case of king moves under check we have to remove king so to catch
+ // as invalid moves like b1a1 when opposite queen is on c1.
+ if (piece_type(piece_on(from)) == KING)
+ {
+ Bitboard b = occupied_squares();
+ clear_bit(&b, from);
+ if (attackers_to(move_to(m), b) & pieces(opposite_color(us)))
+ return false;
+ }
+ else
+ {
+ Bitboard target = checkers();
+ Square checksq = pop_1st_bit(&target);