From b9fd5677c24d668a989e30d30deb5fb453df81db Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 28 Dec 2023 10:10:41 +0100 Subject: [PATCH] Factor out find_halfmove_num() into its own function. --- www/js/remoteglot.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index 2a15b3e..69f0134 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -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(); -- 2.39.2