From 0d8e7ac14236cefc92619e145d33ebc96ed4ad42 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 27 Nov 2025 10:22:03 +0100 Subject: [PATCH] fix: Always include current position (FEN) in LLM prompts - Add FEN and opening data to all user question types (best move, hint, general) - Prevents LLM from losing track of piece positions during conversation - Ensures accurate responses based on actual board state - Fixes issue where tutor would forget piece locations in general questions --- src/components/Tutor.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/components/Tutor.tsx b/src/components/Tutor.tsx index c23f5ec..85b7fe8 100644 --- a/src/components/Tutor.tsx +++ b/src/components/Tutor.tsx @@ -295,9 +295,11 @@ Even though you are their opponent, teaching them is more important than hiding User Question: ${text} Current Position Data: +- FEN: ${currentFen} - Best Move: ${evaluation?.bestMove} - Evaluation: ${evaluation?.score ?? 'N/A'} centipawns ${evaluation?.score !== undefined ? (evaluation.score > 0 ? '(White is better)' : evaluation.score < 0 ? '(Black is better)' : '(Equal)') : ''} - Mate in: ${evaluation?.mate || 'None'} +- Opening: ${openingData ? `${openingData.name} (${openingData.eco})` : 'Unknown/Midgame'} INSTRUCTIONS: - Tell them the best move clearly (e.g., "The best move is e2-e4" or "You should play Nf3") @@ -317,9 +319,11 @@ Even though you are their opponent, teaching them is more important than winning User Question: ${text} Current Position Data: +- FEN: ${currentFen} - Best Move: ${evaluation?.bestMove} - Evaluation: ${evaluation?.score ?? 'N/A'} centipawns ${evaluation?.score !== undefined ? (evaluation.score > 0 ? '(White is better)' : evaluation.score < 0 ? '(Black is better)' : '(Equal)') : ''} - Mate in: ${evaluation?.mate || 'None'} +- Opening: ${openingData ? `${openingData.name} (${openingData.eco})` : 'Unknown/Midgame'} INSTRUCTIONS: - Give a HELPFUL hint without revealing the exact move (unless they specifically ask for it) @@ -328,6 +332,24 @@ INSTRUCTIONS: - Stay in your personality style, but be HELPFUL and EDUCATIONAL - Do NOT refuse to help - teaching is your core role - Do NOT just say the move - guide them to find it themselves`; + } else { + // General question - include full position context + finalPrompt = ` +User Question: ${text} + +Current Position Context: +- FEN: ${currentFen} +- Evaluation: ${evaluation?.score ?? 'N/A'} centipawns ${evaluation?.score !== undefined ? (evaluation.score > 0 ? '(White is better)' : evaluation.score < 0 ? '(Black is better)' : '(Equal)') : ''} +- Best Move: ${evaluation?.bestMove ?? 'N/A'} +- Mate in: ${evaluation?.mate || 'None'} +- Opening: ${openingData ? `${openingData.name} (${openingData.eco})` : 'Unknown/Midgame'} + +INSTRUCTIONS: +- Answer the user's question based on the CURRENT position data above +- Use the FEN to understand exactly where all pieces are located +- Stay in character and maintain your personality +- Be helpful and educational +- Respond in ${language}`; } }