X-Git-Url: https://git.sesse.net/?p=remoteglot-book;a=blobdiff_plain;f=opening-stats.pl;h=27cdee0a257de70d5a48e27a061204dfb1e7bfa2;hp=f8dd56d502def8bc835b870c507cf9f52afa189e;hb=b94d3db60ee33f550078c313560af3718d304ee6;hpb=6b7db3523af062ebb020b53592cf6ad0e128131c diff --git a/opening-stats.pl b/opening-stats.pl index f8dd56d..27cdee0 100755 --- a/opening-stats.pl +++ b/opening-stats.pl @@ -5,13 +5,29 @@ use CGI; use JSON::XS; use lib '..'; use Position; -use ECO; - -#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"; +my $line = <$chld_out>; + +print $line; +chomp $line; + +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>; + print "$move $line"; +}