+ if (defined($remoteglotconf::move_source)) {
+ $json->{'move_source'} = $remoteglotconf::move_source;
+ }
+ if (defined($remoteglotconf::move_source_url)) {
+ $json->{'move_source_url'} = $remoteglotconf::move_source_url;
+ }
+ $json->{'score'} = score_digest($info, $pos_calculating, '');
+ $json->{'using_lomonosov'} = defined($remoteglotconf::tb_serial_key);
+
+ $json->{'nodes'} = $info->{'nodes'};
+ $json->{'nps'} = $info->{'nps'};
+ $json->{'depth'} = $info->{'depth'};
+ $json->{'tbhits'} = $info->{'tbhits'};
+ $json->{'seldepth'} = $info->{'seldepth'};
+ $json->{'tablebase'} = $info->{'tablebase'};
+
+ $json->{'pv_uci'} = $info->{'pv'}; # Still needs to be there for the JS to calculate arrows; only for the primary PV, though!
+ $json->{'pv_pretty'} = [ prettyprint_pv($pos_calculating, @{$info->{'pv'}}) ];
+
+ my %refutation_lines = ();
+ my @refutation_lines = ();
+ if (defined($engine2)) {
+ for (my $mpv = 1; $mpv < 500; ++$mpv) {
+ my $info = $engine2->{'info'};
+ my $pretty_move = "";
+ my @pretty_pv = ();
+ last if (!exists($info->{'pv' . $mpv}));
+
+ eval {
+ complete_using_tbprobe($pos_calculating, $info, $mpv);
+ my $pv = $info->{'pv' . $mpv};
+ my $pretty_move = join('', prettyprint_pv($pos_calculating, $pv->[0]));
+ my @pretty_pv = prettyprint_pv($pos_calculating, @$pv);
+ $refutation_lines{$pv->[0]} = {
+ sort_key => $pretty_move,
+ depth => $info->{'depth' . $mpv},
+ score => score_digest($info, $pos_calculating, $mpv),
+ pretty_move => $pretty_move,
+ pv_pretty => \@pretty_pv,
+ };
+ };
+ }
+ }
+ $json->{'refutation_lines'} = \%refutation_lines;
+
+ # Piece together historic score information, to the degree we have it.
+ if (!$historic_json_only && exists($pos_calculating->{'pretty_history'})) {
+ my %score_history = ();
+
+ my $q = $dbh->prepare('SELECT * FROM scores WHERE id=?');
+ my $pos = Position->start_pos('white', 'black');
+ my $halfmove_num = 0;
+ for my $move (@{$pos_calculating->{'pretty_history'}}) {
+ my $id = id_for_pos($pos, $halfmove_num);
+ my $ref = $dbh->selectrow_hashref($q, undef, $id);
+ if (defined($ref)) {
+ $score_history{$halfmove_num} = [
+ $ref->{'score_type'},
+ $ref->{'score_value'}
+ ];
+ }
+ ++$halfmove_num;
+ ($pos) = $pos->make_pretty_move($move);
+ }
+ $q->finish;
+
+ # If at any point we are missing 10 consecutive moves,
+ # truncate the history there. This is so we don't get into
+ # a situation where we e.g. start analyzing at move 45,
+ # but we have analysis for 1. e4 from some completely different game
+ # and thus show a huge hole.
+ my $consecutive_missing = 0;
+ my $truncate_until = 0;
+ for (my $i = $halfmove_num; $i --> 0; ) {
+ if ($consecutive_missing >= 10) {
+ delete $score_history{$i};
+ next;
+ }
+ if (exists($score_history{$i})) {
+ $consecutive_missing = 0;
+ } else {
+ ++$consecutive_missing;
+ }
+ }