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