feat : add games database

This commit is contained in:
GuillaumeSD
2024-02-22 00:26:07 +01:00
parent 4502651492
commit 2a74b62bae
16 changed files with 450 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
import { Game } from "@/types/game";
import { Chess } from "chess.js";
export const pgnToFens = (pgn: string): string[] => {
@@ -5,3 +6,21 @@ export const pgnToFens = (pgn: string): string[] => {
game.loadPgn(pgn);
return game.history({ verbose: true }).map((move) => move.before);
};
export const getGameFromPgn = (pgn: string): Omit<Game, "id"> => {
const game = new Chess();
game.loadPgn(pgn);
const headers: Record<string, string | undefined> = game.header();
return {
pgn,
event: headers.Event,
site: headers.Site,
date: headers.Date,
round: headers.Round,
white: headers.White,
black: headers.Black,
result: headers.Result,
};
};