From 411b072e2e31f2a1a2176b776ba0e8bd84d0123c Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 27 Nov 2025 20:06:21 +0100 Subject: [PATCH] fix: Add FEN context to move exchange analysis prompt - Include FEN before user's move, after user's move, and current position - Ensures LLM has complete position context to understand piece locations - Fixes issue where LLM could 'forget where pieces are' during move analysis - Add instruction to use FEN data for piece location understanding --- src/components/Tutor.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/Tutor.tsx b/src/components/Tutor.tsx index fcc12b1..033dfbf 100644 --- a/src/components/Tutor.tsx +++ b/src/components/Tutor.tsx @@ -238,11 +238,23 @@ 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(); + const prompt = ` [SYSTEM TRIGGER: move_exchange] User (${playerColorName}) Move: ${userMove.san} My (${tutorColorName}) Reply: ${computerMove.san} +Position Context: +- FEN before user's move: ${fenBeforeUserMove} +- FEN after user's move: ${fenAfterUserMove} +- FEN after my reply (current position): ${currentFen} + My Internal Thoughts (Data): - Pre-Eval (Before User Move): ${preScore} cp - Post-Eval (After My Reply): ${postScore} cp @@ -255,7 +267,8 @@ INSTRUCTIONS: 1. ${evalInstruction} 2. ${openingInstruction} 3. ${tacticalInstruction ? 'If tactical opportunities were missed (see above), explain them in your style.' : ''} -4. Respond in ${language}. +4. Use the FEN data above to understand exactly where all pieces are located on the board. +5. Respond in ${language}. React to this exchange as the player. `;