my $last_text = '';
my ($pos_calculating, $pos_calculating_second_engine);
-uciprint($engine, "setoption name UCI_AnalyseMode value true");
-while (my ($key, $value) = each %remoteglotconf::engine_config) {
- uciprint($engine, "setoption name $key value $value");
-}
+# If not undef, we've started calculating this position but haven't ever given out
+# any analysis for it, so we're on a forced timer to do so.
+my $pos_calculating_started = undef;
+
+setoptions($engine, \%remoteglotconf::engine_config);
uciprint($engine, "ucinewgame");
if (defined($engine2)) {
- uciprint($engine2, "setoption name UCI_AnalyseMode value true");
- while (my ($key, $value) = each %remoteglotconf::engine2_config) {
- uciprint($engine2, "setoption name $key value $value");
- }
+ setoptions($engine2, \%remoteglotconf::engine2_config);
uciprint($engine2, "setoption name MultiPV value 500");
uciprint($engine2, "ucinewgame");
}
# the position.)
#
# Do not output anything new to the main analysis; that's
- # going to be obsolete really soon.
+ # going to be obsolete really soon. (Exception: If we've never
+ # output anything for this move, ie., it didn't hit the 200ms
+ # limit, spit it out to the user anyway. It's probably a really
+ # fast blitz game or something, and it's good to show the moves
+ # as they come in even without great analysis.)
$pos_calculating->{'white_clock'} = $pos->{'white_clock'};
$pos_calculating->{'black_clock'} = $pos->{'black_clock'};
delete $pos_calculating->{'white_clock_target'};
delete $pos_calculating->{'black_clock_target'};
- output_json(1);
+
+ if (defined($pos_calculating_started)) {
+ output_json(0);
+ } else {
+ output_json(1);
+ }
+ $pos_calculating_started = [Time::HiRes::gettimeofday];
# Ask the engine to stop; we will throw away its data until it
# sends us "bestmove", signaling the end of it.
uciprint($engine, "position fen " . $pos->fen());
uciprint($engine, "go infinite");
$pos_calculating = $pos;
+ $pos_calculating_started = [Time::HiRes::gettimeofday];
if (defined($engine2)) {
if (defined($pos_calculating_second_engine)) {
return ();
}
- my $pv = shift @pvs;
- my ($from_row, $from_col, $to_row, $to_col, $promo) = parse_uci_move($pv);
- my ($pretty, $nb) = $board->prettyprint_move($from_row, $from_col, $to_row, $to_col, $promo);
- return ( $pretty, prettyprint_pv_no_cache($nb, @pvs) );
+ my @ret = ();
+ for my $pv (@pvs) {
+ my ($from_row, $from_col, $to_row, $to_col, $promo) = parse_uci_move($pv);
+ my ($pretty, $nb) = $board->prettyprint_move($from_row, $from_col, $to_row, $to_col, $promo);
+ push @ret, $pretty;
+ $board = $nb;
+ }
+ return @ret;
}
sub prettyprint_pv {
$pos = $pos->make_move(parse_uci_move($move));
}
- while ($pos->num_pieces() > 6 && $#pv > -1) {
+ while ($pos->num_pieces() > 7 && $#pv > -1) {
my $move = shift @pv;
push @moves, $move;
$pos = $pos->make_move(parse_uci_move($move));
}
- return if ($pos->num_pieces() > 6);
+ return if ($pos->num_pieces() > 7);
my $fen = $pos->fen();
my $pgn_text = `fathom --path=/srv/syzygy "$fen"`;
# Splice the PV from the tablebase onto what we have so far.
for my $move (@{$pgn->moves}) {
last if $move eq '#';
+ last if $move eq '1-0';
+ last if $move eq '0-1';
+ last if $move eq '1/2-1/2';
my $uci_move;
($pos, $uci_move) = $pos->make_pretty_move($move);
push @moves, $uci_move;
return if (!defined($pos_calculating));
# Don't update too often.
- my $age = Time::HiRes::tv_interval($latest_update);
- if ($age < $remoteglotconf::update_max_interval) {
- my $wait = $remoteglotconf::update_max_interval + 0.01 - $age;
- $output_timer = AnyEvent->timer(after => $wait, cb => \&output);
+ my $wait = $remoteglotconf::update_max_interval - Time::HiRes::tv_interval($latest_update);
+ my $new_pos_wait = defined($pos_calculating_started) ?
+ $remoteglotconf::update_force_after_move - Time::HiRes::tv_interval($pos_calculating_started)
+ : 10000.0;
+ $wait = $new_pos_wait if ($new_pos_wait < $wait);
+ if ($wait > 0.0) {
+ $output_timer = AnyEvent->timer(after => $wait + 0.01, cb => \&output);
return;
}
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;
+
#
# If we have tablebase data from a previous lookup, replace the
# engine data with the data from the tablebase.
my $promo = substr($move, 4, 1);
return ($from_row, $from_col, $to_row, $to_col, $promo);
}
+
+sub setoptions {
+ my ($engine, $config) = @_;
+ uciprint($engine, "setoption name UCI_AnalyseMode value true");
+ uciprint($engine, "setoption name Analysis Contempt value Off");
+ if (exists($config->{'Threads'})) { # Threads first, because clearing hash can be multithreaded then.
+ uciprint($engine, "setoption name Threads value " . $config->{'Threads'});
+ }
+ while (my ($key, $value) = each %$config) {
+ next if $key eq 'Threads';
+ uciprint($engine, "setoption name $key value $value");
+ }
+}