feat : add games database
This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GameEval, LineEval, MoveEval } from "@/types/eval";
|
||||
import { GameEval, LineEval, MoveEval } from "@/types/game";
|
||||
|
||||
export class Stockfish {
|
||||
private worker: Worker;
|
||||
|
||||
Reference in New Issue
Block a user