]> git.sesse.net Git - remoteglot-book/commitdiff
Show immediate end results as moves.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Jun 2015 17:45:28 +0000 (19:45 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Jun 2015 17:54:43 +0000 (19:54 +0200)
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
www/opening-stats.pl

index 8785a3454cbb385079b99ee7b0577ee2c50c5d3a..5ee769335390fe04463ce1756b5386c161232910 100644 (file)
@@ -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) {
index 696bfa147c2d5e2017bc8ff8737231e4828e2b54..0da6e0546f54e1b20382c0d39787cd9292c35df0 100755 (executable)
@@ -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);