piece display change and move constant to types.ts
|
|
@ -9,4 +9,36 @@ export enum Piece {
|
||||||
|
|
||||||
WHITE = 8,
|
WHITE = 8,
|
||||||
BLACK = 16,
|
BLACK = 16,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CHAR_TO_PIECE: Record<string, number> = {
|
||||||
|
"-": Piece.EMPTY,
|
||||||
|
"K": Piece.WHITE | Piece.KING,
|
||||||
|
"Q": Piece.WHITE | Piece.QUEEN,
|
||||||
|
"R": Piece.WHITE | Piece.ROOK,
|
||||||
|
"B": Piece.WHITE | Piece.BISHOP,
|
||||||
|
"N": Piece.WHITE | Piece.KNIGHT,
|
||||||
|
"P": Piece.WHITE | Piece.PAWN,
|
||||||
|
"k": Piece.BLACK | Piece.KING,
|
||||||
|
"q": Piece.BLACK | Piece.QUEEN,
|
||||||
|
"r": Piece.BLACK | Piece.ROOK,
|
||||||
|
"b": Piece.BLACK | Piece.BISHOP,
|
||||||
|
"n": Piece.BLACK | Piece.KNIGHT,
|
||||||
|
"p": Piece.BLACK | Piece.PAWN,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PIECE_TO_CHAR: Record<number, string> = {
|
||||||
|
[Piece.EMPTY]: "-",
|
||||||
|
[Piece.WHITE | Piece.KING]: "K",
|
||||||
|
[Piece.WHITE | Piece.QUEEN]: "Q",
|
||||||
|
[Piece.WHITE | Piece.ROOK]: "R",
|
||||||
|
[Piece.WHITE | Piece.BISHOP]: "B",
|
||||||
|
[Piece.WHITE | Piece.KNIGHT]: "N",
|
||||||
|
[Piece.WHITE | Piece.PAWN]: "P",
|
||||||
|
[Piece.BLACK | Piece.KING]: "k",
|
||||||
|
[Piece.BLACK | Piece.QUEEN]: "q",
|
||||||
|
[Piece.BLACK | Piece.ROOK]: "r",
|
||||||
|
[Piece.BLACK | Piece.BISHOP]: "b",
|
||||||
|
[Piece.BLACK | Piece.KNIGHT]: "n",
|
||||||
|
[Piece.BLACK | Piece.PAWN]: "p",
|
||||||
}
|
}
|
||||||
|
|
@ -1,24 +1,6 @@
|
||||||
import { Piece } from "./types";
|
import { CHAR_TO_PIECE, Piece } from "./types";
|
||||||
|
|
||||||
// export function fen2array(fen: string): Int8Array<ArrayBuffer> {
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const startFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0";
|
export const startFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0";
|
||||||
const CHAR_TO_PIECE: Record<string, number> = {
|
|
||||||
"-": Piece.EMPTY,
|
|
||||||
"K": Piece.WHITE | Piece.KING,
|
|
||||||
"Q": Piece.WHITE | Piece.QUEEN,
|
|
||||||
"R": Piece.WHITE | Piece.ROOK,
|
|
||||||
"B": Piece.WHITE | Piece.BISHOP,
|
|
||||||
"N": Piece.WHITE | Piece.KNIGHT,
|
|
||||||
"P": Piece.WHITE | Piece.PAWN,
|
|
||||||
"k": Piece.BLACK | Piece.KING,
|
|
||||||
"q": Piece.BLACK | Piece.QUEEN,
|
|
||||||
"r": Piece.BLACK | Piece.ROOK,
|
|
||||||
"b": Piece.BLACK | Piece.BISHOP,
|
|
||||||
"n": Piece.BLACK | Piece.KNIGHT,
|
|
||||||
"p": Piece.BLACK | Piece.PAWN,
|
|
||||||
};
|
|
||||||
|
|
||||||
export class Board {
|
export class Board {
|
||||||
public board = new Int8Array(8 ** 2);
|
public board = new Int8Array(8 ** 2);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { PIECE_TO_CHAR } from "$lib/chess/types";
|
||||||
import { Board, startFEN } from "$lib/chess/utils";
|
import { Board, startFEN } from "$lib/chess/utils";
|
||||||
|
|
||||||
const board = new Board();
|
const board = new Board();
|
||||||
|
|
@ -18,7 +19,7 @@
|
||||||
{index % 2 === Math.floor(index / 8) % 2 ? 'bg-orange-200 text-stone-800' : 'bg-amber-800 text-stone-200'}
|
{index % 2 === Math.floor(index / 8) % 2 ? 'bg-orange-200 text-stone-800' : 'bg-amber-800 text-stone-200'}
|
||||||
">
|
">
|
||||||
<span class="absolute top-0 left-0">{showIndex ? index : ''}</span>
|
<span class="absolute top-0 left-0">{showIndex ? index : ''}</span>
|
||||||
{#if square}<img src="assets/{square}.svg" alt="p{square}" class="h-18 aspect-square"/>{/if}
|
{#if square}<img src="assets/{PIECE_TO_CHAR[square]}.svg" alt="{PIECE_TO_CHAR[square]}" class="h-18 aspect-square"/>{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 921 B After Width: | Height: | Size: 921 B |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 921 B After Width: | Height: | Size: 921 B |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |