refacto : global refacto
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user