From: Marco Costalba Date: Sun, 29 May 2011 09:47:13 +0000 (+0100) Subject: Fix SAN disambiguation bug X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=462a39ec496a94cf3f05ca60b4ddcc31150904ac Fix SAN disambiguation bug Signed-off-by: Marco Costalba --- diff --git a/src/move.cpp b/src/move.cpp index da9e977d..7504615d 100644 --- a/src/move.cpp +++ b/src/move.cpp @@ -115,12 +115,14 @@ const string move_to_san(Position& pos, Move m) { // Collect all legal moves of piece type 'pt' with destination 'to' MoveStack* last = generate(pos, mlist); - int f = 0, r = 0; + int f = 0, r = 0, cnt = 0; for (MoveStack* cur = mlist; cur != last; cur++) if ( move_to(cur->move) == to && pos.type_of_piece_on(move_from(cur->move)) == pt) { + cnt++; + if (square_file(move_from(cur->move)) == square_file(from)) f++; @@ -128,15 +130,18 @@ const string move_to_san(Position& pos, Move m) { r++; } - assert(f > 0 && r > 0); + assert(cnt > 0 && f > 0 && r > 0); // Disambiguation if we have more then one piece with destination 'to' - if (f == 1 && r > 1) - san += file_to_char(square_file(from)); - else if (f > 1 && r == 1) - san += rank_to_char(square_rank(from)); - else if (f > 1 && r > 1) - san += square_to_string(from); + if (cnt > 1) + { + if (f == 1) + san += file_to_char(square_file(from)); + else if (r == 1) + san += rank_to_char(square_rank(from)); + else + san += square_to_string(from); + } } if (pos.move_is_capture(m))