-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathengineSettingsDialog.tsx
More file actions
267 lines (253 loc) · 8.13 KB
/
engineSettingsDialog.tsx
File metadata and controls
267 lines (253 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import Slider from "@/components/slider";
import { EngineName, SoundTheme } from "@/types/enums";
import {
MenuItem,
Select,
Button,
Dialog,
DialogTitle,
DialogContent,
FormControl,
InputLabel,
OutlinedInput,
DialogActions,
Typography,
Grid2 as Grid,
Box,
useTheme,
} from "@mui/material";
import {
engineNameAtom,
engineDepthAtom,
engineMultiPvAtom,
engineWorkersNbAtom,
} from "../analysis/states";
import ArrowOptions from "./arrowOptions";
import { useAtomLocalStorage } from "@/hooks/useAtomLocalStorage";
import { useEffect } from "react";
import { isEngineSupported } from "@/lib/engine/shared";
import { Stockfish16_1 } from "@/lib/engine/stockfish16_1";
import { useAtom } from "jotai";
import { boardHueAtom, pieceSetAtom } from "@/components/board/states";
import Image from "next/image";
import {
DEFAULT_ENGINE,
ENGINE_LABELS,
PIECE_SETS,
STRONGEST_ENGINE,
} from "@/constants";
import { getRecommendedWorkersNb } from "@/lib/engine/worker";
import { soundThemeAtom } from "../play/states";
interface Props {
open: boolean;
onClose: () => void;
}
export default function EngineSettingsDialog({ open, onClose }: Props) {
const [depth, setDepth] = useAtomLocalStorage(
"engine-depth",
engineDepthAtom
);
const [multiPv, setMultiPv] = useAtomLocalStorage(
"engine-multi-pv",
engineMultiPvAtom
);
const [engineName, setEngineName] = useAtomLocalStorage(
"engine-name",
engineNameAtom
);
const [boardHue, setBoardHue] = useAtom(boardHueAtom);
const [pieceSet, setPieceSet] = useAtom(pieceSetAtom);
const [engineWorkersNb, setEngineWorkersNb] = useAtom(engineWorkersNbAtom);
const theme = useTheme();
const isDarkMode = theme.palette.mode === "dark";
const [soundTheme, setSoundTheme] = useAtomLocalStorage(
"sound-theme",
soundThemeAtom
);
useEffect(() => {
if (!isEngineSupported(engineName)) {
if (Stockfish16_1.isSupported()) {
setEngineName(EngineName.Stockfish16_1Lite);
} else {
setEngineName(EngineName.Stockfish11);
}
}
}, [setEngineName, engineName]);
return (
<Dialog open={open} onClose={onClose} maxWidth="md" fullWidth>
<DialogTitle variant="h5" sx={{ paddingBottom: 1 }}>
Settings
</DialogTitle>
<DialogContent sx={{ paddingBottom: 0 }}>
<Grid
container
justifyContent="center"
alignItems="center"
paddingTop={1}
spacing={3}
size={12}
>
<Grid
container
justifyContent="center"
size={{ xs: 12, sm: 7, md: 8 }}
>
<Typography variant="body2">
{ENGINE_LABELS[DEFAULT_ENGINE].small} is the default engine if
your device support its requirements. It offers the best balance
between speed and strength.{" "}
{ENGINE_LABELS[STRONGEST_ENGINE].small} is the strongest engine
available, note that it requires a one time download of{" "}
{ENGINE_LABELS[STRONGEST_ENGINE].sizeMb}MB and is much more
compute intensive.
</Typography>
</Grid>
<Grid
container
justifyContent="center"
size={{ xs: 12, sm: 5, md: 4 }}
>
<FormControl variant="outlined">
<InputLabel id="dialog-select-label">Engine</InputLabel>
<Select
labelId="dialog-select-label"
id="dialog-select"
displayEmpty
input={<OutlinedInput label="Engine" />}
value={engineName}
onChange={(e) => setEngineName(e.target.value as EngineName)}
sx={{ width: 280, maxWidth: "100%" }}
>
{Object.values(EngineName).map((engine) => (
<MenuItem
key={engine}
value={engine}
disabled={!isEngineSupported(engine)}
>
{ENGINE_LABELS[engine].full}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Slider
label="Maximum depth"
value={depth}
setValue={setDepth}
min={10}
max={30}
marksFilter={2}
/>
<Slider
label="Number of lines"
value={multiPv}
setValue={setMultiPv}
min={2}
max={6}
marksFilter={1}
size={6}
/>
<ArrowOptions />
<Grid
container
justifyContent="center"
size={{ xs: 12, sm: 8, md: 9 }}
>
<Slider
label="Board hue"
value={boardHue}
setValue={setBoardHue}
min={0}
max={360}
/>
</Grid>
<Grid
container
justifyContent="center"
alignItems="center"
size={{ xs: 12, sm: 4, md: 3 }}
>
<FormControl variant="outlined">
<InputLabel id="dialog-select-label">Piece set</InputLabel>
<Select
labelId="dialog-select-label"
id="dialog-select"
displayEmpty
input={<OutlinedInput label="Piece set" />}
value={pieceSet}
onChange={(e) =>
setPieceSet(e.target.value as (typeof PIECE_SETS)[number])
}
sx={{ width: 200, maxWidth: "100%" }}
>
{PIECE_SETS.map((name) => (
<MenuItem key={name} value={name}>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<Image
loading="lazy"
src={`/piece/${name}/${isDarkMode ? "w" : "b"}N.svg`}
alt={`${name} knight`}
width={24}
height={24}
/>
{name}
</Box>
</MenuItem>
))}
</Select>
</FormControl>
<FormControl variant="outlined">
<InputLabel id="sound-theme-select-label">Sound Theme</InputLabel>
<Select
labelId="sound-theme-select-label"
id="sound-theme-select"
displayEmpty
input={<OutlinedInput label="Sound Theme" />}
value={soundTheme}
onChange={(e) => setSoundTheme(e.target.value as SoundTheme)}
sx={{ width: 280, maxWidth: "100%" }}
>
{Object.values(SoundTheme).map((theme) => (
<MenuItem key={theme} value={theme}>
{theme.charAt(0).toUpperCase() + theme.slice(1)}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Grid
container
justifyContent="center"
alignItems="center"
size={{ xs: 12, md: 11 }}
>
<Slider
label="Number of threads"
value={engineWorkersNb}
setValue={setEngineWorkersNb}
min={1}
max={12}
marksFilter={1}
infoContent={
<>
More threads means faster analysis, but only if your device
can handle them, otherwise it may have the opposite effect.
The estimated optimal value for your device is{" "}
{getRecommendedWorkersNb()}. Due to privacy restrictions in
some browsers, this value might be underestimated. Don't
hesitate to try different values to find the best one for your
device.
</>
}
/>
</Grid>
</Grid>
</DialogContent>
<DialogActions sx={{ m: 1 }}>
<Button variant="contained" onClick={onClose}>
Close
</Button>
</DialogActions>
</Dialog>
);
}