]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Force faster updates if our last output was without a PV.
[remoteglot] / remoteglot.pl
index c574ed05a62027a76b66d2dbf70b80d03cb054e9..06549f2a53813c9969d0e960cb078cf9c32583a6 100755 (executable)
@@ -80,6 +80,11 @@ my ($pos_calculating, $pos_calculating_second_engine);
 # any analysis for it, so we're on a forced timer to do so.
 my $pos_calculating_started = undef;
 
+# If not undef, we've output this position, but without a main PV, so we're on
+# _another_ forced timer to do so.
+my $pos_pv_started = undef;
+my $last_output_had_pv = 0;
+
 setoptions($engine, \%remoteglotconf::engine_config);
 uciprint($engine, "ucinewgame");
 
@@ -408,6 +413,7 @@ sub handle_position {
                        output_json(1);
                }
                $pos_calculating_started = [Time::HiRes::gettimeofday];
+               $pos_pv_started = undef;
 
                # Ask the engine to stop; we will throw away its data until it
                # sends us "bestmove", signaling the end of it.
@@ -426,6 +432,7 @@ sub handle_position {
        uciprint($engine, "go infinite");
        $pos_calculating = $pos;
        $pos_calculating_started = [Time::HiRes::gettimeofday];
+       $pos_pv_started = undef;
 
        if (defined($engine2)) {
                if (defined($pos_calculating_second_engine)) {
@@ -648,19 +655,29 @@ sub output {
 
        return if (!defined($pos_calculating));
 
+       my $info = $engine->{'info'};
+
        # Don't update too often.
        my $wait = $remoteglotconf::update_max_interval - Time::HiRes::tv_interval($latest_update);
        if (defined($pos_calculating_started)) {
                my $new_pos_wait = $remoteglotconf::update_force_after_move - Time::HiRes::tv_interval($pos_calculating_started);
                $wait = $new_pos_wait if ($new_pos_wait < $wait);
        }
+       if (!$last_output_had_pv && has_pv($info)) {
+               if (!defined($pos_pv_started)) {
+                       $pos_pv_started = [Time::HiRes::gettimeofday];
+               }
+               # We just got initial PV, and we're in a hurry since we gave out a blank one earlier,
+               # so give us just 200ms more to increase the quality and then force a display.
+               my $new_pos_wait = $remoteglotconf::update_force_after_move - Time::HiRes::tv_interval($pos_pv_started);
+               $wait = $new_pos_wait if ($new_pos_wait < $wait);
+       }
        if ($wait > 0.0) {
                $output_timer = AnyEvent->timer(after => $wait + 0.01, cb => \&output);
                return;
        }
+       $pos_pv_started = undef;
        
-       my $info = $engine->{'info'};
-
        # We're outputting something for this position now, so the special handling
        # for new positions is off.
        undef $pos_calculating_started;
@@ -756,6 +773,14 @@ sub output {
        output_screen();
        output_json(0);
        $latest_update = [Time::HiRes::gettimeofday];
+       $last_output_had_pv = has_pv($info);
+}
+
+sub has_pv {
+       my $info = shift;
+       return 1 if (exists($info->{'pv'}) && (scalar(@{$info->{'pv'}}) > 0));
+       return 1 if (exists($info->{'pv1'}) && (scalar(@{$info->{'pv1'}}) > 0));
+       return 0;
 }
 
 sub output_screen {