From 66d165921d32058853830891db8ac60fedc46bd4 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 22 Mar 2009 14:32:00 +0100 Subject: [PATCH] Better castle move detector in move_to_san() Merged from iPhone Glaurung. Signed-off-by: Marco Costalba --- src/san.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/san.cpp b/src/san.cpp index 5d5fc06c..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"; } -- 2.39.2