From e3abe43333d1f536f34f746889ba46428989f50e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 19 Nov 2014 23:24:55 +0100 Subject: [PATCH] Output historic analysis (not used by the frontend yet). --- config.pm | 1 + remoteglot.pl | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/config.pm b/config.pm index 94f4ea1..182d6eb 100644 --- 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 = ( diff --git a/remoteglot.pl b/remoteglot.pl index fb74e6e..9b1635c 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -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 { -- 2.39.2