X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=www%2Fjs%2Fremoteglot.js;fp=www%2Fjs%2Fremoteglot.js;h=69f0134b1d86487dad4748a121eb42810ddbf394;hp=2a15b3e3c22c3acb02440da019c7e1815356c753;hb=b9fd5677c24d668a989e30d30deb5fb453df81db;hpb=f1ec5afd1d8e6d99ca439df48f3d6a8a966cbf6b 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();