+ Piece pc = piece_on(from);
+
+ // Use a slower but simpler function for uncommon cases
+ if (move_is_special(m))
+ return move_is_pl_full(m);
+
+ // Is not a promotion, so promotion piece must be empty
+ if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE)
+ return false;
+
+ // If the from square is not occupied by a piece belonging to the side to
+ // move, the move is obviously not legal.
+ if (pc == PIECE_NONE || color_of_piece(pc) != us)
+ return false;
+
+ // The destination square cannot be occupied by a friendly piece
+ if (color_of_piece_on(to) == us)
+ return false;
+
+ // Handle the special case of a pawn move
+ if (type_of_piece(pc) == PAWN)
+ {
+ // Move direction must be compatible with pawn color
+ int direction = to - from;
+ if ((us == WHITE) != (direction > 0))
+ return false;
+
+ // We have already handled promotion moves, so destination
+ // cannot be on the 8/1th rank.
+ if (square_rank(to) == RANK_8 || square_rank(to) == RANK_1)
+ return false;
+
+ // Proceed according to the square delta between the origin and
+ // destination squares.
+ switch (direction)
+ {
+ case DELTA_NW:
+ case DELTA_NE:
+ case DELTA_SW:
+ case DELTA_SE:
+ // Capture. The destination square must be occupied by an enemy
+ // piece (en passant captures was handled earlier).
+ if (color_of_piece_on(to) != them)
+ return false;