Skip to content

Commit fdefe6d

Browse files
fix: stockfish perspective + description not updating
1 parent ada1190 commit fdefe6d

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

src/hooks/useAnalysisController/useAnalysisController.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ export const useAnalysisController = (
112112
const boardDescription = useBoardDescription(
113113
controller.currentNode || null,
114114
moveEvaluation,
115-
blunderMeter,
116-
colorSanMapping,
117115
)
118116

119117
const move = useMemo(() => {

src/hooks/useAnalysisController/useBoardDescription.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
import { useMemo } from 'react'
2-
import {
3-
BlunderMeterResult,
4-
GameNode,
5-
MaiaEvaluation,
6-
StockfishEvaluation,
7-
} from 'src/types'
2+
import { GameNode, MaiaEvaluation, StockfishEvaluation } from 'src/types'
83
import { MAIA_MODELS } from './constants'
94
import { describePosition } from './useDescriptionGenerator'
105

11-
type ColorSanMapping = {
12-
[move: string]: {
13-
san: string
14-
color: string
15-
}
16-
}
17-
186
export const useBoardDescription = (
197
currentNode: GameNode | null,
208
moveEvaluation: {
219
maia?: MaiaEvaluation
2210
stockfish?: StockfishEvaluation
2311
} | null,
24-
blunderMeter: BlunderMeterResult,
25-
colorSanMapping: ColorSanMapping,
2612
) => {
2713
return useMemo(() => {
2814
if (
@@ -57,6 +43,18 @@ export const useBoardDescription = (
5743
}
5844
})
5945

60-
return describePosition(fen, stockfishEvals, maiaEvals, whiteToMove)
61-
}, [currentNode, moveEvaluation])
46+
const description = describePosition(
47+
fen,
48+
stockfishEvals,
49+
maiaEvals,
50+
whiteToMove,
51+
)
52+
return description
53+
}, [
54+
currentNode?.fen,
55+
currentNode?.analysis.stockfish?.depth,
56+
currentNode?.analysis.maia,
57+
moveEvaluation?.stockfish?.depth,
58+
moveEvaluation?.maia?.policy,
59+
])
6260
}

src/hooks/useAnalysisController/useDescriptionGenerator.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function describePosition(
6969
fen: string,
7070
sf: StockfishEvals,
7171
maia: MaiaEvals,
72+
whiteToMove: boolean,
7273
): string {
7374
/* ---------- board ---------- */
7475
const chess = new Chess(fen)
@@ -80,6 +81,10 @@ export function describePosition(
8081
const moves = Object.keys(sf).filter((m) => legal.has(m))
8182
if (!moves.length) return 'No legal moves available.'
8283

84+
if (!whiteToMove) {
85+
sf = Object.fromEntries(Object.entries(sf).map(([m, v]) => [m, -v]))
86+
}
87+
8388
/* ---------- evals (side-to-move) ---------- */
8489
const seval: Record<string, number> = {}
8590
for (const m of moves) seval[m] = sf[m]
@@ -266,9 +271,12 @@ export function describePosition(
266271

267272
/* ---------- assemble ---------- */
268273
const moveList = bestHarder ? listWithoutOpt : listWithOpt
269-
return nGood === 1
270-
? `There ${verb} ${abundance} (${moveList}) ${outcome}, and ${pron} ${phrSet}.${tail}`
271-
: bestHarder
272-
? `There ${verb} ${abundance} (${moveList}) ${outcome}, and ${pron} ${phrSet}, but the best move (${bestMoveSan}) is ${phrBest}.${tail}`
273-
: `There ${verb} ${abundance} (${moveList}) ${outcome}, and ${pron} ${phrSet}.${tail}`
274+
const result =
275+
nGood === 1
276+
? `There ${verb} ${abundance} (${moveList}) ${outcome}, and ${pron} ${phrSet}.${tail}`
277+
: bestHarder
278+
? `There ${verb} ${abundance} (${moveList}) ${outcome}, and ${pron} ${phrSet}, but the best move (${bestMoveSan}) is ${phrBest}.${tail}`
279+
: `There ${verb} ${abundance} (${moveList}) ${outcome}, and ${pron} ${phrSet}.${tail}`
280+
281+
return result
274282
}

0 commit comments

Comments
 (0)