diff --git a/src/components/Tutor.tsx b/src/components/Tutor.tsx index 033dfbf..c32a0db 100644 --- a/src/components/Tutor.tsx +++ b/src/components/Tutor.tsx @@ -239,11 +239,22 @@ IMPORTANT CONTEXT: } // Get FEN before user's move (need to undo both moves) - const tempGame = new Chess(currentFen); - tempGame.undo(); // Undo computer move - const fenAfterUserMove = tempGame.fen(); - tempGame.undo(); // Undo user move - const fenBeforeUserMove = tempGame.fen(); + // We need to use the game object which has the full move history + const history = game.history({ verbose: true }); + + // Current position is after both user and computer moves + // To get FEN after user move, we need to undo the computer move + const tempGame1 = new Chess(); + tempGame1.loadPgn(game.pgn()); + tempGame1.undo(); // Undo computer move + const fenAfterUserMove = tempGame1.fen(); + + // To get FEN before user move, we need to undo both moves + const tempGame2 = new Chess(); + tempGame2.loadPgn(game.pgn()); + tempGame2.undo(); // Undo computer move + tempGame2.undo(); // Undo user move + const fenBeforeUserMove = tempGame2.fen(); const prompt = ` [SYSTEM TRIGGER: move_exchange]