@@ -22,6 +22,7 @@ export const useGameAnalysis = (
2222 gameTree : GameTree | null ,
2323 currentMaiaModel : string ,
2424 setAnalysisState : React . Dispatch < React . SetStateAction < number > > ,
25+ setCurrentNode ?: ( node : GameNode ) => void ,
2526) => {
2627 const maia = useContext ( MaiaEngineContext )
2728 const stockfish = useContext ( StockfishEngineContext )
@@ -124,17 +125,27 @@ export const useGameAnalysis = (
124125 }
125126
126127 // Analyze with Stockfish if not already at target depth
128+ const shouldAnalyze =
129+ ! node . analysis . stockfish ||
130+ node . analysis . stockfish . depth < config . targetDepth
131+ console . log (
132+ `Node analysis check - hasStockfish: ${ ! ! node . analysis . stockfish } , currentDepth: ${ node . analysis . stockfish ?. depth || 'none' } , targetDepth: ${ config . targetDepth } , shouldAnalyze: ${ shouldAnalyze } ` ,
133+ )
134+
127135 if (
128136 ! analysisController . current . cancelled &&
129137 stockfish . isReady ( ) &&
130- ( ! node . analysis . stockfish ||
131- node . analysis . stockfish . depth < config . targetDepth )
138+ shouldAnalyze
132139 ) {
133140 try {
134141 const chess = new Chess ( node . fen )
142+ console . log (
143+ `Starting Stockfish analysis for node with target depth: ${ config . targetDepth } ` ,
144+ )
135145 const evaluationStream = stockfish . streamEvaluations (
136146 chess . fen ( ) ,
137147 chess . moves ( ) . length ,
148+ config . targetDepth ,
138149 )
139150
140151 if ( evaluationStream ) {
@@ -149,8 +160,15 @@ export const useGameAnalysis = (
149160 node . addStockfishAnalysis ( evaluation , currentMaiaModel )
150161 setAnalysisState ( ( state ) => state + 1 )
151162
163+ console . log (
164+ `Received evaluation at depth ${ evaluation . depth } , target: ${ config . targetDepth } ` ,
165+ )
166+
152167 // Stop when we reach target depth
153168 if ( evaluation . depth >= config . targetDepth ) {
169+ console . log (
170+ `Reached target depth ${ config . targetDepth } , stopping analysis` ,
171+ )
154172 break
155173 }
156174 }
@@ -218,6 +236,11 @@ export const useGameAnalysis = (
218236 const node = mainLine [ i ]
219237 analysisController . current . currentNode = node
220238
239+ // Update the UI to show the current node being analyzed (live update)
240+ if ( setCurrentNode ) {
241+ setCurrentNode ( node )
242+ }
243+
221244 const moveDisplay = node . san || node . move || `Position ${ i + 1 } `
222245
223246 setProgress ( ( prev ) => ( {
@@ -238,7 +261,14 @@ export const useGameAnalysis = (
238261 } ) )
239262
240263 analysisController . current . currentNode = null
241- } , [ gameTree , progress . isAnalyzing , stockfish , maia . status , analyzeNode ] )
264+ } , [
265+ gameTree ,
266+ progress . isAnalyzing ,
267+ stockfish ,
268+ maia . status ,
269+ analyzeNode ,
270+ setCurrentNode ,
271+ ] )
242272
243273 const cancelAnalysis = useCallback ( ( ) => {
244274 analysisController . current . cancelled = true
0 commit comments