]> git.sesse.net Git - remoteglot-book/blobdiff - opening-stats.pl
Build with the new transposition data from pgn-extract. A lot of UI is still missing...
[remoteglot-book] / opening-stats.pl
index 963b8d6000d96d2379a46bd4a07cb59eef51ff51..24fdc99c1e31459d46c468df1f4f9469ba96af56 100755 (executable)
@@ -3,15 +3,33 @@ use strict;
 use warnings;
 use CGI;
 use JSON::XS;
-use lib '.';
+use lib '..';
 use Position;
-require 'ECO.pm';
-
-#ECO::unpersist();
+use IPC::Open2;
 
 my $cgi = CGI->new;
 my $fen = $ARGV[0];
+my ($chld_out, $chld_in);
+my $pid = IPC::Open2::open2($chld_out, $chld_in, "./binlookup", "./open.mtbl", "40");
+
+# Root position.
 my $pos = Position->from_fen($fen);
 my $hex = unpack('H*', $pos->bitpacked_fen);
-system("./binlookup", "./open.mtbl", $hex);
+print $chld_in $hex, "\n";
+
+chomp (my $line = <$chld_out>);  # Root position hash.
+print $line, "\n";
+
+chomp (my $line = <$chld_out>);  # Actual stats.
+print $line, "\n";
+my ($white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo, $timestamp, $pgn_file_number, $pgn_start_position, @moves) = split / /, $line;
 
+# Explore one move out.
+for my $move (@moves) {
+       my ($np, $uci_move) = $pos->make_pretty_move($move);
+       my $hex = unpack('H*', $np->bitpacked_fen);
+       print $chld_in $hex, "\n";
+       my $line = <$chld_out>;  # Ignore position hash.
+       $line = <$chld_out>;
+       print "$move $line";
+}