]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Unbreak sorting, which was broken at some point in December.
[remoteglot] / www / js / remoteglot.js
index ceeff7b3c94de6c10ff6f013d837b414c500227f..899a26ca23b1af97cca1e27094e5f2ec9d6f545a 100644 (file)
@@ -702,7 +702,7 @@ function find_nonstupid_moves(data, margin, invert) {
                }
        }
        let toplay = find_toplay(data['position']['fen']);
                }
        }
        let toplay = find_toplay(data['position']['fen']);
-       moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], toplay, a, b) });
+       moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], invert, a, b) });
        moves.unshift(data['pv'][0]);
 
        return moves;
        moves.unshift(data['pv'][0]);
 
        return moves;
@@ -1319,7 +1319,7 @@ function update_board() {
                document.getElementById("searchstats").textContent = "";
        }
        if (admin_password !== null) {
                document.getElementById("searchstats").textContent = "";
        }
        if (admin_password !== null) {
-               document.getElementById("searchstats").innerHTML += " | <span style=\"color: red;\">ADMIN MODE (if password is right)</span>";
+               document.getElementById("searchstats").innerHTML += " | <span style=\"color: red;\">ADMIN MODE (if password is right) | <a href=\"javascript:undo_move()\">Undo move</a></span>";
        }
 
        // Update the board itself.
        }
 
        // Update the board itself.
@@ -2258,6 +2258,29 @@ function send_chosen_move(fen, move) {
        }
 }
 
        }
 }
 
+function undo_move() {
+       if (admin_password !== null) {
+               let history = current_analysis_data['position']['history'];
+               history = history.slice(0, history.length - 1);
+
+               let position = current_analysis_data['position']['start_fen'];
+               let hiddenboard = chess_from(position, history, history.length);
+               let fen = hiddenboard.fen();
+
+               let url = '/manual-override.pl';
+               url += '?fen=' + encodeURIComponent(fen);
+               url += '&history=' + encodeURIComponent(JSON.stringify(history));
+               url += '&move=null';
+               url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']);
+               url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']);
+               url += '&password=' + encodeURIComponent(admin_password);
+
+               console.log(fen, history);
+               fetch(url);  // Ignore the result.
+       }
+}
+window['undo_move'] = undo_move;
+
 function onSnapEnd(source, target) {
        if (source === target && recommended_move !== null) {
                source = recommended_move.from;
 function onSnapEnd(source, target) {
        if (source === target && recommended_move !== null) {
                source = recommended_move.from;
@@ -2436,7 +2459,7 @@ function compute_score_sort_key(score, depth, invert) {
        } else if (score[0] === 'cp') {
                s = score[1];
        }
        } else if (score[0] === 'cp') {
                s = score[1];
        }
-       if (s) {
+       if (s !== null) {
                if (invert) s = -s;
                return s;
        } else {
                if (invert) s = -s;
                return s;
        } else {