-/// move_to_san() takes a position and a legal Move as input and returns its
-/// short algebraic notation representation.
-
-const string move_to_san(Position& pos, Move m) {
-
- if (m == MOVE_NONE)
- return "(none)";
-
- if (m == MOVE_NULL)
- return "(null)";
-
- assert(MoveList<LEGAL>(pos).contains(m));
-
- Bitboard others, b;
- string san;
- Color us = pos.side_to_move();
- Square from = from_sq(m);
- Square to = to_sq(m);
- Piece pc = pos.piece_on(from);
- PieceType pt = type_of(pc);
-
- if (type_of(m) == CASTLE)
- san = to > from ? "O-O" : "O-O-O";
- else
- {
- if (pt != PAWN)
- {
- san = PieceToChar[WHITE][pt]; // Upper case
-
- // Disambiguation if we have more then one piece of type 'pt' that can
- // reach 'to' with a legal move.
- others = b = (pos.attacks_from(pc, to) & pos.pieces(us, pt)) ^ from;
-
- while (b)
- {
- Move move = make_move(pop_lsb(&b), to);
- if (!pos.pl_move_is_legal(move, pos.pinned_pieces()))
- others ^= from_sq(move);
- }
-
- if (others)
- {
- if (!(others & file_bb(from)))
- san += file_to_char(file_of(from));
-
- else if (!(others & rank_bb(from)))
- san += rank_to_char(rank_of(from));
-
- else
- san += square_to_string(from);
- }
- }
- else if (pos.is_capture(m))
- san = file_to_char(file_of(from));
-
- if (pos.is_capture(m))
- san += 'x';
-
- san += square_to_string(to);
-
- if (type_of(m) == PROMOTION)
- san += string("=") + PieceToChar[WHITE][promotion_type(m)];
- }
-
- if (pos.move_gives_check(m, CheckInfo(pos)))
- {
- StateInfo st;
- pos.do_move(m, st);
- san += MoveList<LEGAL>(pos).size() ? "+" : "#";
- pos.undo_move(m);
- }
-
- return san;
-}
-
-