diff --git a/src/lib/chess/utils.ts b/src/lib/chess/utils.ts index e7eb6df..33a99e3 100644 --- a/src/lib/chess/utils.ts +++ b/src/lib/chess/utils.ts @@ -1,4 +1,4 @@ -import { CHAR_TO_PIECE, Piece, type GameListener } from "./types"; +import { CHAR_TO_PIECE, Piece, PIECE_TO_CHAR, type GameListener } from "./types"; export const startFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0"; @@ -59,6 +59,15 @@ export class Game { } } +export function boardToAscii(board: Int8Array): string { + let ascii = ''; + board.forEach((piece, i) => { + if (i % 8 === 0 && i !== 0) ascii += '\n'; + ascii += PIECE_TO_CHAR[piece]; + }); + return ascii; +} + function algebraicToIndex(algebraic: string): number { const FILE_TO_INDEX: Record = { a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7, diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 33c31b5..4c4c825 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,16 +1,20 @@ @@ -25,6 +29,36 @@ {/each}
+ +