]> git.sesse.net Git - remoteglot/commitdiff
When parsing moves, use illegal moves to disambiguate.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 15 Jun 2014 17:09:46 +0000 (19:09 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 15 Jun 2014 17:09:46 +0000 (19:09 +0200)
Board.pm

index b925a388952ce6c5cc6e5ae1d35d00a5898d6171..1838f7dd492846c858cdc10f5c66707311c89f09 100644 (file)
--- a/Board.pm
+++ b/Board.pm
@@ -194,6 +194,14 @@ sub parse_pretty_move {
                        next if (defined($from_col) && $from_col != $col);
                        next if ($board->[$row][$col] ne $piece);
                        next if (!$board->can_reach($piece, $row, $col, $to_row, $to_col));
+
+                       # See if doing this move would put us in check
+                       # (yes, there are clients that expect us to do this).
+                       my $check = $board->make_move($row, $col, $to_row, $to_col, $promo)->in_check();
+                       next if ($check eq 'both' ||
+                                ($toplay eq 'W' && $check eq 'white') ||
+                                ($toplay eq 'B' && $check eq 'black'));
+
                        push @squares, [ $row, $col ];
                }
        }