From 74f1261e4067cbc1b743b329ed2d419aee735cbf Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 6 Jun 2015 19:45:28 +0200 Subject: [PATCH] Show immediate end results as moves. This makes sure lines no longer stop in dead ends. It's not perfect, since we don't get the elos or computer percentages, but it's much better than nothing. --- www/js/book.js | 12 ++++++++---- www/opening-stats.pl | 29 ++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/www/js/book.js b/www/js/book.js index 8785a34..5ee7693 100644 --- a/www/js/book.js +++ b/www/js/book.js @@ -250,10 +250,14 @@ var show_lines = function(data, game) { } } - var move_a = document.createElement("a"); - move_a.href = "javascript:make_move('" + line[j] + "')"; - td.appendChild(move_a); - $(move_a).text(line[j]); + if (line[j] === '1-0' || line[j] === '1/2-1/2' || line[j] === '0-1') { + $(td).text($(td).text() + line[j]); + } else { + var move_a = document.createElement("a"); + move_a.href = "javascript:make_move('" + line[j] + "')"; + td.appendChild(move_a); + $(move_a).text(line[j]); + } } else if (headings[j][1] == TYPE_INTEGER) { add_td(tr, line[j] || 0); } else if (headings[j][1] == TYPE_FLOAT) { 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); -- 2.39.2