Compare commits
No commits in common. "a56e77c378a1db48b0905403b0193764e993e50c" and "014d170e6ab009c0c7fa2b5c1148d20067cf49a1" have entirely different histories.
a56e77c378
...
014d170e6a
3 changed files with 40 additions and 41 deletions
|
|
@ -3,41 +3,46 @@ import { Piece } from "./types";
|
||||||
// export function fen2array(fen: string): Int8Array<ArrayBuffer> {
|
// export function fen2array(fen: string): Int8Array<ArrayBuffer> {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export const startFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0";
|
|
||||||
const CHAR_TO_PIECE: Record<string, number> = {
|
|
||||||
"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: Int8Array;
|
||||||
public details = {
|
|
||||||
turn: "w",
|
|
||||||
castling: {
|
|
||||||
white: { king: true, queen: true },
|
|
||||||
black: { king: true, queen: true },
|
|
||||||
},
|
|
||||||
enPassant: -1,
|
|
||||||
halfMove: 0,
|
|
||||||
fullMove: 0,
|
|
||||||
};
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.loadFEN();
|
const board = new Int8Array(8**2);
|
||||||
}
|
board[0] = Piece.WHITE | Piece.ROOK;
|
||||||
|
board[1] = Piece.WHITE | Piece.KNIGHT;
|
||||||
|
board[2] = Piece.WHITE | Piece.BISHOP;
|
||||||
|
board[3] = Piece.WHITE | Piece.QUEEN;
|
||||||
|
board[4] = Piece.WHITE | Piece.KING;
|
||||||
|
board[5] = Piece.WHITE | Piece.BISHOP;
|
||||||
|
board[6] = Piece.WHITE | Piece.KNIGHT;
|
||||||
|
board[7] = Piece.WHITE | Piece.ROOK;
|
||||||
|
board[8] = Piece.WHITE | Piece.PAWN;
|
||||||
|
board[9] = Piece.WHITE | Piece.PAWN;
|
||||||
|
board[10] = Piece.WHITE | Piece.PAWN;
|
||||||
|
board[11] = Piece.WHITE | Piece.PAWN;
|
||||||
|
board[12] = Piece.WHITE | Piece.PAWN;
|
||||||
|
board[13] = Piece.WHITE | Piece.PAWN;
|
||||||
|
board[14] = Piece.WHITE | Piece.PAWN;
|
||||||
|
board[15] = Piece.WHITE | Piece.PAWN;
|
||||||
|
|
||||||
loadFEN(fen = startFEN) {
|
board[48] = Piece.BLACK | Piece.PAWN;
|
||||||
const [position, turn, castling, enPassant, halfMove, fullMove] = fen.split(" ");
|
board[49] = Piece.BLACK | Piece.PAWN;
|
||||||
|
board[50] = Piece.BLACK | Piece.PAWN;
|
||||||
|
board[51] = Piece.BLACK | Piece.PAWN;
|
||||||
|
board[52] = Piece.BLACK | Piece.PAWN;
|
||||||
|
board[53] = Piece.BLACK | Piece.PAWN;
|
||||||
|
board[54] = Piece.BLACK | Piece.PAWN;
|
||||||
|
board[55] = Piece.BLACK | Piece.PAWN;
|
||||||
|
board[56] = Piece.BLACK | Piece.ROOK;
|
||||||
|
board[57] = Piece.BLACK | Piece.KNIGHT;
|
||||||
|
board[58] = Piece.BLACK | Piece.BISHOP;
|
||||||
|
board[59] = Piece.BLACK | Piece.QUEEN;
|
||||||
|
board[60] = Piece.BLACK | Piece.KING;
|
||||||
|
board[61] = Piece.BLACK | Piece.BISHOP;
|
||||||
|
board[62] = Piece.BLACK | Piece.KNIGHT;
|
||||||
|
board[63] = Piece.BLACK | Piece.ROOK;
|
||||||
|
|
||||||
|
this.board = board;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export const ssr = false;
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Board, startFEN } from "$lib/chess/utils";
|
import { Board } from "$lib/chess/utils";
|
||||||
|
|
||||||
const board = new Board();
|
const board = new Board();
|
||||||
let showIndex = $state(false);
|
let showIndex = $state(false);
|
||||||
let fen = $state(startFEN);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-cols-8 gap-0 border-2">
|
<div class="grid grid-cols-8 gap-0 border-2">
|
||||||
|
|
@ -11,18 +10,14 @@
|
||||||
<div class="h-20 aspect-square flex justify-center items-center
|
<div class="h-20 aspect-square flex justify-center items-center
|
||||||
{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'}
|
||||||
">
|
">
|
||||||
{#if square}<img src="assets/{square}.svg" alt="p{square}" class="h-16 aspect-square"/>{/if}
|
{#if square}<img src="assets/{square}.svg" alt="{square}" class="h-16 aspect-square"/>{/if}
|
||||||
{showIndex ? index : ''}
|
{showIndex ? index : ''}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="block">
|
<label>
|
||||||
show index
|
show index
|
||||||
<input type="checkbox" bind:checked={showIndex} />
|
<input type="checkbox" bind:checked={showIndex} />
|
||||||
</label>
|
</label>
|
||||||
<label class="block">
|
|
||||||
fen:
|
|
||||||
<input type="text" onkeypress={(e) => e.key === 'Enter' && board.loadFEN(fen)} bind:value={fen} />
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue