]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
When a position comes in with the same position but new result, copy the result over...
[remoteglot] / remoteglot.pl
index 6d07c5bd6049d773e2da54633d215bd5b9784000..86c447489e2f095f8a5d7eb8a439a258ca62e693 100755 (executable)
@@ -328,13 +328,19 @@ sub handle_position {
        my ($pos) = @_;
        find_clock_start($pos);
                
-       # if this is already in the queue, ignore it
-       return if (defined($pos_waiting) && $pos->fen() eq $pos_waiting->fen());
+       # if this is already in the queue, ignore it (just update the result)
+       if (defined($pos_waiting) && $pos->fen() eq $pos_waiting->fen()) {
+               $pos_waiting->{'result'} = $pos->{'result'};
+               return;
+       }
 
        # if we're already chewing on this and there's nothing else in the queue,
        # also ignore it
-       return if (!defined($pos_waiting) && defined($pos_calculating) &&
-                $pos->fen() eq $pos_calculating->fen());
+       if (!defined($pos_waiting) && defined($pos_calculating) &&
+           $pos->fen() eq $pos_calculating->fen()) {
+               $pos_calculating->{'result'} = $pos->{'result'};
+               return;
+       }
 
        # if we're already thinking on something, stop and wait for the engine
        # to approve
@@ -1009,12 +1015,15 @@ sub extract_clock {
 
        if (exists($comments->{$white_key}) &&
            exists($comments->{$black_key}) &&
-           $comments->{$white_key} =~ /tl=(\d+:\d+:\d+)/ &&
-           $comments->{$black_key} =~ /tl=(\d+:\d+:\d+)/) {
-               $comments->{$white_key} =~ /tl=(\d+:\d+:\d+)/;
+           $comments->{$white_key} =~ /(?:tl=|clk )(\d+:\d+:\d+)/ &&
+           $comments->{$black_key} =~ /(?:tl=|clk )(\d+:\d+:\d+)/) {
+               $comments->{$white_key} =~ /(?:tl=|clk )(\d+:\d+:\d+)/;
                $pos->{'white_clock'} = $1;
-               $comments->{$black_key} =~ /tl=(\d+:\d+:\d+)/;
+               $comments->{$black_key} =~ /(?:tl=|clk )(\d+:\d+:\d+)/;
                $pos->{'black_clock'} = $1;
+
+               $pos->{'white_clock'} =~ s/\b(\d)\b/0$1/g;
+               $pos->{'black_clock'} =~ s/\b(\d)\b/0$1/g;
                return;
        }