feat : add accuracy calculation

This commit is contained in:
GuillaumeSD
2024-02-28 23:29:30 +01:00
parent 43017c89ee
commit a8da159870
8 changed files with 283 additions and 677 deletions

View File

@@ -3,7 +3,11 @@ import { Game } from "@/types/game";
import { Chess } from "chess.js";
export const getFens = (game: Chess): string[] => {
return game.history({ verbose: true }).map((move) => move.before);
const history = game.history({ verbose: true });
const fens = history.map((move) => move.before);
fens.push(history[history.length - 1].after);
return fens;
};
export const getGameFromPgn = (pgn: string): Chess => {
@@ -106,3 +110,9 @@ export const getEvaluationBarValue = (
return { whiteBarPercentage, label: pEval.toFixed(1) };
};
export const getWhoIsCheckmated = (fen: string): "w" | "b" | null => {
const game = new Chess(fen);
if (!game.isCheckmate()) return null;
return game.turn();
};