+ let moves;
+ let piece_matches = clean_move.match(/^([NBRQK])x?([a-h][1-8])$/);
+ if (piece_matches) {
+ // Only look for moves by the given piece to the given square.
+ let to = SQUARES[piece_matches[2]];
+ if (board[to] != null && board[to].color === turn) {
+ // Cannot capture our own piece.
+ return null;
+ }
+ moves = find_attacking_moves(to, piece_matches[1].toLowerCase(), turn);
+ // Legal moves only.
+ moves = possibly_filter_moves(moves, turn, true);
+ } else {
+ // Fallback (also used for pawns): Any (legal) moves.
+ moves = generate_moves();
+ }
+