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