X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsan.cpp;h=c8292462ad5019c264ff1901a0c2c9f63f7d77ca;hp=efdf1773956a90510b33034c469bbdb8f8c62758;hb=66d165921d32058853830891db8ac60fedc46bd4;hpb=9f943a132a2290f28eea388bf5ea45ddab7da973 diff --git a/src/san.cpp b/src/san.cpp index efdf1773..c8292462 100644 --- a/src/san.cpp +++ b/src/san.cpp @@ -70,23 +70,28 @@ const std::string move_to_san(const Position& pos, Move m) { assert(pos.is_ok()); assert(move_is_ok(m)); + Square from, to; + PieceType pt; + + from = move_from(m); + to = move_to(m); + pt = type_of_piece(pos.piece_on(move_from(m))); + std::string san = ""; if (m == MOVE_NONE) return "(none)"; else if (m == MOVE_NULL) return "(null)"; - else if (move_is_long_castle(m)) + else if (move_is_long_castle(m) || (int(to - from) == -2 && pt == KING)) san = "O-O-O"; - else if (move_is_short_castle(m)) + else if (move_is_short_castle(m) || (int(to - from) == 2 && pt == KING)) san = "O-O"; else { - Piece pc = pos.piece_on(move_from(m)); - if (type_of_piece(pc) != PAWN) + if (pt != PAWN) { - san += piece_type_to_char(type_of_piece(pc), true); - Square from = move_from(m); + san += piece_type_to_char(pt, true); switch (move_ambiguity(pos, m)) { case AMBIGUITY_NONE: break; @@ -105,7 +110,7 @@ const std::string move_to_san(const Position& pos, Move m) { } if (pos.move_is_capture(m)) { - if (type_of_piece(pc) == PAWN) + if (pt == PAWN) san += file_to_char(square_file(move_from(m))); san += "x"; } @@ -119,9 +124,9 @@ const std::string move_to_san(const Position& pos, Move m) { // Is the move check? We don't use pos.move_is_check(m) here, because // Position::move_is_check doesn't detect all checks (not castling moves, // promotions and en passant captures). - UndoInfo u; + StateInfo st; Position p(pos); - p.do_move(m, u); + p.do_move(m, st); if (p.is_check()) san += p.is_mate()? "#" : "+"; @@ -172,7 +177,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) { for (size_t i = 0; i < movestr.length(); i++) { char type, c = movestr[i]; - if (pieceLetters.find(c) != -1) + if (pieceLetters.find(c) != std::string::npos) type = 'P'; else if (c >= 'a' && c <= 'h') type = 'F'; @@ -223,7 +228,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) { toRank = rank_from_char(c); state = (i < movestr.length() - 1) ? PROMOTION_OR_CHECK : END; } - else if (state == TO_FILE && fromRank == FILE_NONE) + else if (state == TO_FILE && fromRank == RANK_NONE) { // It's a disambiguation rank instead of a file fromRank = rank_from_char(c); @@ -263,7 +268,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) { return MOVE_NONE; // Look for a matching move - Move m, move; + Move m, move = MOVE_NONE; to = make_square(toFile, toRank); int matches = 0; @@ -290,7 +295,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) { const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) { - UndoInfo u; + StateInfo st; std::stringstream s; std::string moveStr; size_t length = 0; @@ -309,9 +314,9 @@ const std::string line_to_san(const Position& pos, Move line[], int startColumn, s << moveStr << ' '; if (line[i] == MOVE_NULL) - p.do_null_move(u); + p.do_null_move(st); else - p.do_move(line[i], u); + p.do_move(line[i], st); } return s.str(); }