X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=remoteglot.pl;h=c86eedee530e2a1e879e8b413aa2ceb524a1c551;hb=82620f45773509d6cb29f1df0f12bab1e3bbb63e;hp=dec440bafd4137ade2da8cedd6dd4f1c3706e1f6;hpb=467e50a8cfaf38bd84053401ce4cc652f543ca74;p=remoteglot diff --git a/remoteglot.pl b/remoteglot.pl index dec440b..c86eede 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -77,6 +77,7 @@ my $last_text = ''; my ($pos_calculating, $pos_calculating_second_engine); uciprint($engine, "setoption name UCI_AnalyseMode value true"); +uciprint($engine, "setoption name Analysis Contempt value Off"); while (my ($key, $value) = each %remoteglotconf::engine_config) { uciprint($engine, "setoption name $key value $value"); } @@ -84,6 +85,7 @@ uciprint($engine, "ucinewgame"); if (defined($engine2)) { uciprint($engine2, "setoption name UCI_AnalyseMode value true"); + uciprint($engine2, "setoption name Analysis Contempt value Off"); while (my ($key, $value) = each %remoteglotconf::engine2_config) { uciprint($engine2, "setoption name $key value $value"); } @@ -124,7 +126,7 @@ if (defined($remoteglotconf::server)) { ); } if (defined($remoteglotconf::target)) { - if ($remoteglotconf::target =~ /^https?:/) { + if ($remoteglotconf::target =~ /^(?:\/|https?:)/) { fetch_pgn($remoteglotconf::target); } elsif (defined($t)) { $t->cmd("observe $remoteglotconf::target"); @@ -248,9 +250,26 @@ sub handle_fics { # Starts periodic fetching of PGNs from the given URL. sub fetch_pgn { my ($url) = @_; - AnyEvent::HTTP::http_get($url, sub { - handle_pgn(@_, $url); - }); + if ($url =~ m#^/#) { # Local file. + eval { + local $/ = undef; + open my $fh, "<", $url + or die "$url: $!"; + my $pgn = <$fh>; + close $fh; + handle_pgn($pgn, '', $url); + }; + if ($@) { + warn "$url: $@"; + $http_timer = AnyEvent->timer(after => 1.0, cb => sub { + fetch_pgn($url); + }); + } + } else { + AnyEvent::HTTP::http_get($url, sub { + handle_pgn(@_, $url); + }); + } } my ($last_pgn_white, $last_pgn_black); @@ -290,6 +309,7 @@ sub handle_pgn { my $pos; if (exists($tags->{'FEN'})) { $pos = Position->from_fen($tags->{'FEN'}); + $pos->{'last_move'} = 'none'; $pos->{'player_w'} = $white; $pos->{'player_b'} = $black; $pos->{'start_fen'} = $tags->{'FEN'}; @@ -393,7 +413,7 @@ sub handle_position { # and per the UCI spec, we should really have sent "ucinewgame"), # but it's easier, and it works around a Stockfish repetition issue. if ($engine->{'chess960'} != $pos->{'chess960'}) { - uciprint($engine, "setoption UCI_Chess960 " . ($pos->{'chess960'} ? 'true' : 'false')); + uciprint($engine, "setoption name UCI_Chess960 value " . ($pos->{'chess960'} ? 'true' : 'false')); $engine->{'chess960'} = $pos->{'chess960'}; } uciprint($engine, "position fen " . $pos->fen()); @@ -406,7 +426,7 @@ sub handle_position { uciprint($engine2, "stop"); } if ($engine2->{'chess960'} != $pos->{'chess960'}) { - uciprint($engine2, "setoption UCI_Chess960 " . ($pos->{'chess960'} ? 'true' : 'false')); + uciprint($engine2, "setoption name UCI_Chess960 value " . ($pos->{'chess960'} ? 'true' : 'false')); $engine2->{'chess960'} = $pos->{'chess960'}; } uciprint($engine2, "position fen " . $pos->fen()); @@ -909,6 +929,7 @@ sub output_json { } else { $pos = Position->start_pos('white', 'black'); } + $pos->{'chess960'} = $pos_calculating->{'chess960'}; my $halfmove_num = 0; for my $move (@{$pos_calculating->{'history'}}) { my $id = id_for_pos($pos, $halfmove_num);