refacto : global refacto

This commit is contained in:
GuillaumeSD
2024-02-22 23:18:02 +01:00
parent 2a74b62bae
commit 2af0959e82
24 changed files with 230 additions and 190 deletions

View File

@@ -1,20 +1,22 @@
import { Game } from "@/types/game";
import { Chess } from "chess.js";
export const pgnToFens = (pgn: string): string[] => {
const game = new Chess();
game.loadPgn(pgn);
export const getFens = (game: Chess): string[] => {
return game.history({ verbose: true }).map((move) => move.before);
};
export const getGameFromPgn = (pgn: string): Omit<Game, "id"> => {
export const getGameFromPgn = (pgn: string): Chess => {
const game = new Chess();
game.loadPgn(pgn);
return game;
};
export const formatGameToDatabase = (game: Chess): Omit<Game, "id"> => {
const headers: Record<string, string | undefined> = game.header();
return {
pgn,
pgn: game.pgn(),
event: headers.Event,
site: headers.Site,
date: headers.Date,

View File

@@ -1,4 +1,4 @@
import { GameEval, LineEval, MoveEval } from "@/types/game";
import { GameEval, LineEval, MoveEval } from "@/types/eval";
export class Stockfish {
private worker: Worker;
@@ -80,7 +80,7 @@ export class Stockfish {
this.ready = true;
console.log("Game evaluated");
console.log(moves);
return { moves, whiteAccuracy: 82.34, blackAccuracy: 67.49 };
return { moves, accuracy: { white: 82.34, black: 67.49 } }; // TODO: Calculate accuracy
}
public async evaluatePosition(fen: string, depth = 16): Promise<MoveEval> {