]> git.sesse.net Git - remoteglot/blobdiff - www/js/remoteglot.js
Factor out find_halfmove_num() into its own function.
[remoteglot] / www / js / remoteglot.js
index 2a15b3e3c22c3acb02440da019c7e1815356c753..69f0134b1d86487dad4748a121eb42810ddbf394 100644 (file)
@@ -427,6 +427,17 @@ function find_move_num(fen) {
        return parseInt(fen.split(' ')[5]);
 }
 
+/** @param {!string} fen
+ * @return {!number}
+ *
+ * Return the half-move clock, starting from 0 (and never resetting).
+ */
+function find_halfmove_num(fen) {
+       let move_num = find_move_num(fen);
+       let toplay = find_toplay(fen);
+       return (move_num - 1) * 2 + (toplay === 'w' ? 0 : 1);
+}
+
 /** @param {!number} x
  * @return {!number}
  */
@@ -734,9 +745,7 @@ function add_pv(start_fen, pv, scores, start_display_move_num, opt_limit, opt_sh
 function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
        let display_line = display_lines[line_num];
        let pv = display_line.pv;
-       let move_num = find_move_num(display_line.start_fen);
-       let toplay = find_toplay(display_line.start_fen);
-       let halfmove_num = move_num * 2 + (toplay === 'w' ? 0 : 1);  // From two, for simplicity.
+       let halfmove_num = find_halfmove_num(display_line.start_fen) + 2;  // From two, for simplicity.
 
        let ret = document.createDocumentFragment();