fix: undo wrong move instead of resetting puzzle to start position

When a user makes an incorrect move in a puzzle, now only that move
is undone (like chess.com) instead of resetting the entire puzzle.
This improves usability by letting users retry from the same position
rather than having to redo all previous correct moves.
This commit is contained in:
Claude
2026-01-03 21:45:22 +00:00
parent 35ba74e5c0
commit e08cd3e4d6
+12 -8
View File
@@ -276,7 +276,10 @@ export default function TacticalPracticePage() {
} else {
errorSound.current?.play().catch(e => console.error("Audio play failed", e));
setFeedback('incorrect');
gameRef.current = new Chess(exercise.startPosition.fen);
// Undo the wrong move instead of resetting to start position
// This allows the user to try again from the same position (like chess.com)
gameRef.current.undo();
setFen(gameRef.current.fen());
// Update stats for incorrect answer
setStats(prev => ({
@@ -313,10 +316,11 @@ export default function TacticalPracticePage() {
if (!isCorrect) {
errorSound.current?.play().catch(e => console.error("Audio play failed", e));
setFeedback('incorrect');
// Reset the board to starting position
gameRef.current = new Chess(exercise.startPosition.fen);
setFen(exercise.startPosition.fen);
setCurrentMoveIndex(0);
// Undo the wrong move instead of resetting to start position
// This allows the user to try again from the same position (like chess.com)
// The currentMoveIndex stays the same since we're still waiting for the same move
gameRef.current.undo();
setFen(gameRef.current.fen());
// Update stats for incorrect answer
setStats(prev => ({
@@ -382,10 +386,10 @@ export default function TacticalPracticePage() {
};
const handleTryAgain = () => {
gameRef.current = new Chess(exercise.startPosition.fen);
setFen(exercise.startPosition.fen);
// Since we now undo the wrong move immediately when it's made,
// the board is already in the correct position (before the error).
// We just need to reset the feedback state to allow the user to try again.
setFeedback('none');
setCurrentMoveIndex(0); // Reset move sequence progress
// Don't reset userMove - keep the chat context
// The Tutor will know the user tried again because feedback changed to 'none'
};