Skip to content

Commit 3ab6f28

Browse files
fix: errors in analysis + orientation of stockfish eval
1 parent 4686b38 commit 3ab6f28

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

src/components/Analysis/MoveRecommendations.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const MoveRecommendations: React.FC<Props> = ({
5151
key={index}
5252
className="flex items-center justify-between"
5353
style={{
54-
color: colorSanMapping[move].color,
54+
color: colorSanMapping[move]?.color || '#fff',
5555
}}
5656
>
5757
<p
@@ -95,7 +95,10 @@ export const MoveRecommendations: React.FC<Props> = ({
9595
>
9696
{colorSanMapping[move].san}
9797
</p>
98-
<p className="font-mono text-sm">{cp / 100}</p>
98+
<p className="font-mono text-sm">
99+
{cp > 0 ? '+' : null}
100+
{cp / 100}
101+
</p>
99102
</div>
100103
))}
101104
</div>

src/hooks/useAnalysisController/useAnalysisController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export const useAnalysisController = (
6565
const board = new Chess(game.moves[controller.currentIndex].board)
6666

6767
;(async () => {
68-
if (status !== 'ready' || maiaEvaluations[controller.currentIndex]) return
68+
if (maiaStatus !== 'ready' || maiaEvaluations[controller.currentIndex])
69+
return
6970

7071
const { result } = await maia.batchEvaluate(
7172
Array(9).fill(board.fen()),

src/hooks/useMaiaEngine/model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ class Maia {
138138
legalMoves,
139139
)
140140

141+
console.log({
142+
policy,
143+
value,
144+
})
145+
141146
return {
142147
policy,
143148
value,

src/pages/analysis/[...id].tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,25 @@ const Analysis: React.FC<Props> = ({
278278

279279
if (moveEvaluation?.maia) {
280280
const maia = Object.entries(moveEvaluation?.maia?.policy)[0]
281-
arr.push({
282-
brush: 'red',
283-
orig: maia[0].slice(0, 2) as Key,
284-
dest: maia[0].slice(2, 4) as Key,
285-
} as DrawShape)
281+
if (maia) {
282+
arr.push({
283+
brush: 'red',
284+
orig: maia[0].slice(0, 2) as Key,
285+
dest: maia[0].slice(2, 4) as Key,
286+
} as DrawShape)
287+
}
286288
}
287289

288290
if (moveEvaluation?.stockfish) {
289291
const stockfish = Object.entries(moveEvaluation?.stockfish.cp_vec)[0]
290-
arr.push({
291-
brush: 'blue',
292-
orig: stockfish[0].slice(0, 2) as Key,
293-
dest: stockfish[0].slice(2, 4) as Key,
294-
modifiers: { lineWidth: 8 },
295-
})
292+
if (stockfish) {
293+
arr.push({
294+
brush: 'blue',
295+
orig: stockfish[0].slice(0, 2) as Key,
296+
dest: stockfish[0].slice(2, 4) as Key,
297+
modifiers: { lineWidth: 8 },
298+
})
299+
}
296300
}
297301

298302
setArrows(arr)
@@ -379,10 +383,16 @@ const Analysis: React.FC<Props> = ({
379383
<div className="flex items-center justify-center">
380384
<HorizontalEvaluationBar
381385
min={0}
382-
max={800}
386+
max={1200}
383387
value={
384388
moveEvaluation?.stockfish
385-
? 400 + moveEvaluation.stockfish.model_optimal_cp
389+
? 600 +
390+
moveEvaluation.stockfish.model_optimal_cp *
391+
(analyzedGame.moves[
392+
controller.currentIndex
393+
].board.split(' ')[1] !== controller.orientation[0]
394+
? 1
395+
: -1)
386396
: void 0
387397
}
388398
label="Stockfish Evaluation"

0 commit comments

Comments
 (0)