@@ -128,9 +128,6 @@ export const useGameAnalysis = (
128128 const shouldAnalyze =
129129 ! node . analysis . stockfish ||
130130 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- )
134131
135132 if (
136133 ! analysisController . current . cancelled &&
@@ -139,9 +136,6 @@ export const useGameAnalysis = (
139136 ) {
140137 try {
141138 const chess = new Chess ( node . fen )
142- console . log (
143- `Starting Stockfish analysis for node with target depth: ${ config . targetDepth } ` ,
144- )
145139 const evaluationStream = stockfish . streamEvaluations (
146140 chess . fen ( ) ,
147141 chess . moves ( ) . length ,
@@ -160,15 +154,8 @@ export const useGameAnalysis = (
160154 node . addStockfishAnalysis ( evaluation , currentMaiaModel )
161155 setAnalysisState ( ( state ) => state + 1 )
162156
163- console . log (
164- `Received evaluation at depth ${ evaluation . depth } , target: ${ config . targetDepth } ` ,
165- )
166-
167157 // Stop when we reach target depth
168158 if ( evaluation . depth >= config . targetDepth ) {
169- console . log (
170- `Reached target depth ${ config . targetDepth } , stopping analysis` ,
171- )
172159 break
173160 }
174161 }
@@ -190,7 +177,13 @@ export const useGameAnalysis = (
190177 )
191178
192179 const startAnalysis = useCallback ( async ( ) => {
193- if ( ! gameTree || progress . isAnalyzing ) return
180+ if ( ! gameTree ) return
181+
182+ // If already analyzing, cancel the current analysis first
183+ if ( progress . isAnalyzing ) {
184+ analysisController . current . cancelled = true
185+ stockfish . stopEvaluation ( )
186+ }
194187
195188 // Reset state
196189 analysisController . current . cancelled = false
0 commit comments