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