# open the chess engine
my $pid = IPC::Open2::open2(*UCIREAD, *UCIWRITE, $engine);
my %uciinfo = ();
+my %uciid = ();
my %ficsinfo = ();
uciprint("uci");
# gobble the options
while (<UCIREAD>) {
/uciok/ && last;
+ handle_uci($_);
}
uciprint("setoption name UCI_AnalyseMode value true");
# 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
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 = '';
}
}
+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;
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'}));