]> git.sesse.net Git - remoteglot/commitdiff
Print out who's doing the analysis.
authorSteinar H. Gunderson <sesse@debian.org>
Sat, 30 Jun 2007 15:50:00 +0000 (17:50 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Sat, 30 Jun 2007 15:50:00 +0000 (17:50 +0200)
remoteglot.pl

index 9aaa43d654574c8e134f4f597d18ae7cd598aa65..d457e9297eb3cb6c2135092db68cae7d2fd99eb5 100755 (executable)
@@ -41,6 +41,7 @@ select(STDOUT);
 # open the chess engine
 my $pid = IPC::Open2::open2(*UCIREAD, *UCIWRITE, $engine);
 my %uciinfo = ();
+my %uciid = ();
 my %ficsinfo = ();
 
 uciprint("uci");
@@ -48,6 +49,7 @@ uciprint("uci");
 # gobble the options
 while (<UCIREAD>) {
        /uciok/ && last;
+       handle_uci($_);
 }
 
 uciprint("setoption name UCI_AnalyseMode value true");
@@ -105,15 +107,7 @@ while (1) {
        # any fun on the UCI channel?
        if ($nfound > 0 && vec($rout, fileno(UCIREAD), 1) == 1) {
                my $line = <UCIREAD>;
-               chomp $line;
-               $line =~ tr/\r//d;
-               print UCILOG "<= $line\n";
-               if ($line =~ /^info/) {
-                       my (@infos) = split / /, $line;
-                       shift @infos;
-
-                       parse_infos(@infos);
-               }
+               handle_uci($line);
                $sleep = 0;
 
                # don't update too often
@@ -123,6 +117,26 @@ while (1) {
        sleep $sleep;
 }
 
+sub handle_uci {
+       my ($line) = @_;
+
+       chomp $line;
+       $line =~ tr/\r//d;
+       print UCILOG "<= $line\n";
+       if ($line =~ /^info/) {
+               my (@infos) = split / /, $line;
+               shift @infos;
+
+               parse_infos(@infos);
+       }
+       if ($line =~ /^id/) {
+               my (@ids) = split / /, $line;
+               shift @ids;
+
+               parse_ids(@ids);
+       }
+}
+
 sub parse_infos {
        my (@x) = @_;
        my $mpv = '';
@@ -179,6 +193,22 @@ sub parse_infos {
        }
 }
 
+sub parse_ids {
+       my (@x) = @_;
+
+       while (scalar @x > 0) {
+               if ($x[0] =~ /^(name|author)$/) {
+                       my $key = shift @x;
+                       my $value = join(' ', @x);
+                       $uciid{$key} = $value;
+                       last;
+               }
+
+               # unknown
+               shift @x;
+       }
+}
+
 sub style12_to_fen {
        my $str = shift; 
        my (@x) = split / /, $str;
@@ -433,7 +463,12 @@ sub output_screen {
                return;
        }
 
-       print  "\e[H\e[2JAnalysis:\n\n";
+       print "\e[H\e[2J"; # clear the screen
+       if (exists($uciid{'name'})) {
+               print "Analysis by $uciid{'name'}:\n\n";
+       } else {
+               print "Analysis:\n\n";
+       }
 
        return unless (exists($ficsinfo{'board'}));