X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fopening-stats.pl;h=aea5db863bdd6139c5b47ad69d576418d911a1b4;hb=04d675c5a4a867b2c15e2ef64d5179353fd1489e;hp=28dd4436f69219e09d63d02451cc5f17073cde51;hpb=f95dfda2d14615a9816ba1abb32bd240a470e228;p=remoteglot-book diff --git a/www/opening-stats.pl b/www/opening-stats.pl index 28dd443..aea5db8 100755 --- a/www/opening-stats.pl +++ b/www/opening-stats.pl @@ -20,9 +20,9 @@ my $fen = $cgi->param('fen') // 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w K my $includetransp = $cgi->param('includetransp') // 1; my $pos = Position->from_fen($fen); -my ($json_root_pos, $root_aux_data) = get_json_move($pos, undef, $chld_in, $chld_out); # TODO: include previous hash if $includetransp == 0 -my $opening = $openings{$json_root_pos->{'opening_num'}} // 'A00: Start position'; +my ($json_root_pos, $root_aux_data) = get_json_move($pos, undef, $chld_in, $chld_out); +my $opening = $openings{$json_root_pos->{'opening_num'}} // 'A00: Start position'; my @json_moves = ($json_root_pos); my $root_game; @@ -55,6 +55,12 @@ for my $move (@{$root_aux_data->{'moves'}}) { my $json_pos; if ($includetransp) { ($json_pos, undef) = get_json_move($np, undef, $chld_in, $chld_out); + + # See if this move exists only due to transpositions. + my ($alt_json_pos, undef) = get_json_move($np, $root_aux_data->{'pos_hash'}, $chld_in, $chld_out); + if (!defined($alt_json_pos)) { + $json_pos->{'transpose_only'} = 1; + } } else { ($json_pos, undef) = get_json_move($np, $root_aux_data->{'pos_hash'}, $chld_in, $chld_out); } @@ -111,25 +117,28 @@ sub read_root_pgn { sub get_json_move { my ($pos, $filter_prev_pos_hash, $chld_in, $chld_out) = @_; - my $hex = unpack('H*', $pos->bitpacked_fen); + my $bpfen_hex = unpack('H*', $pos->bitpacked_fen); + my $prev_pos_hash_hex = ''; if (defined($filter_prev_pos_hash)) { - $hex .= unpack('H*', pack('S', $filter_prev_pos_hash)); + $prev_pos_hash_hex .= unpack('H*', pack('S', $filter_prev_pos_hash)); } - print $chld_in $hex, "\n"; + print $chld_in $bpfen_hex, "\n", $prev_pos_hash_hex, "\n"; # Read the hash of this position. chomp (my $pos_hash = <$chld_out>); chomp (my $line = <$chld_out>); if ($line eq '-') { - return ({}, {}); + warn "Missing pos '" . $pos->fen . "' " . $filter_prev_pos_hash; + return (undef, undef); } - my ($white, $draw, $black, $opening_num, $white_sum_elo, $black_sum_elo, $num_elo, $timestamp, $pgn_file_number, $pgn_start_position, @moves) = split / /, $line; + my ($white, $draw, $black, $computer, $opening_num, $white_sum_elo, $black_sum_elo, $num_elo, $timestamp, $pgn_file_number, $pgn_start_position, @moves) = split / /, $line; my $json_pos = { white => $white, draw => $draw, black => $black, + computer => $computer, white_avg_elo => $num_elo == 0 ? undef : $white_sum_elo / $num_elo, black_avg_elo => $num_elo == 0 ? undef : $black_sum_elo / $num_elo, num_elo => $num_elo,