feat : show eval

This commit is contained in:
GuillaumeSD
2024-02-17 19:58:00 +01:00
parent 770ae13517
commit 98d99c0df0
10 changed files with 224 additions and 50 deletions

View File

@@ -3,29 +3,32 @@ import ReviewResult from "./reviewResult";
import SelectDepth from "./selectDepth";
import SelectGameOrigin from "./selectGame/selectGameOrigin";
import { Stockfish } from "@/lib/engine/stockfish";
import { useAtomValue } from "jotai";
import { gameFensAtom } from "./selectGame/gameOrigin.state";
import { useAtomValue, useSetAtom } from "jotai";
import { boardPgnAtom, gameEvalAtom, gamePgnAtom } from "./index.state";
import { getGameFens, initPgn } from "@/lib/chess";
export default function ReviewPanelBody() {
const [engine, setEngine] = useState<Stockfish | null>(null);
const gameFens = useAtomValue(gameFensAtom);
const setGameEval = useSetAtom(gameEvalAtom);
const setBoardPgn = useSetAtom(boardPgnAtom);
const gamePgn = useAtomValue(gamePgnAtom);
useEffect(() => {
const engine = new Stockfish();
engine.init().then(() => {
console.log("Engine initialized");
});
engine.init();
setEngine(engine);
return () => {
engine.shutdown();
console.log("Engine shutdown");
};
}, []);
const handleAnalyse = () => {
if (engine?.isReady() && gameFens) {
engine.evaluateGame(gameFens);
const handleAnalyse = async () => {
setBoardPgn(initPgn);
const gameFens = getGameFens(gamePgn);
if (engine?.isReady() && gameFens.length) {
const newGameEval = await engine.evaluateGame(gameFens);
setGameEval(newGameEval);
}
};
@@ -50,7 +53,7 @@ export default function ReviewPanelBody() {
<b id="secondary-message" className="white" />
{false && <ReviewResult />}
<ReviewResult />
</div>
);
}