@@ -32,19 +32,7 @@ export const useLegacyAnalysisController = (
32
32
) => {
33
33
const controller = useGameController ( game , initialIndex , initialOrientation )
34
34
35
- const parseStockfishEvaluation = (
36
- message : StockfishEvaluation ,
37
- moveIndex : number ,
38
- ) => {
39
- setStockfishEvaluations ( ( prev ) => {
40
- const newEvaluations = [ ...prev ]
41
- newEvaluations [ moveIndex ] = message
42
-
43
- return newEvaluations
44
- } )
45
- }
46
-
47
- const engine = useStockfishEngine ( parseStockfishEvaluation )
35
+ const { streamEvaluations, stopEvaluation } = useStockfishEngine ( )
48
36
const [ currentMove , setCurrentMove ] = useState < null | [ string , string ] > ( null )
49
37
const [ stockfishEvaluations , setStockfishEvaluations ] = useState <
50
38
StockfishEvaluation [ ]
@@ -57,15 +45,37 @@ export const useLegacyAnalysisController = (
57
45
58
46
useEffect ( ( ) => {
59
47
if ( game . type === 'tournament' ) return
60
- if ( stockfishEvaluations [ controller . currentIndex ] ?. depth == 18 ) return
61
48
62
49
const board = new Chess ( game . moves [ controller . currentIndex ] . board )
63
- engine . evaluatePosition (
50
+ if ( stockfishEvaluations [ controller . currentIndex ] ?. depth == 18 ) return
51
+
52
+ const evaluationStream = streamEvaluations (
64
53
board . fen ( ) ,
65
54
board . moves ( ) . length ,
66
- controller . currentIndex ,
67
55
)
68
- } , [ controller . currentIndex , game . moves , game . type , engine ] )
56
+
57
+ if ( evaluationStream ) {
58
+ ; ( async ( ) => {
59
+ for await ( const evaluation of evaluationStream ) {
60
+ setStockfishEvaluations ( ( prev ) => {
61
+ const newEvaluations = [ ...prev ]
62
+ newEvaluations [ controller . currentIndex ] = evaluation
63
+ return newEvaluations
64
+ } )
65
+ }
66
+ } ) ( )
67
+ }
68
+
69
+ return ( ) => {
70
+ stopEvaluation ( )
71
+ }
72
+ } , [
73
+ controller . currentIndex ,
74
+ game . moves ,
75
+ game . type ,
76
+ streamEvaluations ,
77
+ stopEvaluation ,
78
+ ] )
69
79
70
80
const moves = useMemo ( ( ) => {
71
81
const moveMap = new Map < string , string [ ] > ( )
0 commit comments