]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Deal with multipv not being the first element on the info line (e.g. for Stockfish).
[remoteglot] / remoteglot.pl
index 2ebffc89f355eda4a33acc270c58e34907e8c592..c4518fc1c8837fa61285ed6de36e901c8a4ff550 100755 (executable)
@@ -258,10 +258,19 @@ sub parse_infos {
 
        my $info = $engine->{'info'};
 
+       # Search for "multipv" first of all, since e.g. Stockfish doesn't put it first.
+       for my $i (0..$#x - 1) {
+               if ($x[$i] =~ 'multipv') {
+                       $mpv = $x[$i + 1];
+                       next;
+               }
+       }
+
        while (scalar @x > 0) {
                if ($x[0] =~ 'multipv') {
+                       # Dealt with above
+                       shift @x;
                        shift @x;
-                       $mpv = shift @x;
                        next;
                }
                if ($x[0] =~ /^(currmove|currmovenumber|cpuload)$/) {
@@ -736,6 +745,9 @@ sub output_screen {
                        $text .= sprintf "  %u nodes, %7u nodes/sec, depth %u ply",
                                $info->{'nodes'}, $info->{'nps'}, $info->{'depth'};
                }
+               if (exists($info->{'seldepth'})) {
+                       $text .= sprintf " (%u selective)", $info->{'seldepth'};
+               }
                if (exists($info->{'tbhits'}) && $info->{'tbhits'} > 0) {
                        if ($info->{'tbhits'} == 1) {
                                $text .= ", one Nalimov hit";
@@ -743,9 +755,6 @@ sub output_screen {
                                $text .= sprintf ", %u Nalimov hits", $info->{'tbhits'};
                        }
                }
-               if (exists($info->{'seldepth'})) {
-                       $text .= sprintf " (%u selective)", $info->{'seldepth'};
-               }
                $text .= "\n\n";
        }
 
@@ -1130,11 +1139,6 @@ sub short_score {
 sub score_sort_key {
        my ($info, $pos, $mpv, $invert) = @_;
 
-       $invert //= 0;
-       if ($pos->{'toplay'} eq 'B') {
-               $invert = !$invert;
-       }
-
        if (defined($info->{'score_mate' . $mpv})) {
                if ($invert) {
                        return -(99999 - $info->{'score_mate' . $mpv});
@@ -1144,9 +1148,6 @@ sub score_sort_key {
        } else {
                if (exists($info->{'score_cp' . $mpv})) {
                        my $score = $info->{'score_cp' . $mpv};
-                       if ($score == 0) {
-                               return " 0.00";
-                       }
                        if ($invert) {
                                $score = -$score;
                        }
@@ -1348,7 +1349,7 @@ sub give_new_move_to_second_engine {
                my $this = $refutation_moves{$move};
 
                if ($this->{'depth'} < $best->{'depth'} ||
-                   ($this->{'depth'} == $best->{'depth'} && $this->{'score_cp'} < $best->{'score_cp'})) {
+                   ($this->{'depth'} == $best->{'depth'} && score_sort_key($this, $pos, '', 1) > score_sort_key($best, $pos, '', 1))) {
                        $best_move = $move;
                        next;
                }