- // This is a castling move, but we have to translate it to the
- // internal "king captures rook" representation.
- SquareDelta delta = (to > from ? DELTA_E : DELTA_W);
- Square s = from + delta;
- while (relative_rank(us, s) == RANK_1 && pos.piece_on(s) != piece_of_color_and_type(us, ROOK))
- s += delta;
-
- return (relative_rank(us, s) == RANK_1 ? make_castle_move(from, s) : MOVE_NONE);
+ san = piece_type_to_char(pt);
+
+ // Disambiguation if we have more then one piece with destination 'to'
+ // note that for pawns is not needed because starting file is explicit.
+ attackers = pos.attackers_to(to) & pos.pieces(pt, pos.side_to_move());
+ clear_bit(&attackers, from);
+ ambiguousMove = ambiguousFile = ambiguousRank = false;
+
+ while (attackers)
+ {
+ sq = pop_1st_bit(&attackers);
+
+ if (square_file(sq) == square_file(from))
+ ambiguousFile = true;
+
+ if (square_rank(sq) == square_rank(from))
+ ambiguousRank = true;
+
+ ambiguousMove = true;
+ }
+
+ if (ambiguousMove)
+ {
+ if (!ambiguousFile)
+ san += file_to_char(square_file(from));
+ else if (!ambiguousRank)
+ san += rank_to_char(square_rank(from));
+ else
+ san += square_to_string(from);
+ }
+ }
+
+ if (pos.move_is_capture(m))
+ {
+ if (pt == PAWN)
+ san += file_to_char(square_file(from));
+
+ san += 'x';
+ }
+
+ san += square_to_string(to);
+
+ if (move_is_promotion(m))
+ {
+ san += '=';
+ san += piece_type_to_char(promotion_piece_type(m));