Skip to content

Commit 20c54d5

Browse files
feat: added moves by rating graph and began ui changes
1 parent ea5496c commit 20c54d5

File tree

10 files changed

+502
-96
lines changed

10 files changed

+502
-96
lines changed

package-lock.json

Lines changed: 279 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"react-dom": "^18.2.0",
3232
"react-markdown": "^8.0.2",
3333
"react-tooltip": "^5.28.0",
34+
"recharts": "^2.15.0",
3435
"sass": "^1.47.0"
3536
},
3637
"devDependencies": {

src/components/Analysis/HorizontalEvaluationBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export const HorizontalEvaluationBar: React.FC<Props> = ({
1515
width = Math.max(0, Math.min(100, width))
1616

1717
return (
18-
<div className="relative flex h-6 w-[75vh] max-w-[70vw] flex-col justify-center overflow-hidden rounded-sm bg-engine-3/30">
19-
<p className="z-10 ml-2 whitespace-nowrap text-sm">{label}</p>
18+
<div className="relative flex h-6 w-[60vh] max-w-[70vw] flex-col justify-center overflow-hidden rounded-sm bg-engine-3/30">
19+
<p className="z-10 ml-2 whitespace-nowrap text-xs">{label}</p>
2020
<div
2121
className="absolute bottom-0 left-0 z-0 h-full w-full transform rounded-r-sm bg-engine-3 duration-300"
2222
style={{ width: `${width}%` }}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import {
2+
Area,
3+
AreaChart,
4+
CartesianGrid,
5+
Legend,
6+
ResponsiveContainer,
7+
XAxis,
8+
YAxis,
9+
} from 'recharts'
10+
11+
interface Props {
12+
moves: { [key: string]: number }[] | undefined
13+
}
14+
15+
export const MovesByRating: React.FC<Props> = ({ moves }: Props) => {
16+
return (
17+
<div className="col-span-2 flex h-full max-h-full flex-col rounded bg-background-1/60 pb-4">
18+
<p className="p-4 text-xl text-white">Moves by Rating</p>
19+
<div className="flex h-full w-full flex-col">
20+
<ResponsiveContainer width="100%" height="100%">
21+
<AreaChart data={moves} margin={{ left: 20, right: 0 }}>
22+
<CartesianGrid strokeDasharray="3 3" stroke="#3C3C3C" />
23+
<XAxis
24+
dataKey="rating"
25+
axisLine={false}
26+
tick={{
27+
fill: 'white',
28+
fontSize: 14,
29+
}}
30+
tickMargin={6}
31+
ticks={[1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]}
32+
/>
33+
<YAxis
34+
yAxisId="left"
35+
orientation="left"
36+
axisLine={false}
37+
domain={[0, 100]}
38+
tick={{
39+
fill: 'white',
40+
fontSize: 14,
41+
}}
42+
label={{
43+
value: 'Maia Probability',
44+
angle: -90,
45+
fill: '#ff0000',
46+
position: 'insideLeft',
47+
dy: 46,
48+
offset: 4,
49+
fontWeight: 600,
50+
fontSize: 14,
51+
}}
52+
tickCount={4}
53+
tickMargin={5}
54+
tickLine={false}
55+
tickFormatter={(value) => `${value}%`}
56+
/>
57+
<YAxis
58+
yAxisId="right"
59+
orientation="right"
60+
axisLine={false}
61+
domain={[0, 100]}
62+
tick={{
63+
fill: 'white',
64+
fontSize: 14,
65+
}}
66+
tickCount={4}
67+
tickMargin={5}
68+
tickLine={false}
69+
tickFormatter={(value) => `${value}%`}
70+
/>
71+
{moves &&
72+
Object.keys(moves[0]).map((move, i) => {
73+
if (move === 'rating') {
74+
return null
75+
}
76+
return (
77+
<Area
78+
key={i}
79+
yAxisId="left"
80+
dataKey={move}
81+
dot={{
82+
stroke: '#fff',
83+
strokeWidth: 1,
84+
}}
85+
stroke={'#fff'}
86+
fill={'#fff'}
87+
fillOpacity={0.1}
88+
strokeWidth={3}
89+
/>
90+
)
91+
})}
92+
<Legend
93+
verticalAlign="top"
94+
align="right"
95+
wrapperStyle={{ top: -14, right: 20, fontSize: 14 }}
96+
iconSize={0}
97+
/>
98+
</AreaChart>
99+
</ResponsiveContainer>
100+
</div>
101+
</div>
102+
)
103+
}

src/components/Analysis/VerticalEvaluationBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const VerticalEvaluationBar: React.FC<Props> = ({
1414
const height = ((value ?? min - min) / (max - min)) * 100
1515

1616
return (
17-
<div className="relative flex h-[75vh] max-h-[70vw] w-6 flex-col justify-end overflow-hidden rounded-sm bg-human-3/30">
18-
<p className="z-10 mb-2 -rotate-90 whitespace-nowrap text-sm">{label}</p>
17+
<div className="relative flex h-[60vh] max-h-[70vw] w-6 flex-col justify-end overflow-hidden rounded-sm bg-human-3/30">
18+
<p className="z-10 mb-3 -rotate-90 whitespace-nowrap text-xs">{label}</p>
1919
<div
2020
className="absolute bottom-0 left-0 z-0 h-full w-full transform rounded-t-sm bg-human-3 duration-300"
2121
style={{ height: `${height}%` }}

src/components/Analysis/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './AnalysisGameList'
66
export * from './HorizontalEvaluationBar'
77
export * from './PositionEvaluationContainer'
88
export * from './VerticalEvaluationBar'
9+
export * from './MovesByRating'

src/components/Board/MovesContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const MovesContainer: React.FC<Props> = ({
6060
)
6161

6262
const container = (
63-
<div className="red-scrollbar flex h-64 flex-col overflow-y-auto overflow-x-hidden whitespace-nowrap rounded-sm bg-background-1/60 md:h-full">
63+
<div className="red-scrollbar flex h-64 flex-col overflow-y-auto overflow-x-hidden whitespace-nowrap rounded-sm bg-background-1/60 md:h-full md:w-full">
6464
<Tooltip id="check" />
6565
{moves.map(([white, black], index) => {
6666
const prevMoveIndex = index * 2

src/hooks/useAnalysisController/useAnalysisController.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ export const useAnalysisController = (
7575
})
7676
}
7777

78-
console.log(moveMap)
79-
8078
return moveMap
8179
}, [controller.currentIndex, game.maiaEvaluations, maiaModels])
8280

src/hooks/useClientAnalysisController/useClientAnalysisController.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,59 @@ export const useClientAnalysisController = (
229229
}
230230
}, [moveEvaluation])
231231

232+
const movesByRating = useMemo(() => {
233+
if (
234+
!maiaEvaluations[controller.currentIndex] ||
235+
!stockfishEvaluations[controller.currentIndex]
236+
)
237+
return
238+
239+
const maia = maiaEvaluations[controller.currentIndex]
240+
const stockfish = stockfishEvaluations[controller.currentIndex]
241+
242+
const candidates: string[][] = []
243+
244+
// Get top 3 Maia moves from selected rating level
245+
for (const move of Object.keys(maia[currentMaiaModel].policy).slice(0, 3)) {
246+
if (candidates.find((c) => c[0] === move)) continue
247+
candidates.push([move, move])
248+
}
249+
250+
// Get top 3 Stockfish moves
251+
for (const move of Object.keys(stockfish.cp_vec).slice(0, 3)) {
252+
if (candidates.find((c) => c[0] === move)) continue
253+
candidates.push([move, move])
254+
}
255+
256+
// Get top Maia move from each rating level
257+
for (const rating of MAIA_MODELS) {
258+
const move = Object.keys(maia[rating].policy)[0]
259+
if (candidates.find((c) => c[0] === move)) continue
260+
candidates.push([move, move])
261+
}
262+
263+
const data = []
264+
for (const rating of MAIA_MODELS) {
265+
const entry: { [key: string]: number } = {
266+
rating: parseInt(rating.slice(-4)),
267+
}
268+
269+
for (const move of candidates) {
270+
const probability = maia[rating].policy[move[0]] * 100
271+
entry[move[1]] = probability
272+
}
273+
274+
data.push(entry)
275+
}
276+
277+
return data
278+
}, [
279+
controller.currentIndex,
280+
maiaEvaluations,
281+
stockfishEvaluations,
282+
currentMaiaModel,
283+
])
284+
232285
const move = useMemo(() => {
233286
if (
234287
currentMove &&
@@ -253,6 +306,7 @@ export const useClientAnalysisController = (
253306
currentMove,
254307
setCurrentMove,
255308
moveEvaluation,
309+
movesByRating,
256310
blunderMeter,
257311
stockfishEvaluations,
258312
maiaEvaluations,

0 commit comments

Comments
 (0)