X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=remoteglot.pl;h=86c447489e2f095f8a5d7eb8a439a258ca62e693;hp=6a5778a0b96b3c321d0095b21fa92bd67d018904;hb=46280f671364dbc49270404d6c5b4c45d5ac59f7;hpb=9876a860a0ceb0d64fcf074ddecb08ac207c0aa5 diff --git a/remoteglot.pl b/remoteglot.pl index 6a5778a..86c4474 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -273,6 +273,12 @@ sub handle_pgn { warn "Error in parsing PGN from $url\n"; } else { eval { + # Skip to the right game. + while (defined($remoteglotconf::pgn_filter) && + !&$remoteglotconf::pgn_filter($pgn)) { + $pgn->read_game() or die "Out of games during filtering"; + } + $pgn->parse_game({ save_comments => 'yes' }); my $pos = Position->start_pos($pgn->white, $pgn->black); my $moves = $pgn->moves; @@ -309,7 +315,7 @@ sub handle_pgn { } }; if ($@) { - warn "Error in parsing moves from $url\n"; + warn "Error in parsing moves from $url: $@\n"; } } @@ -322,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 @@ -1003,14 +1015,20 @@ 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; } + + delete $pos->{'white_clock'}; + delete $pos->{'black_clock'}; } sub find_clock_start { @@ -1030,6 +1048,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; }