X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fjs%2Fchess.js;h=91f6c1dda7af308f342e08e05095ca26238566c7;hb=1770f13ae85fae334e7f680e244ad531970a514e;hp=af275589f65e1924bf880d37ba480c1c6b763f49;hpb=ed195fa00ccd9cceb58184d2a9e332d52fed26ad;p=remoteglot diff --git a/www/js/chess.js b/www/js/chess.js index af27558..91f6c1d 100644 --- a/www/js/chess.js +++ b/www/js/chess.js @@ -1120,7 +1120,14 @@ var Chess = function(fen) { return ''; } - let moves = find_attacking_moves(move.to, piece, move.color, sloppy); + let moves = find_attacking_moves(move.to, piece, move.color); + if (moves.length <= 1) { + // There can be no ambiguity, so don't bother checking legality + // (we assume the move has already been found legal). + return ''; + } + + moves = possibly_filter_moves(moves, move.color, !sloppy); var ambiguities = 0; var same_rank = 0; @@ -1169,11 +1176,12 @@ var Chess = function(fen) { return ''; } - // Find all moves featuring the given piece attacking the given square - // (using symmetry of all non-pawn-or-castle moves, we simply generate - // moves backwards). Does not support kings or pawns. Assumes there's - // not already a piece of our own color on the destination square. - function find_attacking_moves(to, piece, us, sloppy) { + // Find all pseudolegal moves featuring the given piece attacking + // the given square (using symmetry of all non-pawn-or-castle moves, + // we simply generate // moves backwards). Does not support kings + // or pawns. Assumes there's // not already a piece of our own color + // on the destination square. + function find_attacking_moves(to, piece, us) { let moves = []; function add_move(board, moves, from, to, flags, rook_sq) { @@ -1201,7 +1209,7 @@ var Chess = function(fen) { } } - return possibly_filter_moves(moves, us, !sloppy); + return moves; } function ascii() {