From 3b624f881c25e5455e2972eb2d22efe37a5c9f38 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 20 Sep 2014 18:42:14 +0200 Subject: [PATCH] Call in_check() fewer times. Actually 60% or so faster. --- Board.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Board.pm b/Board.pm index 3d83278..f011b17 100644 --- a/Board.pm +++ b/Board.pm @@ -393,8 +393,7 @@ sub _find_kings { # 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 @@ -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); - if ($nb->in_mate()) { + my $check = $nb->in_check(); + if ($nb->in_mate($check)) { $pretty .= '#'; - } elsif ($nb->in_check() ne 'none') { + } elsif ($check ne 'none') { $pretty .= '+'; } return ($pretty, $nb); -- 2.39.2