feat : show eval
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user