Skip to content

Commit 9455ed0

Browse files
Clean up debug logging and fix re-analysis issues
Co-authored-by: kevinjosethomas <46242684+kevinjosethomas@users.noreply.github.com>
1 parent 364a54d commit 9455ed0

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/hooks/useAnalysisController/useGameAnalysis.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/pages/analysis/[...id].tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ const Analysis: React.FC<Props> = ({
394394

395395
const handleAnalysisConfigConfirm = useCallback(
396396
(depth: number) => {
397+
// Reset any previous analysis state before starting new one
398+
controller.gameAnalysis.resetProgress()
397399
controller.gameAnalysis.setConfig({ targetDepth: depth })
398400
controller.gameAnalysis.startAnalysis()
399401
},

0 commit comments

Comments
 (0)