diff --git a/src/app/analysis/page.tsx b/src/app/analysis/page.tsx index 9bb717d..58f65f4 100644 --- a/src/app/analysis/page.tsx +++ b/src/app/analysis/page.tsx @@ -12,7 +12,7 @@ import { Personality, PERSONALITIES } from "@/lib/personalities"; import { Stockfish, StockfishEvaluation } from "@/lib/stockfish"; import { detectChessFormat, ChessFormat } from "@/lib/chessFormatDetector"; import { detectMissedTactics, DetectedTactic, uciToSan } from "@/lib/tacticDetection"; -import { lookupOpening } from "@/lib/openings"; +import { lookupPossibleOpenings, buildMoveSequenceFromSteps, OpeningMetadata } from "@/lib/openings"; import { getGenAIModel } from "@/lib/gemini"; import { ChatSession } from "@google/generative-ai"; import ReactMarkdown from "react-markdown"; @@ -111,7 +111,11 @@ IMPORTANT: return steps[currentIndex - 1]?.fenAfter || initialFen; }, [currentIndex, steps, initialFen]); - const openingInfo = useMemo(() => lookupOpening(currentFen), [currentFen]); + const possibleOpenings = useMemo(() => { + if (currentIndex === 0) return []; + const moveSequence = buildMoveSequenceFromSteps(steps, currentIndex); + return lookupPossibleOpenings(moveSequence, 5); + }, [currentIndex, steps]); const handleInputChange = (value: string) => { setInput(value); @@ -268,7 +272,7 @@ DATA: - Evaluation after move: ${evalAfter.toFixed(2)} pawns - Best move suggestion: ${details.bestMoveSan ?? details.evalBefore!.bestMove} - Evaluation shift (centipawns): ${delta} -- Opening context: ${openingInfo ? `${openingInfo.name} (${openingInfo.eco})` : "Unknown"} +- Possible Openings: ${possibleOpenings.length > 0 ? possibleOpenings.map(o => `${o.name} (${o.eco})`).join(', ') : "Unknown/Midgame"} - Missed tactics: ${tactics} - Mate hint: ${mateInfo} @@ -295,7 +299,7 @@ INSTRUCTIONS: clearTimeout(timeout); setIsCommenting(false); }; - }, [chatSession, currentIndex, stepDetails, steps, comments, openingInfo]); + }, [chatSession, currentIndex, stepDetails, steps, comments, possibleOpenings]); const formatEval = (evaluation?: StockfishEvaluation) => { if (!evaluation) return t.analysis.enginePending; @@ -415,9 +419,12 @@ INSTRUCTIONS:

{t.analysis.title}

- {openingInfo && ( + {possibleOpenings.length > 0 && ( - {t.analysis.opening}: {openingInfo.name} ({openingInfo.eco}) + {t.analysis.opening}: {possibleOpenings.length === 1 + ? `${possibleOpenings[0].name} (${possibleOpenings[0].eco})` + : `${possibleOpenings.length} possible openings` + } )}