Skip to content

Commit

Permalink
fix: errors in analysis + orientation of stockfish eval
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjosethomas committed Feb 5, 2025
1 parent 4686b38 commit 3ab6f28
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/components/Analysis/MoveRecommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const MoveRecommendations: React.FC<Props> = ({
key={index}
className="flex items-center justify-between"
style={{
color: colorSanMapping[move].color,
color: colorSanMapping[move]?.color || '#fff',
}}
>
<p
Expand Down Expand Up @@ -95,7 +95,10 @@ export const MoveRecommendations: React.FC<Props> = ({
>
{colorSanMapping[move].san}
</p>
<p className="font-mono text-sm">{cp / 100}</p>
<p className="font-mono text-sm">
{cp > 0 ? '+' : null}
{cp / 100}
</p>
</div>
))}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useAnalysisController/useAnalysisController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export const useAnalysisController = (
const board = new Chess(game.moves[controller.currentIndex].board)

;(async () => {
if (status !== 'ready' || maiaEvaluations[controller.currentIndex]) return
if (maiaStatus !== 'ready' || maiaEvaluations[controller.currentIndex])
return

const { result } = await maia.batchEvaluate(
Array(9).fill(board.fen()),
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useMaiaEngine/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ class Maia {
legalMoves,
)

console.log({
policy,
value,
})

return {
policy,
value,
Expand Down
36 changes: 23 additions & 13 deletions src/pages/analysis/[...id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,25 @@ const Analysis: React.FC<Props> = ({

if (moveEvaluation?.maia) {
const maia = Object.entries(moveEvaluation?.maia?.policy)[0]
arr.push({
brush: 'red',
orig: maia[0].slice(0, 2) as Key,
dest: maia[0].slice(2, 4) as Key,
} as DrawShape)
if (maia) {
arr.push({
brush: 'red',
orig: maia[0].slice(0, 2) as Key,
dest: maia[0].slice(2, 4) as Key,
} as DrawShape)
}
}

if (moveEvaluation?.stockfish) {
const stockfish = Object.entries(moveEvaluation?.stockfish.cp_vec)[0]
arr.push({
brush: 'blue',
orig: stockfish[0].slice(0, 2) as Key,
dest: stockfish[0].slice(2, 4) as Key,
modifiers: { lineWidth: 8 },
})
if (stockfish) {
arr.push({
brush: 'blue',
orig: stockfish[0].slice(0, 2) as Key,
dest: stockfish[0].slice(2, 4) as Key,
modifiers: { lineWidth: 8 },
})
}
}

setArrows(arr)
Expand Down Expand Up @@ -379,10 +383,16 @@ const Analysis: React.FC<Props> = ({
<div className="flex items-center justify-center">
<HorizontalEvaluationBar
min={0}
max={800}
max={1200}
value={
moveEvaluation?.stockfish
? 400 + moveEvaluation.stockfish.model_optimal_cp
? 600 +
moveEvaluation.stockfish.model_optimal_cp *
(analyzedGame.moves[
controller.currentIndex
].board.split(' ')[1] !== controller.orientation[0]
? 1
: -1)
: void 0
}
label="Stockfish Evaluation"
Expand Down

0 comments on commit 3ab6f28

Please sign in to comment.