diff --git a/src/lib/chess/utils.ts b/src/lib/chess/utils.ts index 6f2e7f8..c597548 100644 --- a/src/lib/chess/utils.ts +++ b/src/lib/chess/utils.ts @@ -5,7 +5,6 @@ import { Piece } from "./types"; export const startFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0"; const CHAR_TO_PIECE: Record = { - "-": Piece.EMPTY, "K": Piece.WHITE | Piece.KING, "Q": Piece.WHITE | Piece.QUEEN, "R": Piece.WHITE | Piece.ROOK, @@ -32,22 +31,13 @@ export class Board { halfMove: 0, fullMove: 0, }; - constructor() { this.loadFEN(); } loadFEN(fen = startFEN) { const [position, turn, castling, enPassant, halfMove, fullMove] = fen.split(" "); - this.board.fill(Piece.EMPTY); - position.split("/").forEach((row, rank) => { - let file = 0; - row.split("").forEach((char) => { - if (!isNaN(parseInt(char))) return file += parseInt(char); - this.board[rank * 8 + file] = CHAR_TO_PIECE[char] - file++; - }); - }); + } } \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 4eff4e1..bd4c54e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,22 +2,16 @@ import { Board, startFEN } from "$lib/chess/utils"; const board = new Board(); - - let boardView = $state(Array.from(board.board)); let showIndex = $state(false); let fen = $state(startFEN); - - function updateView() { - boardView = Array.from(board.board); - }
- {#each boardView as square, index} + {#each board.board as square, index}
- {#if square}p{square}{/if} + {#if square}p{square}{/if} {showIndex ? index : ''}
{/each} @@ -28,9 +22,7 @@ - -
\ No newline at end of file diff --git a/src/routes/layout.css b/src/routes/layout.css index 46b5600..e9704fd 100644 --- a/src/routes/layout.css +++ b/src/routes/layout.css @@ -2,5 +2,3 @@ html, body { @apply h-full; } body { @apply bg-gray-900 text-gray-100; } - -input, button { @apply bg-stone-200 text-stone-800 px-2 py-1 m-1 rounded; } \ No newline at end of file