- if (f == 1 && r > 1)
- san += file_to_char(square_file(from));
- else if (f > 1 && r == 1)
- san += rank_to_char(square_rank(from));
- else if (f > 1 && r > 1)
- san += square_to_string(from);
+ // 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);
+ }