- // Is this a castling move? A king move is assumed to be a castling move
- // if the destination square is occupied by a friendly rook, or if the
- // distance between the source and destination squares is more than 1.
- if (piece == piece_of_color_and_type(us, KING))
+Move move_from_uci(const Position& pos, const string& str) {
+
+ for (MoveList<MV_LEGAL> ml(pos); !ml.end(); ++ml)
+ if (str == move_to_uci(ml.move(), pos.is_chess960()))
+ return ml.move();
+
+ return MOVE_NONE;
+}
+
+
+/// move_to_san() takes a position and a move as input, where it is assumed
+/// that the move is a legal move for the position. The return value is
+/// a string containing the move in short algebraic notation.
+
+const string move_to_san(Position& pos, Move m) {
+
+ if (m == MOVE_NONE)
+ return "(none)";
+
+ if (m == MOVE_NULL)
+ return "(null)";
+
+ assert(move_is_ok(m));
+
+ Bitboard attackers;
+ bool ambiguousMove, ambiguousFile, ambiguousRank;
+ Square sq, from = move_from(m);
+ Square to = move_to(m);
+ PieceType pt = piece_type(pos.piece_on(from));
+ string san;
+
+ if (move_is_castle(m))
+ san = (move_to(m) < move_from(m) ? "O-O-O" : "O-O");
+ else