From: Steinar H. Gunderson Date: Thu, 13 Nov 2014 00:14:17 +0000 (+0100) Subject: Hopefully fix sorting in the cases where the side to move is getting mated. X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=f19e1618521811dad0e260ff79645d7055b1b7b7 Hopefully fix sorting in the cases where the side to move is getting mated. --- diff --git a/remoteglot.pl b/remoteglot.pl index 18b5b17..dd913f6 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -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};