+
+ return if (!defined($pos_calculating));
+
+ #
+ # Check the PVs first. if they're invalid, just wait, as our data
+ # is most likely out of sync. This isn't a very good solution, as
+ # it can frequently miss stuff, but it's good enough for most users.
+ #
+ eval {
+ my $dummy;
+ if (exists($uciinfo{'pv'})) {
+ $dummy = prettyprint_pv($pos_calculating->{'board'}, @{$uciinfo{'pv'}});
+ }
+
+ my $mpv = 1;
+ while (exists($uciinfo{'pv' . $mpv})) {
+ $dummy = prettyprint_pv($pos_calculating->{'board'}, @{$uciinfo{'pv' . $mpv}});
+ ++$mpv;
+ }
+ };
+ if ($@) {
+ %uciinfo = ();
+ return;
+ }
+
+ my $text = '';
+
+ if (exists($uciid{'name'})) {
+ $text .= "Analysis by $uciid{'name'}:\n\n";
+ } else {
+ $text .= "Analysis:\n\n";
+ }
+
+ return unless (exists($pos_calculating->{'board'}));
+
+ #
+ # Some programs _always_ report MultiPV, even with only one PV.
+ # In this case, we simply use that data as if MultiPV was never
+ # specified.
+ #
+ if (exists($uciinfo{'pv1'}) && !exists($uciinfo{'pv2'})) {
+ for my $key qw(pv score_cp score_mate nodes nps depth seldepth tbhits) {
+ if (exists($uciinfo{$key . '1'}) && !exists($uciinfo{$key})) {
+ $uciinfo{$key} = $uciinfo{$key . '1'};
+ }
+ }
+ }
+
+ if (exists($uciinfo{'pv1'}) && exists($uciinfo{'pv2'})) {
+ # multi-PV
+ my $mpv = 1;
+ while (exists($uciinfo{'pv' . $mpv})) {
+ $text .= sprintf " PV%2u", $mpv;
+ my $score = short_score(\%uciinfo, $pos_calculating, $mpv);
+ $text .= " ($score)" if (defined($score));
+
+ my $tbhits = '';
+ if (exists($uciinfo{'tbhits' . $mpv})) {
+ $tbhits = sprintf ", %u tbhits", $uciinfo{'tbhits' . $mpv};
+ }
+
+ if (exists($uciinfo{'nodes' . $mpv}) && exists($uciinfo{'nps' . $mpv}) && exists($uciinfo{'depth' . $mpv})) {
+ $text .= sprintf " (%5u kn, %3u kn/s, %2u ply$tbhits)",
+ $uciinfo{'nodes' . $mpv} / 1000, $uciinfo{'nps' . $mpv} / 1000, $uciinfo{'depth' . $mpv};
+ }