From 07c90e9ef56247473e7de4022d33a64177b5c4b2 Mon Sep 17 00:00:00 2001 From: satr14 Date: Sat, 25 Jul 2026 16:42:33 +0700 Subject: [PATCH] full fen parsing --- src/lib/chess/utils.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/chess/utils.ts b/src/lib/chess/utils.ts index c5aca34..c4a0dd7 100644 --- a/src/lib/chess/utils.ts +++ b/src/lib/chess/utils.ts @@ -1,3 +1,4 @@ +import type { GTK_A11Y, TPM2_PKCS11_TCTI } from "$env/static/private"; import { Piece } from "./types"; // export function fen2array(fen: string): Int8Array { @@ -23,7 +24,7 @@ const CHAR_TO_PIECE: Record = { export class Board { public board = new Int8Array(8 ** 2); public details = { - turn: "w", + whiteTurn: true, castling: { white: { king: true, queen: true }, black: { king: true, queen: true }, @@ -39,8 +40,8 @@ export class Board { loadFEN(fen = startFEN) { const [position, turn, castling, enPassant, halfMove, fullMove] = fen.split(" "); - this.board.fill(Piece.EMPTY); + this.board.fill(Piece.EMPTY); position.split("/").forEach((row, rank) => { let file = 0; row.split("").forEach((char) => { @@ -49,6 +50,18 @@ export class Board { file++; }); }); + + this.details.whiteTurn = turn === "w"; + + this.details.castling.white.king = castling.includes("K"); + this.details.castling.white.queen = castling.includes("Q"); + this.details.castling.black.king = castling.includes("k"); + this.details.castling.black.queen = castling.includes("q"); + + this.details.enPassant = algebraicToIndex(enPassant); + + this.details.halfMove = parseInt(halfMove); + this.details.fullMove = parseInt(fullMove); } }