- // If the string has more than 4 characters, try to interpret the 5th
- // character as a promotion.
- if (str.length() > 4 && piece == piece_of_color_and_type(us, PAWN))
- {
- switch (tolower(str[4])) {
- case 'n':
- return make_promotion_move(from, to, KNIGHT);
- case 'b':
- return make_promotion_move(from, to, BISHOP);
- case 'r':
- return make_promotion_move(from, to, ROOK);
- case 'q':
- return make_promotion_move(from, to, QUEEN);
- }
- }
+ return square_to_string(from) + square_to_string(to) + promotion;
+}
+
+
+/// move_from_uci() takes a position and a string representing a move in
+/// simple coordinate notation and returns an equivalent Move if any.
+/// Moves are guaranteed to be legal.
+
+Move move_from_uci(const Position& pos, const string& str) {
+
+ MoveStack mlist[MAX_MOVES];
+ MoveStack* last = generate<MV_LEGAL>(pos, mlist);
+
+ for (MoveStack* cur = mlist; cur != last; cur++)
+ if (str == move_to_uci(cur->move, pos.is_chess960()))
+ return cur->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 from the position. The return value is
+/// a string containing the move in short algebraic notation.
+
+const string move_to_san(Position& pos, Move m) {
+
+ assert(pos.is_ok());
+ assert(move_is_ok(m));
+
+ Bitboard attackers;
+ bool ambiguousMove, ambiguousFile, ambiguousRank;
+ Square sq, from = move_from(m);
+ Square to = move_to(m);
+ PieceType pt = pos.type_of_piece_on(from);
+ string san;
+
+ if (m == MOVE_NONE)
+ return "(none)";