@@ -22,12 +22,13 @@ export const useBoardDescription = (
2222
2323 const fen = currentNode . fen
2424 const whiteToMove = currentNode . turn === 'w'
25+ const selectedMaiaEvaluation = moveEvaluation . maia
2526
2627 const stockfishEvals = moveEvaluation . stockfish . cp_vec
2728 const maiaEvals : Record < string , number [ ] > = { }
2829 const allMaiaAnalysis = currentNode . analysis . maia || { }
2930
30- Object . keys ( moveEvaluation . maia . policy ) . forEach ( ( move ) => {
31+ Object . keys ( selectedMaiaEvaluation . policy ) . forEach ( ( move ) => {
3132 maiaEvals [ move ] = new Array ( MAIA_MODELS . length ) . fill ( 0 )
3233 } )
3334
@@ -43,11 +44,47 @@ export const useBoardDescription = (
4344 }
4445 } )
4546
47+ let selectedMaiaIndex = MAIA_MODELS . findIndex ( ( model ) => {
48+ const modelAnalysis = allMaiaAnalysis [ model ]
49+ return (
50+ modelAnalysis === selectedMaiaEvaluation ||
51+ modelAnalysis ?. policy === selectedMaiaEvaluation . policy
52+ )
53+ } )
54+
55+ if ( selectedMaiaIndex < 0 ) {
56+ let bestIndex = - 1
57+ let bestScore = - Infinity
58+ MAIA_MODELS . forEach ( ( model , index ) => {
59+ const policy = allMaiaAnalysis [ model ] ?. policy
60+ if ( ! policy ) return
61+
62+ const sharedMoves = Object . keys ( selectedMaiaEvaluation . policy ) . filter (
63+ ( move ) => policy [ move ] !== undefined ,
64+ )
65+ if ( ! sharedMoves . length ) return
66+
67+ const score = sharedMoves . reduce (
68+ ( acc , move ) =>
69+ acc -
70+ Math . abs ( ( policy [ move ] ?? 0 ) - selectedMaiaEvaluation . policy [ move ] ) ,
71+ 0 ,
72+ )
73+ if ( score > bestScore ) {
74+ bestScore = score
75+ bestIndex = index
76+ }
77+ } )
78+ selectedMaiaIndex = bestIndex
79+ }
80+
4681 const description = describePosition (
4782 fen ,
4883 stockfishEvals ,
4984 maiaEvals ,
5085 whiteToMove ,
86+ selectedMaiaEvaluation . policy ,
87+ selectedMaiaIndex >= 0 ? selectedMaiaIndex : undefined ,
5188 )
5289 return description
5390 } , [
0 commit comments