fix : set play engine elo
This commit is contained in:
@@ -7,6 +7,7 @@ export interface Props {
|
|||||||
max: number;
|
max: number;
|
||||||
label: string;
|
label: string;
|
||||||
size?: number;
|
size?: number;
|
||||||
|
marksFilter?: number;
|
||||||
step?: number;
|
step?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ export default function Slider({
|
|||||||
value,
|
value,
|
||||||
setValue,
|
setValue,
|
||||||
size,
|
size,
|
||||||
|
marksFilter,
|
||||||
step = 1,
|
step = 1,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
return (
|
return (
|
||||||
@@ -27,14 +29,22 @@ export default function Slider({
|
|||||||
size={size ?? 11}
|
size={size ?? 11}
|
||||||
>
|
>
|
||||||
<Typography id={`input-${label}`} textAlign="left" width="100%">
|
<Typography id={`input-${label}`} textAlign="left" width="100%">
|
||||||
{`${label}: ${value}`}
|
{step === 1 && marksFilter ? label : `${label}: ${value}`}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<MuiSlider
|
<MuiSlider
|
||||||
min={min}
|
min={min}
|
||||||
max={max}
|
max={max}
|
||||||
|
marks={
|
||||||
|
marksFilter
|
||||||
|
? Array.from({ length: max - min + 1 }, (_, i) => ({
|
||||||
|
value: i + min,
|
||||||
|
label: `${i + min}`,
|
||||||
|
})).filter((_, i) => i % marksFilter === 0)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
step={step}
|
step={step}
|
||||||
valueLabelDisplay="auto"
|
valueLabelDisplay="off"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(_, value) => setValue(value as number)}
|
onChange={(_, value) => setValue(value as number)}
|
||||||
aria-labelledby={`input-${label}`}
|
aria-labelledby={`input-${label}`}
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import {
|
|||||||
playIllegalMoveSound,
|
playIllegalMoveSound,
|
||||||
playSoundFromMove,
|
playSoundFromMove,
|
||||||
} from "@/lib/sounds";
|
} from "@/lib/sounds";
|
||||||
|
import { Player } from "@/types/game";
|
||||||
import { Chess, Move } from "chess.js";
|
import { Chess, Move } from "chess.js";
|
||||||
import { PrimitiveAtom, useAtom } from "jotai";
|
import { PrimitiveAtom, useAtom } from "jotai";
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
|
||||||
export interface resetGameParams {
|
export interface resetGameParams {
|
||||||
fen?: string;
|
fen?: string;
|
||||||
whiteName?: string;
|
white?: Player;
|
||||||
blackName?: string;
|
black?: Player;
|
||||||
noHeaders?: boolean;
|
noHeaders?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { EvaluateGameParams, LineEval, PositionEval } from "@/types/eval";
|
import { EvaluateGameParams, LineEval, PositionEval } from "@/types/eval";
|
||||||
import { Game } from "@/types/game";
|
import { Game, Player } from "@/types/game";
|
||||||
import { Chess, PieceSymbol, Square } from "chess.js";
|
import { Chess, PieceSymbol, Square } from "chess.js";
|
||||||
import { getPositionWinPercentage } from "./engine/helpers/winPercentage";
|
import { getPositionWinPercentage } from "./engine/helpers/winPercentage";
|
||||||
import { Color, MoveClassification } from "@/types/enums";
|
import { Color, MoveClassification } from "@/types/enums";
|
||||||
@@ -54,19 +54,22 @@ export const getGameToSave = (game: Chess, board: Chess): Chess => {
|
|||||||
|
|
||||||
export const setGameHeaders = (
|
export const setGameHeaders = (
|
||||||
game: Chess,
|
game: Chess,
|
||||||
params: { whiteName?: string; blackName?: string; resigned?: Color } = {}
|
params: { white?: Player; black?: Player; resigned?: Color } = {}
|
||||||
): Chess => {
|
): Chess => {
|
||||||
game.setHeader("Event", "Chesskit Game");
|
game.setHeader("Event", "Chesskit Game");
|
||||||
game.setHeader("Site", "Chesskit");
|
game.setHeader("Site", "Chesskit.org");
|
||||||
game.setHeader(
|
game.setHeader(
|
||||||
"Date",
|
"Date",
|
||||||
new Date().toISOString().split("T")[0].replaceAll("-", ".")
|
new Date().toISOString().split("T")[0].replaceAll("-", ".")
|
||||||
);
|
);
|
||||||
|
|
||||||
const { whiteName, blackName, resigned } = params;
|
const { white, black, resigned } = params;
|
||||||
|
|
||||||
if (whiteName) game.setHeader("White", whiteName);
|
if (white?.name) game.setHeader("White", white.name);
|
||||||
if (blackName) game.setHeader("Black", blackName);
|
if (black?.name) game.setHeader("Black", black.name);
|
||||||
|
|
||||||
|
if (white?.rating) game.setHeader("WhiteElo", `${white.rating}`);
|
||||||
|
if (black?.rating) game.setHeader("BlackElo", `${black.rating}`);
|
||||||
|
|
||||||
const whiteNameToUse = game.getHeaders().White || "White";
|
const whiteNameToUse = game.getHeaders().White || "White";
|
||||||
const blackNameToUse = game.getHeaders().Black || "Black";
|
const blackNameToUse = game.getHeaders().Black || "Black";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class UciEngine {
|
|||||||
private isReady = false;
|
private isReady = false;
|
||||||
private engineName: EngineName;
|
private engineName: EngineName;
|
||||||
private multiPv = 3;
|
private multiPv = 3;
|
||||||
private skillLevel: number | undefined = undefined;
|
private elo: number | undefined = undefined;
|
||||||
|
|
||||||
private constructor(engineName: EngineName, workers: EngineWorker[]) {
|
private constructor(engineName: EngineName, workers: EngineWorker[]) {
|
||||||
this.engineName = engineName;
|
this.engineName = engineName;
|
||||||
@@ -92,37 +92,28 @@ export class UciEngine {
|
|||||||
this.multiPv = multiPv;
|
this.multiPv = multiPv;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setLimitStrength(on: boolean) {
|
private async setElo(elo: number, initCase = false) {
|
||||||
await this.broadcastCommands(
|
|
||||||
[`setoption name UCI_LimitStrength value ${on}`, "isready"],
|
|
||||||
"readyok"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setElo(elo: number) {
|
|
||||||
await this.broadcastCommands(
|
|
||||||
[`setoption name UCI_Elo value ${elo}`, "isready"],
|
|
||||||
"readyok"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setSkillLevel(skillLevel: number, initCase = false) {
|
|
||||||
if (!initCase) {
|
if (!initCase) {
|
||||||
if (skillLevel === this.skillLevel) return;
|
if (elo === this.elo) return;
|
||||||
|
|
||||||
this.throwErrorIfNotReady();
|
this.throwErrorIfNotReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skillLevel < 0 || skillLevel > 20) {
|
if (elo < 1320 || elo > 3190) {
|
||||||
throw new Error(`Invalid SkillLevel value : ${skillLevel}`);
|
throw new Error(`Invalid Elo value : ${elo}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.broadcastCommands(
|
await this.broadcastCommands(
|
||||||
[`setoption name Skill Level value ${skillLevel}`, "isready"],
|
["setoption name UCI_LimitStrength value true", "isready"],
|
||||||
"readyok"
|
"readyok"
|
||||||
);
|
);
|
||||||
|
|
||||||
this.skillLevel = skillLevel;
|
await this.broadcastCommands(
|
||||||
|
[`setoption name UCI_Elo value ${elo}`, "isready"],
|
||||||
|
"readyok"
|
||||||
|
);
|
||||||
|
|
||||||
|
this.elo = elo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private throwErrorIfNotReady() {
|
private throwErrorIfNotReady() {
|
||||||
@@ -370,7 +361,6 @@ export class UciEngine {
|
|||||||
depth = 16
|
depth = 16
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
this.throwErrorIfNotReady();
|
this.throwErrorIfNotReady();
|
||||||
await this.setLimitStrength(true);
|
|
||||||
await this.setElo(elo);
|
await this.setElo(elo);
|
||||||
|
|
||||||
console.log(`Evaluating position: ${fen}`);
|
console.log(`Evaluating position: ${fen}`);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { useMemo } from "react";
|
|||||||
import { useScreenSize } from "@/hooks/useScreenSize";
|
import { useScreenSize } from "@/hooks/useScreenSize";
|
||||||
import { Color } from "@/types/enums";
|
import { Color } from "@/types/enums";
|
||||||
import Board from "@/components/board";
|
import Board from "@/components/board";
|
||||||
import { usePlayersData } from "@/hooks/usePlayerNames";
|
import { usePlayersData } from "@/hooks/usePlayersData";
|
||||||
|
|
||||||
export default function BoardContainer() {
|
export default function BoardContainer() {
|
||||||
const screenSize = useScreenSize();
|
const screenSize = useScreenSize();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { usePlayersData } from "@/hooks/usePlayerNames";
|
import { usePlayersData } from "@/hooks/usePlayersData";
|
||||||
import { Grid2 as Grid, Typography } from "@mui/material";
|
import { Grid2 as Grid, Typography } from "@mui/material";
|
||||||
import { gameAtom, gameEvalAtom } from "../../../states";
|
import { gameAtom, gameEvalAtom } from "../../../states";
|
||||||
import { MoveClassification } from "@/types/enums";
|
import { MoveClassification } from "@/types/enums";
|
||||||
|
|||||||
@@ -43,7 +43,11 @@ export default function LoadGame() {
|
|||||||
|
|
||||||
resetAndSetGamePgn(gameFromUrl.pgn);
|
resetAndSetGamePgn(gameFromUrl.pgn);
|
||||||
setEval(gameFromUrl.eval);
|
setEval(gameFromUrl.eval);
|
||||||
setBoardOrientation(true);
|
setBoardOrientation(
|
||||||
|
gameFromUrl.black.name === "You" && gameFromUrl.site === "Chesskit.org"
|
||||||
|
? false
|
||||||
|
: true
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
loadGame();
|
loadGame();
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ export default function EngineSettingsDialog({ open, onClose }: Props) {
|
|||||||
setValue={setMultiPv}
|
setValue={setMultiPv}
|
||||||
min={2}
|
min={2}
|
||||||
max={6}
|
max={6}
|
||||||
|
marksFilter={1}
|
||||||
size={6}
|
size={6}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { useEngine } from "@/hooks/useEngine";
|
|||||||
import { uciMoveParams } from "@/lib/chess";
|
import { uciMoveParams } from "@/lib/chess";
|
||||||
import Board from "@/components/board";
|
import Board from "@/components/board";
|
||||||
import { useGameData } from "@/hooks/useGameData";
|
import { useGameData } from "@/hooks/useGameData";
|
||||||
import { usePlayersData } from "@/hooks/usePlayerNames";
|
import { usePlayersData } from "@/hooks/usePlayersData";
|
||||||
|
|
||||||
export default function BoardContainer() {
|
export default function BoardContainer() {
|
||||||
const screenSize = useScreenSize();
|
const screenSize = useScreenSize();
|
||||||
|
|||||||
@@ -55,10 +55,16 @@ export default function GameSettingsDialog({ open, onClose }: Props) {
|
|||||||
const handleGameStart = () => {
|
const handleGameStart = () => {
|
||||||
onClose();
|
onClose();
|
||||||
resetGame({
|
resetGame({
|
||||||
whiteName:
|
white: {
|
||||||
|
name:
|
||||||
playerColor === Color.White ? "You" : engineLabel[engineName].small,
|
playerColor === Color.White ? "You" : engineLabel[engineName].small,
|
||||||
blackName:
|
rating: playerColor === Color.White ? undefined : engineElo,
|
||||||
|
},
|
||||||
|
black: {
|
||||||
|
name:
|
||||||
playerColor === Color.Black ? "You" : engineLabel[engineName].small,
|
playerColor === Color.Black ? "You" : engineLabel[engineName].small,
|
||||||
|
rating: playerColor === Color.Black ? undefined : engineElo,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
playGameStartSound();
|
playGameStartSound();
|
||||||
setIsGameInProgress(true);
|
setIsGameInProgress(true);
|
||||||
@@ -129,9 +135,10 @@ export default function GameSettingsDialog({ open, onClose }: Props) {
|
|||||||
label="Bot Elo rating"
|
label="Bot Elo rating"
|
||||||
value={engineElo}
|
value={engineElo}
|
||||||
setValue={setEngineElo}
|
setValue={setEngineElo}
|
||||||
min={100}
|
min={1320}
|
||||||
max={3200}
|
max={3190}
|
||||||
step={100}
|
step={10}
|
||||||
|
marksFilter={374}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
|
|||||||
@@ -7,6 +7,5 @@ export const gameAtom = atom(new Chess());
|
|||||||
export const gameDataAtom = atom<CurrentPosition>({});
|
export const gameDataAtom = atom<CurrentPosition>({});
|
||||||
export const playerColorAtom = atom<Color>(Color.White);
|
export const playerColorAtom = atom<Color>(Color.White);
|
||||||
export const enginePlayNameAtom = atom<EngineName>(EngineName.Stockfish17Lite);
|
export const enginePlayNameAtom = atom<EngineName>(EngineName.Stockfish17Lite);
|
||||||
export const engineSkillLevelAtom = atom<number>(1);
|
export const engineEloAtom = atom(1320);
|
||||||
export const engineEloAtom = atom<number>(1200);
|
|
||||||
export const isGameInProgressAtom = atom(false);
|
export const isGameInProgressAtom = atom(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user