Skip to content

Commit

Permalink
feat: change color san mapping to base off stockfish eval instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjosethomas committed Feb 15, 2025
1 parent f8c5bc8 commit a81626d
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/hooks/useAnalysisController/useAnalysisController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,36 +138,24 @@ export const useAnalysisController = (game: AnalyzedGame) => {
const chess = new Chess(controller.currentNode.fen)
const moves = chess.moves({ verbose: true })

const stockfish = controller.currentNode.analysis.stockfish
const topMoves = stockfish ? Object.keys(stockfish.cp_vec).slice(0, 4) : []

for (const move of moves) {
let color, maiaRank, stockfishRank
const lan = move.from + move.to + (move.promotion || '')
const maia = controller.currentNode.analysis.maia?.[currentMaiaModel]
const stockfish = controller.currentNode.analysis.stockfish

if (stockfish) {
stockfishRank = Object.keys(stockfish.cp_vec).indexOf(lan) + 1

if (stockfishRank <= 4) {
color = STOCKFISH_COLORS[stockfishRank]
}
}

if (maia) {
maiaRank = Object.keys(maia.policy).indexOf(lan) + 1

if (maiaRank <= 4) {
color = MAIA_COLORS[maiaRank]
}
let color = '#FFFFFF'
const topIndex = topMoves.indexOf(lan)
if (topIndex !== -1 && topIndex < 4) {
color = STOCKFISH_COLORS[topIndex]
}

mapping[lan] = {
san: move.san,
color: color || '#FFFFFF',
color,
}
}

return mapping
}, [currentMaiaModel, controller.currentNode, analysisState])
}, [controller.currentNode, analysisState])

const moveEvaluation = useMemo(() => {
if (!controller.currentNode) return null
Expand Down

0 comments on commit a81626d

Please sign in to comment.