]> git.sesse.net Git - remoteglot/commitdiff
Hopefully fix sorting in the cases where the side to move is getting mated.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 13 Nov 2014 00:14:17 +0000 (01:14 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 13 Nov 2014 00:14:17 +0000 (01:14 +0100)
remoteglot.pl

index 18b5b170405800be1b08112cd174cc49f042b78d..dd913f6a6855b45263c043691a380da6514a2920 100755 (executable)
@@ -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};