From: Marco Costalba Date: Sat, 9 Feb 2013 05:40:46 +0000 (+0100) Subject: Simplify move_to_san() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=3f44be9baa38663bce163e4f7c9ab00a1553529f Simplify move_to_san() Nicely simplify disambiguation code. No functional change. --- diff --git a/src/notation.cpp b/src/notation.cpp index bb4a713c..b8e89b67 100644 --- a/src/notation.cpp +++ b/src/notation.cpp @@ -110,8 +110,7 @@ const string move_to_san(Position& pos, Move m) { assert(MoveList(pos).contains(m)); - Bitboard attackers; - bool ambiguousMove, ambiguousFile, ambiguousRank; + Bitboard others, b; string san; Color us = pos.side_to_move(); Square from = from_sq(m); @@ -127,31 +126,23 @@ const string move_to_san(Position& pos, Move m) { { san = PieceToChar[WHITE][pt]; // Upper case - // Disambiguation if we have more then one piece with destination 'to' - // note that for pawns is not needed because starting file is explicit. - ambiguousMove = ambiguousFile = ambiguousRank = false; + // Disambiguation if we have more then one piece of type 'pt' that can + // reach 'to' with a legal move. + others = b = (pos.attacks_from(pc, to) & pos.pieces(us, pt)) ^ from; - attackers = (pos.attacks_from(pc, to) & pos.pieces(us, pt)) ^ from; - - while (attackers) + while (b) { - Square sq = pop_lsb(&attackers); - - // If the move is illegal, the piece is not included in the sub-set - if (!pos.pl_move_is_legal(make_move(sq, to), pos.pinned_pieces())) - continue; - - ambiguousFile |= file_of(sq) == file_of(from); - ambiguousRank |= rank_of(sq) == rank_of(from); - ambiguousMove = true; + Move move = make_move(pop_lsb(&b), to); + if (!pos.pl_move_is_legal(move, pos.pinned_pieces())) + others ^= from_sq(move); } - if (ambiguousMove) + if (others) { - if (!ambiguousFile) + if (!(others & file_bb(from))) san += file_to_char(file_of(from)); - else if (!ambiguousRank) + else if (!(others & rank_bb(from))) san += rank_to_char(rank_of(from)); else