From d3fea58e8e553bce782f4a0eda4cbe7c229069f4 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 27 Nov 2025 12:38:31 +0100 Subject: [PATCH] feat: Update analysis page to use multiple opening detection - Import lookupPossibleOpenings and buildMoveSequenceFromSteps - Build move sequence from steps array up to currentIndex - Lookup up to 5 possible openings per position - Update prompt to include all possible openings - Update UI to show single opening name or count of possibilities - Consistent with play page opening detection --- src/app/analysis/page.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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` + } )}