]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Make the JSON output filename configurable.
[remoteglot] / remoteglot.pl
index 7a498c6ac42c1b8954f6076ecbf20907e75fbee9..10dead9315e21da0d4879bc384084f35cbf5f426 100755 (executable)
@@ -105,6 +105,8 @@ EV::run;
 sub handle_uci {
        my ($engine, $line, $primary) = @_;
 
+       return if $line =~ /(upper|lower)bound/;
+
        $line =~ s/  / /g;  # Sometimes needed for Zappa Mexico
        print UCILOG localtime() . " $engine->{'tag'} <= $line\n";
        if ($line =~ /^info/) {
@@ -184,10 +186,14 @@ sub handle_pgn {
                $pgn->quick_parse_game;
                my $pos = Position->start_pos($pgn->white, $pgn->black);
                my $moves = $pgn->moves;
+               my @uci_moves = ();
                for my $move (@$moves) {
                        my ($from_row, $from_col, $to_row, $to_col, $promo) = $pos->parse_pretty_move($move);
+                       push @uci_moves, Board::move_to_uci_notation($from_row, $from_col, $to_row, $to_col, $promo);
                        $pos = $pos->make_move($from_row, $from_col, $to_row, $to_col, $promo);
                }
+               $pos->{'history'} = \@uci_moves;
+               $pos->{'pretty_history'} = $moves;
                handle_position($pos);
        }
        
@@ -296,7 +302,7 @@ sub parse_infos {
                        delete $info->{'score_cp' . $mpv};
                        delete $info->{'score_mate' . $mpv};
 
-                       while ($x[0] eq 'cp' || $x[0] eq 'mate' || $x[0] eq 'lowerbound' || $x[0] eq 'upperbound') {
+                       while ($x[0] eq 'cp' || $x[0] eq 'mate') {
                                if ($x[0] eq 'cp') {
                                        shift @x;
                                        $info->{'score_cp' . $mpv} = shift @x;
@@ -582,11 +588,11 @@ sub output_json {
        }
        $json->{'refutation_lines'} = \%refutation_lines;
 
-       open my $fh, ">/srv/analysis.sesse.net/www/analysis.json.tmp"
+       open my $fh, ">", $remoteglotconf::json_output . ".tmp"
                or return;
        print $fh JSON::XS::encode_json($json);
        close $fh;
-       rename("/srv/analysis.sesse.net/www/analysis.json.tmp", "/srv/analysis.sesse.net/www/analysis.json");
+       rename($remoteglotconf::json_output . ".tmp", $remoteglotconf::json_output);
 }
 
 sub uciprint {
@@ -629,11 +635,19 @@ sub score_sort_key {
        my ($info, $pos, $mpv, $invert) = @_;
 
        if (defined($info->{'score_mate' . $mpv})) {
-               if ($invert) {
-                       return 99999 - $info->{'score_mate' . $mpv};
+               my $mate = $info->{'score_mate' . $mpv};
+               my $score;
+               if ($mate > 0) {
+                       # Side to move mates
+                       $mate = 99999 - $mate;
                } else {
-                       return -(99999 - $info->{'score_mate' . $mpv});
+                       # Side to move is getting mated (note the double negative for $mate)
+                       $mate = -99999 - $mate;
+               }
+               if ($invert) {
+                       $score = -$score;
                }
+               return $score;
        } else {
                if (exists($info->{'score_cp' . $mpv})) {
                        my $score = $info->{'score_cp' . $mpv};