X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fopening-stats.pl;h=0da6e0546f54e1b20382c0d39787cd9292c35df0;hb=74f1261e4067cbc1b743b329ed2d419aee735cbf;hp=696bfa147c2d5e2017bc8ff8737231e4828e2b54;hpb=804c3f70dfd6575f18763df88d475e5190d97d3c;p=remoteglot-book diff --git a/www/opening-stats.pl b/www/opening-stats.pl index 696bfa1..0da6e05 100755 --- a/www/opening-stats.pl +++ b/www/opening-stats.pl @@ -50,24 +50,47 @@ eval { }; # Explore one move out. +my $white_left = $json_root_pos->{'white'}; +my $draw_left = $json_root_pos->{'draw'}; +my $black_left = $json_root_pos->{'black'}; for my $move (@{$root_aux_data->{'moves'}}) { my ($np, $uci_move) = $pos->make_pretty_move($move); my $json_pos; + + my ($json_pos_only_this_root, undef) = get_json_move($np, $root_aux_data->{'pos_hash'}, $chld_in, $chld_out); + $white_left -= $json_pos_only_this_root->{'white'}; + $draw_left -= $json_pos_only_this_root->{'draw'}; + $black_left -= $json_pos_only_this_root->{'black'}; + 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)) { + if (!defined($json_pos_only_this_root)) { $json_pos->{'transpose_only'} = 1; } } else { - ($json_pos, undef) = get_json_move($np, $root_aux_data->{'pos_hash'}, $chld_in, $chld_out); + $json_pos = $json_pos_only_this_root; } $json_pos->{'move'} = $move; push @json_moves, $json_pos; } +# If there are any positions that are not accounted for by any moves, +# these have to be games that end here. Add them as pseudo-moves so as +# not to confuse the user. +for my $result (['1-0', 'white', $white_left], ['1/2-1/2', 'draw', $draw_left], ['0-1', 'black', $black_left]) { + next if ($result->[2] == 0); + my $move = { + move => $result->[0], + white => 0, + draw => 0, + black => 0 + }; + $move->{$result->[1]} = $result->[2]; + push @json_moves, $move; +} + # Get stats for the root position, for the human index. my $start_pos = Position->start_pos("white", "black"); my ($json_start_pos, undef) = get_json_move($start_pos, 0, $chld_in, $chld_out);