]> git.sesse.net Git - remoteglot/commitdiff
Factor out the short and long scores into separate functions.
authorSteinar H. Gunderson <sesse@debian.org>
Sun, 1 Jul 2007 22:35:09 +0000 (00:35 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Sun, 1 Jul 2007 22:35:09 +0000 (00:35 +0200)
remoteglot.pl

index 36af4ed093e7af20f95bb83b7d17b878ca092498..5409d7bc9645e776629eab76c085799e4bb1a828 100755 (executable)
@@ -63,7 +63,7 @@ uciprint("setoption name UCI_AnalyseMode value true");
 uciprint("setoption name NalimovPath value c:\\nalimov");
 uciprint("setoption name NalimovUsage value Rarely");
 uciprint("setoption name Hash value 1024");
-uciprint("setoption name MultiPV value 3");
+uciprint("setoption name MultiPV value 3");
 # uciprint("setoption name Contempt value 1000");
 # uciprint("setoption name Outlook value Ultra Optimistic");
 uciprint("ucinewgame");
@@ -496,19 +496,9 @@ sub output_screen {
                my $mpv = 1;
                while (exists($uciinfo{'pv' . $mpv})) {
                        $text .= sprintf "  PV%2u", $mpv;
+                       my $score = short_score(\%uciinfo, \%ficsinfo, $mpv);
+                       $text .= "  ($score)" if (!defined($score));
 
-                       if (defined($uciinfo{'score_mate' . $mpv})) {
-                               $text .= sprintf " (M%3d)", $uciinfo{'score_mate' . $mpv};
-                       } else {
-                               if (exists($uciinfo{'score_cp' . $mpv})) {
-                                       my $score = $uciinfo{'score_cp' . $mpv} * 0.01;
-                                       if ($ficsinfo{'toplay'} eq 'B') {
-                                               $score = -$score;
-                                       }
-                                       $text .= sprintf " (%+5.2f)", $score;
-                               }
-                       }
-                       
                        if (exists($uciinfo{'nodes' . $mpv}) && exists($uciinfo{'nps' . $mpv}) && exists($uciinfo{'depth' . $mpv})) {
                                $text .= sprintf " (%5u kn, %3u kn/s, %2u ply)",
                                        $uciinfo{'nodes' . $mpv} / 1000, $uciinfo{'nps' . $mpv} / 1000, $uciinfo{'depth' . $mpv};
@@ -534,26 +524,8 @@ sub output_screen {
                }
 
                # single-PV
-               if (defined($uciinfo{'score_mate'})) {
-                       my $mate = $uciinfo{'score_mate'};
-                       if ($ficsinfo{'toplay'} eq 'B') {
-                               $mate = -$mate;
-                       }
-                       if ($mate > 0) {
-                               $text .= sprintf "  White mates in %u\n", $mate;
-                       } else {
-                               $text .= sprintf "  Black mates in %u\n", -$mate;
-                       }
-               } else {
-                       if (exists($uciinfo{'score_cp'})) {
-                               my $score = $uciinfo{'score_cp'} * 0.01;
-                               if ($ficsinfo{'toplay'} eq 'B') {
-                                       $score = -$score;
-                               }
-                               $text .= sprintf "  Score: %+5.2f\n", $score;
-                       }
-               }
-
+               my $score = long_score(\%uciinfo, \%ficsinfo, '');
+               $text .= "  $score\n" if defined($score);
                $text .=  "  PV: " . join(', ', prettyprint_pv($ficsinfo{'board'}, @{$uciinfo{'pv'}}));
                $text .=  "\n";
 
@@ -788,3 +760,47 @@ sub uciprint {
        print UCIWRITE "$msg\n";
        print UCILOG "=> $msg\n";
 }
+
+sub short_score {
+       my ($uciinfo, $ficsinfo, $mpv) = @_;
+
+       if (defined($uciinfo{'score_mate' . $mpv})) {
+               return sprintf "M%3d", $uciinfo{'score_mate' . $mpv};
+       } else {
+               if (exists($uciinfo{'score_cp' . $mpv})) {
+                       my $score = $uciinfo{'score_cp' . $mpv} * 0.01;
+                       if ($ficsinfo{'toplay'} eq 'B') {
+                               $score = -$score;
+                       }
+                       return sprintf "%+5.2f", $score;
+               }
+       }
+
+       return undef;
+}
+
+sub long_score {
+       my ($uciinfo, $ficsinfo, $mpv) = @_;
+
+       if (defined($uciinfo{'score_mate' . $mpv})) {
+               my $mate = $uciinfo{'score_mate' . $mpv};
+               if ($ficsinfo{'toplay'} eq 'B') {
+                       $mate = -$mate;
+               }
+               if ($mate > 0) {
+                       return sprintf "White mates in %u", $mate;
+               } else {
+                       return sprintf "Black mates in %u", -$mate;
+               }
+       } else {
+               if (exists($uciinfo{'score_cp' . $mpv})) {
+                       my $score = $uciinfo{'score_cp' . $mpv} * 0.01;
+                       if ($ficsinfo{'toplay'} eq 'B') {
+                               $score = -$score;
+                       }
+                       return sprintf "Score: %+5.2f", $score;
+               }
+       }
+
+       return undef;
+}