Output historic analysis (not used by the frontend yet).
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Nov 2014 22:24:55 +0000 (23:24 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Nov 2014 22:24:55 +0000 (23:24 +0100)
config.pm
remoteglot.pl

index 94f4ea1..182d6eb 100644 (file)
--- a/config.pm
+++ b/config.pm
@@ -8,6 +8,7 @@ our $server = "freechess.org";
 our $nick = "SesseBOT";
 our $target = "GMCarlsen";  # FICS username or HTTP to a PGN file.
 our $json_output = "/srv/analysis.sesse.net/www/analysis.json";
+our $json_history_dir = "/srv/analysis.sesse.net/www/history/";  # undef for none.
 
 our $engine_cmdline = "./stockfish";
 our %engine_config = (
index fb74e6e..9b1635c 100755 (executable)
@@ -744,6 +744,16 @@ sub output_json {
 
        my $encoded = JSON::XS::encode_json($json);
        atomic_set_contents($remoteglotconf::json_output, $encoded);
+
+       if (exists($pos_calculating->{'history'}) &&
+           defined($remoteglotconf::json_history_dir)) {
+               my $halfmove_num = scalar @{$pos_calculating->{'history'}};
+               (my $fen = $pos_calculating->fen()) =~ tr,/ ,-_,;
+               my $filename = $remoteglotconf::json_history_dir . "/move$halfmove_num-$fen.json";
+
+               # TODO: Avoid overwriting earlier analysis if it's better.
+               atomic_set_contents($filename, $encoded);
+       }
 }
 
 sub atomic_set_contents {