full fen parsing
This commit is contained in:
parent
9032a40b24
commit
07c90e9ef5
1 changed files with 15 additions and 2 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import type { GTK_A11Y, TPM2_PKCS11_TCTI } from "$env/static/private";
|
||||||
import { Piece } from "./types";
|
import { Piece } from "./types";
|
||||||
|
|
||||||
// export function fen2array(fen: string): Int8Array<ArrayBuffer> {
|
// export function fen2array(fen: string): Int8Array<ArrayBuffer> {
|
||||||
|
|
@ -23,7 +24,7 @@ const CHAR_TO_PIECE: Record<string, number> = {
|
||||||
export class Board {
|
export class Board {
|
||||||
public board = new Int8Array(8 ** 2);
|
public board = new Int8Array(8 ** 2);
|
||||||
public details = {
|
public details = {
|
||||||
turn: "w",
|
whiteTurn: true,
|
||||||
castling: {
|
castling: {
|
||||||
white: { king: true, queen: true },
|
white: { king: true, queen: true },
|
||||||
black: { king: true, queen: true },
|
black: { king: true, queen: true },
|
||||||
|
|
@ -39,8 +40,8 @@ export class Board {
|
||||||
|
|
||||||
loadFEN(fen = startFEN) {
|
loadFEN(fen = startFEN) {
|
||||||
const [position, turn, castling, enPassant, halfMove, fullMove] = fen.split(" ");
|
const [position, turn, castling, enPassant, halfMove, fullMove] = fen.split(" ");
|
||||||
this.board.fill(Piece.EMPTY);
|
|
||||||
|
|
||||||
|
this.board.fill(Piece.EMPTY);
|
||||||
position.split("/").forEach((row, rank) => {
|
position.split("/").forEach((row, rank) => {
|
||||||
let file = 0;
|
let file = 0;
|
||||||
row.split("").forEach((char) => {
|
row.split("").forEach((char) => {
|
||||||
|
|
@ -49,6 +50,18 @@ export class Board {
|
||||||
file++;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue