]> git.sesse.net Git - remoteglot/commitdiff
Call in_check() fewer times. Actually 60% or so faster.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Sep 2014 16:42:14 +0000 (18:42 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Sep 2014 16:42:14 +0000 (18:42 +0200)
Board.pm

index 3d832781bc2b1d4dc84b89daa3b933b2d57dcdd0..f011b17510221f65774c1ae249a71243f1d451c5 100644 (file)
--- a/Board.pm
+++ b/Board.pm
@@ -393,8 +393,7 @@ sub _find_kings {
 
 # Returns if any side is in mate.
 sub in_mate {
 
 # Returns if any side is in mate.
 sub in_mate {
-       my $board = shift;
-       my $check = $board->in_check();
+       my ($board, $check) = @_;
        return 0 if ($check eq 'none');
 
        # try all possible moves for the side in check
        return 0 if ($check eq 'none');
 
        # try all possible moves for the side in check
@@ -434,9 +433,10 @@ sub prettyprint_move {
        my $pretty = $board->_prettyprint_move_no_check_or_mate($from_row, $from_col, $to_row, $to_col, $promo);
 
        my $nb = $board->make_move($from_row, $from_col, $to_row, $to_col, $promo);
        my $pretty = $board->_prettyprint_move_no_check_or_mate($from_row, $from_col, $to_row, $to_col, $promo);
 
        my $nb = $board->make_move($from_row, $from_col, $to_row, $to_col, $promo);
-       if ($nb->in_mate()) {
+       my $check = $nb->in_check();
+       if ($nb->in_mate($check)) {
                $pretty .= '#';
                $pretty .= '#';
-       } elsif ($nb->in_check() ne 'none') {
+       } elsif ($check ne 'none') {
                $pretty .= '+';
        }
        return ($pretty, $nb);
                $pretty .= '+';
        }
        return ($pretty, $nb);