fix : lint warnings & errors
This commit is contained in:
@@ -56,7 +56,7 @@ export const useCurrentMove = (engineName?: EngineName) => {
|
||||
}
|
||||
|
||||
setCurrentMove(move);
|
||||
}, [gameEval, board, game, engine, depth, multiPv]);
|
||||
}, [gameEval, board, game, engine, depth, multiPv, setCurrentMove]);
|
||||
|
||||
return currentMove;
|
||||
};
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
import { Stockfish16 } from "@/lib/engine/stockfish16";
|
||||
import { UciEngine } from "@/lib/engine/uciEngine";
|
||||
import { engineMultiPvAtom } from "@/sections/analysis/states";
|
||||
import { EngineName } from "@/types/enums";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const useEngine = (engineName: EngineName | undefined) => {
|
||||
const [engine, setEngine] = useState<UciEngine | null>(null);
|
||||
const multiPv = useAtomValue(engineMultiPvAtom);
|
||||
|
||||
const pickEngine = (engine: EngineName): UciEngine => {
|
||||
switch (engine) {
|
||||
case EngineName.Stockfish16:
|
||||
return new Stockfish16(multiPv);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!engineName) return;
|
||||
@@ -27,7 +17,14 @@ export const useEngine = (engineName: EngineName | undefined) => {
|
||||
return () => {
|
||||
engine.shutdown();
|
||||
};
|
||||
}, []);
|
||||
}, [engineName]);
|
||||
|
||||
return engine;
|
||||
};
|
||||
|
||||
const pickEngine = (engine: EngineName): UciEngine => {
|
||||
switch (engine) {
|
||||
case EngineName.Stockfish16:
|
||||
return new Stockfish16();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,14 +2,14 @@ import { EngineName } from "@/types/enums";
|
||||
import { UciEngine } from "./uciEngine";
|
||||
|
||||
export class Stockfish16 extends UciEngine {
|
||||
constructor(multiPv: number) {
|
||||
constructor() {
|
||||
const isWasmSupported = Stockfish16.isWasmSupported();
|
||||
|
||||
const enginePath = isWasmSupported
|
||||
? "engines/stockfish-wasm/stockfish-nnue-16-single.js"
|
||||
: "engines/stockfish.js";
|
||||
|
||||
super(EngineName.Stockfish16, enginePath, multiPv);
|
||||
super(EngineName.Stockfish16, enginePath);
|
||||
}
|
||||
|
||||
public static isWasmSupported() {
|
||||
|
||||
@@ -10,12 +10,10 @@ export abstract class UciEngine {
|
||||
private worker: Worker;
|
||||
private ready = false;
|
||||
private engineName: EngineName;
|
||||
private multiPv: number;
|
||||
private multiPv = 3;
|
||||
|
||||
constructor(engineName: EngineName, enginePath: string, multiPv: number) {
|
||||
constructor(engineName: EngineName, enginePath: string) {
|
||||
this.engineName = engineName;
|
||||
this.multiPv = multiPv;
|
||||
|
||||
this.worker = new Worker(enginePath);
|
||||
|
||||
console.log(`${engineName} created`);
|
||||
|
||||
@@ -32,7 +32,7 @@ export default function GameReport() {
|
||||
setBoardOrientation(true);
|
||||
gameActions.setPgn(new Chess().pgn());
|
||||
}
|
||||
}, [gameId]);
|
||||
}, [gameId, boardActions, gameActions, setEval, setBoardOrientation]);
|
||||
|
||||
return (
|
||||
<Grid
|
||||
|
||||
@@ -17,13 +17,15 @@ export default function EvaluationBar({ height }: Props) {
|
||||
const boardOrientation = useAtomValue(boardOrientationAtom);
|
||||
const currentMove = useAtomValue(currentMoveAtom);
|
||||
|
||||
const isWhiteToPlay = board.turn() === "w";
|
||||
|
||||
useEffect(() => {
|
||||
const bestLine = currentMove?.eval?.lines[0];
|
||||
if (!bestLine) return;
|
||||
|
||||
const evalBar = getEvaluationBarValue(bestLine, board.turn() === "w");
|
||||
const evalBar = getEvaluationBarValue(bestLine, isWhiteToPlay);
|
||||
setEvalBar(evalBar);
|
||||
}, [currentMove, board.turn()]);
|
||||
}, [currentMove, isWhiteToPlay]);
|
||||
|
||||
return (
|
||||
<Grid
|
||||
|
||||
Reference in New Issue
Block a user