X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=remoteglot.pl;h=10dead9315e21da0d4879bc384084f35cbf5f426;hp=18b5b170405800be1b08112cd174cc49f042b78d;hb=352d2a6829b4144ba1ad156c08f9b3332bc73d0f;hpb=06c56e7798037c0c2e2f3bf26bd4bbe071dbb670 diff --git a/remoteglot.pl b/remoteglot.pl index 18b5b17..10dead9 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -588,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 { @@ -635,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};