Support showing the history of the game.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 9 Nov 2014 20:48:32 +0000 (21:48 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 9 Nov 2014 20:49:45 +0000 (21:49 +0100)
remoteglot.pl
www/index.html
www/js/remoteglot.js

index 7a498c6..4459015 100755 (executable)
@@ -184,10 +184,14 @@ sub handle_pgn {
                $pgn->quick_parse_game;
                my $pos = Position->start_pos($pgn->white, $pgn->black);
                my $moves = $pgn->moves;
+               my @uci_moves = ();
                for my $move (@$moves) {
                        my ($from_row, $from_col, $to_row, $to_col, $promo) = $pos->parse_pretty_move($move);
+                       push @uci_moves, Board::move_to_uci_notation($from_row, $from_col, $to_row, $to_col, $promo);
                        $pos = $pos->make_move($from_row, $from_col, $to_row, $to_col, $promo);
                }
+               $pos->{'history'} = \@uci_moves;
+               $pos->{'pretty_history'} = $moves;
                handle_position($pos);
        }
        
index 44a22fd..5468d60 100644 (file)
   <p id="score">Score:</p>
   <p><strong>PV:</strong> <span id="pv"></span></p>
   <p id="searchstats"></p>
-  <h3>Shallow search of all legal moves (multi-PV)</h3>
+  <h3>History and potential moves (multi-PV)</h3>
   <p id="sortbyscoreholder">Sort by: <span id="sortbyscore0"><a href="javascript:resort_refutation_lines(0)">Move</a></span>
     <span id="sortbyscore1"><a href="javascript:resort_refutation_lines(1)">Score</a></span>
     |
-    <span id="linemsg">Click on any move to show it on the board.</span>
+    <span id="history">No history</span>
+    |
+    <span id="linemsg">Click on any move to show it.</span>
     <span id="linenav">
       <span id="prevmove"><a href="javascript:prev_move();">Previous</a></span>,
       <span id="nextmove"><a href="javascript:next_move();">Next</a></span>,
index cb38ebe..c103716 100644 (file)
@@ -377,8 +377,9 @@ var thousands = function(x) {
  * @param {number} move_num
  * @param {!string} toplay
  * @param {number=} opt_limit
+ * @param {boolean=} opt_showlast
  */
-var print_pv = function(fen, uci_pv, pretty_pv, move_num, toplay, opt_limit) {
+var print_pv = function(fen, uci_pv, pretty_pv, move_num, toplay, opt_limit, opt_showlast) {
        display_lines.push({
                start_fen: fen,
                uci_pv: uci_pv,
@@ -387,7 +388,16 @@ var print_pv = function(fen, uci_pv, pretty_pv, move_num, toplay, opt_limit) {
 
        var pv = '';
        var i = 0;
-       if (toplay == 'B') {
+       if (opt_limit && opt_showlast) {
+               // Truncate the PV at the beginning (instead of at the end).
+               // We assume here that toplay is 'W'.
+               pv = '(…) ';
+               i = pretty_pv.length - opt_limit;
+               if (i % 2 == 1) {
+                       ++i;
+               }
+               move_num += i / 2;
+       } else if (toplay == 'B') {
                var move = "<a class=\"move\" href=\"javascript:show_line(" + (display_lines.length - 1) + ", " + 0 + ");\">" + pretty_pv[0] + "</a>";
                pv = move_num + '. … ' + move;
                toplay = 'W';
@@ -398,7 +408,7 @@ var print_pv = function(fen, uci_pv, pretty_pv, move_num, toplay, opt_limit) {
                var move = "<a class=\"move\" href=\"javascript:show_line(" + (display_lines.length - 1) + ", " + i + ");\">" + pretty_pv[i] + "</a>";
 
                if (toplay == 'W') {
-                       if (i > opt_limit) {
+                       if (i > opt_limit && !opt_showlast) {
                                return pv + ' (…)';
                        }
                        if (pv != '') {
@@ -557,6 +567,13 @@ var update_board = function(data, num_viewers) {
        }
        update_highlight();
 
+       // Print the history.
+       if (data['position']['history']) {
+               $("#history").html(print_pv('start', data['position']['history'], data['position']['pretty_history'], 1, 'W', 8, true));
+       } else {
+               $("#history").html("No history");
+       }
+
        // Print the PV.
        $("#pv").html(print_pv(data['position']['fen'], data['pv_uci'], data['pv_pretty'], data['position']['move_num'], data['position']['toplay']));
 
@@ -651,7 +668,7 @@ var show_line = function(line_num, move_num) {
 window['show_line'] = show_line;
 
 var prev_move = function() {
-       if (current_display_move > 0) {
+       if (current_display_move > -1) {
                --current_display_move;
        }
        update_displayed_line();