X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmove.cpp;h=7504615d6d670c5ee0e7279ca90c57aa06bd6b27;hb=2f6142cb9bd9db2a749fa3faad4d0ef793336ddb;hp=ff0adbe5b6d7cfce860b30b732d7dc17e7cccd0f;hpb=321320b0814d5994640977cf96e015eba8ce22d5;p=stockfish diff --git a/src/move.cpp b/src/move.cpp index ff0adbe5..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)) @@ -156,11 +161,11 @@ const string move_to_san(Position& pos, Move m) { } } - // The move gives check? We don't use pos.move_is_check() here + // The move gives check? We don't use pos.move_gives_check() here // because we need to test for a mate after the move is done. StateInfo st; pos.do_move(m, st); - if (pos.is_check()) + if (pos.in_check()) san += pos.is_mate() ? "#" : "+"; pos.undo_move(m);