fix : engine parallel workers

This commit is contained in:
GuillaumeSD
2025-04-20 03:49:15 +02:00
parent 61c90b9c6b
commit 3e9523c49f
12 changed files with 137 additions and 108 deletions

View File

@@ -17,7 +17,7 @@ import { getMovesClassification } from "@/lib/engine/helpers/moveClassification"
export const useCurrentPosition = (engineName?: EngineName) => {
const [currentPosition, setCurrentPosition] = useAtom(currentPositionAtom);
const engine = useEngine(engineName);
const engine = useEngine(engineName, 1);
const gameEval = useAtomValue(gameEvalAtom);
const game = useAtomValue(gameAtom);
const board = useAtomValue(boardAtom);
@@ -52,7 +52,7 @@ export const useCurrentPosition = (engineName?: EngineName) => {
if (
!position.eval &&
engine?.isReady() &&
engine?.getIsReady() &&
engineName &&
!board.isCheckmate() &&
!board.isStalemate()
@@ -61,7 +61,7 @@ export const useCurrentPosition = (engineName?: EngineName) => {
fen: string,
setPartialEval?: (positionEval: PositionEval) => void
) => {
if (!engine?.isReady() || !engineName)
if (!engine?.getIsReady() || !engineName)
throw new Error("Engine not ready");
const savedEval = savedEvals[fen];
if (

View File

@@ -30,11 +30,15 @@ export default function AnalyzeButton() {
const setSavedEvals = useSetAtom(savedEvalsAtom);
const readyToAnalyse =
engine?.isReady() && game.history().length > 0 && !evaluationProgress;
engine?.getIsReady() && game.history().length > 0 && !evaluationProgress;
const handleAnalyze = async () => {
const params = getEvaluateGameParams(game);
if (!engine?.isReady() || params.fens.length === 0 || evaluationProgress) {
if (
!engine?.getIsReady() ||
params.fens.length === 0 ||
evaluationProgress
) {
return;
}

View File

@@ -13,7 +13,7 @@ export const showBestMoveArrowAtom = atom(true);
export const showPlayerMoveIconAtom = atom(true);
export const engineNameAtom = atom<EngineName>(EngineName.Stockfish17Lite);
export const engineDepthAtom = atom(16);
export const engineDepthAtom = atom(14);
export const engineMultiPvAtom = atom(3);
export const evaluationProgressAtom = atom(0);

View File

@@ -19,7 +19,7 @@ import { useGameData } from "@/hooks/useGameData";
export default function BoardContainer() {
const screenSize = useScreenSize();
const engineName = useAtomValue(enginePlayNameAtom);
const engine = useEngine(engineName);
const engine = useEngine(engineName, 1);
const game = useAtomValue(gameAtom);
const playerColor = useAtomValue(playerColorAtom);
const { makeMove: makeGameMove } = useChessActions(gameAtom);
@@ -32,7 +32,7 @@ export default function BoardContainer() {
useEffect(() => {
const playEngineMove = async () => {
if (
!engine?.isReady() ||
!engine?.getIsReady() ||
game.turn() === playerColor ||
isGameFinished ||
!isGameInProgress