]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Factor out halfmove -> move formatting into a separate JS function.
[remoteglot] / www / js / remoteglot.js
index 43b2e1ddbb7c304b2450349fbaef79e23e355d92..8df6085e9355ac55a92efc0c28ba56c65e787579 100644 (file)
@@ -692,10 +692,9 @@ var update_board = function(current_data, display_data) {
        if (display_data) {
                // Displaying some non-current position, pick out the last move
                // from the history. This will work even if the fetch failed.
-               last_move = format_move_with_number(
+               last_move = format_halfmove_with_number(
                        current_display_line.pretty_pv[current_display_move],
-                       Math.floor((current_display_move + 1) / 2) + 1,
-                       (current_display_move % 2 == 1));
+                       current_display_move + 1);
                headline += ' after ' + last_move;
        } else if (data['position']['last_move'] !== 'none') {
                last_move = format_move_with_number(
@@ -1011,6 +1010,17 @@ var format_move_with_number = function(move, move_num, white_to_play) {
        return ret;
 }
 
+/**
+ * @param {string} move
+ * @param {Number} halfmove_num
+ */
+var format_halfmove_with_number = function(move, halfmove_num) {
+       return format_move_with_number(
+               move,
+               Math.floor(halfmove_num / 2) + 1,
+               halfmove_num % 2 == 0);
+}
+
 /**
  * @param {boolean} sort_by_score
  */