+# Like can_reach, but also checks the move doesn't put the side in check.
+# We use this in prettyprint_move to reduce the disambiguation, because Chess.js
+# needs moves to be in minimally disambiguated form.
+sub can_legally_reach {
+ my ($board, $piece, $from_row, $from_col, $to_row, $to_col) = @_;
+
+ return 0 if (!can_reach($board, $piece, $from_row, $from_col, $to_row, $to_col));
+
+ my $nb = $board->make_move($from_row, $from_col, $to_row, $to_col);
+ my $side = ($piece eq lc($piece)) ? 'k' : 'K';
+
+ return !in_check($nb, $side);
+}
+