]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Get rid of some cruft (pv_uci and sort_key), and rename pv_pretty/pretty_pv to just pv.
[remoteglot] / remoteglot.pl
index c8beaa463d5c58f3ae21f7b884c44257cb4d8d83..b1e37aacb43d8398caa7ccb27e9120e66770076c 100755 (executable)
@@ -309,7 +309,9 @@ sub handle_pgn {
                                push @repretty_moves, $pretty;
                                $pos = $npos;
                        }
-                       $pos->{'result'} = $pgn->result;
+                       if ($pgn->result eq '1-0' || $pgn->result eq '1/2-1/2' || $pgn->result eq '0-1') {
+                               $pos->{'result'} = $pgn->result;
+                       }
                        $pos->{'pretty_history'} = \@repretty_moves;
 
                        extract_clock($pgn, $pos);
@@ -842,9 +844,7 @@ sub output_json {
        $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'}}) ];
+       $json->{'pv'} = [ prettyprint_pv($pos_calculating, @{$info->{'pv'}}) ];
 
        my %refutation_lines = ();
        my @refutation_lines = ();
@@ -860,12 +860,11 @@ sub output_json {
                                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,
+                               $refutation_lines{$pretty_move} = {
                                        depth => $info->{'depth' . $mpv},
                                        score => score_digest($info, $pos_calculating, $mpv),
                                        pretty_move => $pretty_move,
-                                       pv_pretty => \@pretty_pv,
+                                       pv => \@pretty_pv,
                                };
                        };
                }
@@ -916,6 +915,7 @@ sub output_json {
        }
 
        # Give out a list of other games going on. (Empty is fine.)
+       # TODO: Don't bother reading our own file, the data will be stale anyway.
        if (!$historic_json_only) {
                my @games = ();
 
@@ -930,13 +930,18 @@ sub output_json {
                                my $white = $other_game_json->{'position'}{'player_w'} // die 'Missing white';
                                my $black = $other_game_json->{'position'}{'player_b'} // die 'Missing black';
 
-                               push @games, {
+                               my $game = {
                                        id => $ref->{'id'},
                                        name => "$white–$black",
                                        url => $ref->{'url'},
                                        hashurl => $ref->{'hash_url'},
-                                       score => $other_game_json->{'score'}
                                };
+                               if (defined($other_game_json->{'position'}{'result'})) {
+                                       $game->{'result'} = $other_game_json->{'position'}{'result'};
+                               } else {
+                                       $game->{'score'} = $other_game_json->{'score'};
+                               }
+                               push @games, $game;
                        };
                        if ($@) {
                                warn "Could not add external game " . $ref->{'json_path'} . ": $@";