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}
*/
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();