X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=remoteglot.pl;h=a94a618035eea6860c40f11afbb9fc6271436e44;hp=2a6e2a6b742ef822422556bac6c714718768e421;hb=35725006988891aae7234a39c4f7c603c8b17bd9;hpb=21f55c578f83ecbe042d0af09b79402c9005cf0d diff --git a/remoteglot.pl b/remoteglot.pl index 2a6e2a6..a94a618 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -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 @@ -990,11 +996,8 @@ sub extract_clock { # Look for extended PGN clock tags. my $tags = $pgn->tags; if (exists($tags->{'WhiteClock'}) && exists($tags->{'BlackClock'})) { - $pos->{'white_clock'} = $tags->{'WhiteClock'}; - $pos->{'black_clock'} = $tags->{'BlackClock'}; - - $pos->{'white_clock'} =~ s/\b(\d)\b/0$1/g; - $pos->{'black_clock'} =~ s/\b(\d)\b/0$1/g; + $pos->{'white_clock'} = hms_to_sec($tags->{'WhiteClock'}); + $pos->{'black_clock'} = hms_to_sec($tags->{'BlackClock'}); return; } @@ -1009,14 +1012,24 @@ 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+)/; - $pos->{'white_clock'} = $1; - $comments->{$black_key} =~ /tl=(\d+:\d+:\d+)/; - $pos->{'black_clock'} = $1; + $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'} = hms_to_sec($1); + $comments->{$black_key} =~ /(?:tl=|clk )(\d+:\d+:\d+)/; + $pos->{'black_clock'} = hms_to_sec($1); return; } + + delete $pos->{'white_clock'}; + delete $pos->{'black_clock'}; +} + +sub hms_to_sec { + my $hms = shift; + return undef if (!defined($hms)); + $hms =~ /(\d+):(\d+):(\d+)/; + return $1 * 3600 + $2 * 60 + $3; } sub find_clock_start { @@ -1036,6 +1049,7 @@ sub find_clock_start { } # TODO(sesse): Maybe we can get the number of moves somehow else for FICS games. + # The history is needed for id_for_pos. if (!exists($pos->{'pretty_history'})) { return; } @@ -1057,8 +1071,7 @@ sub find_clock_start { # No clock information. return; } - $pos->{$key} =~ /(\d+):(\d+):(\d+)/; - my $time_left = $1 * 3600 + $2 * 60 + $3; + my $time_left = $pos->{$key}; $clock_target_for_pos{$id} = time + $time_left; if ($pos->{'toplay'} eq 'W') { $pos->{'white_clock_target'} = $clock_target_for_pos{$id};