From 94e890f3cafeab48d5f2af25a0105313394ba43d Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Thu, 25 Jun 2026 19:29:27 +0000 Subject: [PATCH] fix: rewinding and replaying a move now overwrites the line instead of appending doMove only truncated moves/frames on the first divergence (forkPoint===null). Subsequent rewind+move appended to the end of the line, corrupting the game state irrecoverably. Always truncate to the current point before pushing. Drop the dead forkedMoves state. --- src/chess_pressure/static/app.js | 13 +++++-------- src/chess_pressure/static/index.html | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/chess_pressure/static/app.js b/src/chess_pressure/static/app.js index 4083407..8e99230 100644 --- a/src/chess_pressure/static/app.js +++ b/src/chess_pressure/static/app.js @@ -12,7 +12,6 @@ let board = null; let forkPoint = null; // index where fork happened, null if on original line let originalData = null; // saved original game before fork - let forkedMoves = []; // UCI moves made after fork point let showPieces = true; let showBoard = false; let selectedSquare = null; // tap-to-move: currently selected source square @@ -157,16 +156,17 @@ .then((r) => r.ok ? r.json() : null) .then((data) => { if (!data) return; + // First divergence from the originally-loaded line: snapshot it so "Reset to original" works. if (forkPoint === null && currentIndex < gameData.frames.length - 1) { originalData = JSON.parse(JSON.stringify(gameData)); forkPoint = currentIndex; - gameData.moves = gameData.moves.slice(0, currentIndex); - gameData.frames = gameData.frames.slice(0, currentIndex + 1); - forkedMoves = []; } + // Always overwrite any continuation past the current point, so rewinding and + // playing a different move replaces the old line instead of appending to it. + gameData.moves = gameData.moves.slice(0, currentIndex); + gameData.frames = gameData.frames.slice(0, currentIndex + 1); gameData.moves.push({ san: data.san, uci: data.uci, ply: currentIndex + 1 }); gameData.frames.push(data.frame); - if (forkPoint !== null) forkedMoves.push(data.uci); goTo(gameData.frames.length - 1); updateForkUI(); }); @@ -318,7 +318,6 @@ gameData = originalData; originalData = null; forkPoint = null; - forkedMoves = []; goTo(0); updateForkUI(); } @@ -330,7 +329,6 @@ gameData = await r.json(); forkPoint = null; originalData = null; - forkedMoves = []; currentIndex = 0; goTo(0); updateGameInfo(); @@ -350,7 +348,6 @@ gameData = await r.json(); forkPoint = null; originalData = null; - forkedMoves = []; currentIndex = 0; goTo(0); updateGameInfo(); diff --git a/src/chess_pressure/static/index.html b/src/chess_pressure/static/index.html index d196d6f..9a75edb 100644 --- a/src/chess_pressure/static/index.html +++ b/src/chess_pressure/static/index.html @@ -4,7 +4,7 @@ Chess Pressure - + @@ -124,6 +124,6 @@ - +