+ #
+ # 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($ficsinfo{'board'}, @{$uciinfo{'pv'}});
+ }
+
+ my $mpv = 1;
+ while (exists($uciinfo{'pv' . $mpv})) {
+ $dummy = prettyprint_pv($ficsinfo{'board'}, @{$uciinfo{'pv' . $mpv}});
+ ++$mpv;
+ }
+ };
+ if ($@) {
+ return;
+ }
+
+ print "\e[H\e[2JAnalysis:\n\n";
+
+ return unless (exists($ficsinfo{'board'}));
+
+ if (exists($uciinfo{'pv1'})) {
+ # multi-PV
+ my $mpv = 1;
+ while (exists($uciinfo{'pv' . $mpv})) {
+ printf " PV%2u", $mpv;
+
+ if (defined($uciinfo{'score_mate' . $mpv})) {
+ printf " (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;
+ }
+ printf " (%+5.2f)", $score;
+ }
+ }
+
+ if (exists($uciinfo{'nodes' . $mpv}) && exists($uciinfo{'nps' . $mpv}) && exists($uciinfo{'depth' . $mpv})) {
+ printf " (%5u kn, %3u kn/s, %2u ply)",
+ $uciinfo{'nodes' . $mpv} / 1000, $uciinfo{'nps' . $mpv} / 1000, $uciinfo{'depth' . $mpv};
+ }
+
+ print ":\n";
+ print " ", join(', ', prettyprint_pv($ficsinfo{'board'}, @{$uciinfo{'pv' . $mpv}})), "\n";
+ print "\n";
+ ++$mpv;
+ }