Compare commits

..

6 commits

Author SHA1 Message Date
3aa70f903e movegen enums 2026-07-26 09:31:24 +07:00
e20f297fc6 tweak piece enum 2026-07-26 09:19:41 +07:00
fb70f9ab1b update imports 2026-07-26 09:19:02 +07:00
3f9c5afb6b rename to game.ts 2026-07-26 09:10:38 +07:00
125356d321 use bit shifts 2026-07-26 08:35:41 +07:00
b9b7937a96 optimize to use 1 less bit for color 2026-07-25 21:56:38 +07:00
3 changed files with 39 additions and 10 deletions

View file

@ -1,17 +1,46 @@
import { Game } from "./utils";
import { Game } from "./game";
export type GameListener = (board: Game) => void;
export enum Piece {
EMPTY = 0,
KING = 1,
QUEEN = 2,
ROOK = 3,
BISHOP = 4,
KNIGHT = 5,
PAWN = 6,
export enum MoveFlag {
NORMAL = 0,
PAWN_DOUBLE = 1,
EN_PASSANT = 2,
CASTLE_KING = 3,
CASTLE_QUEEN = 4,
PROMOTION = 5,
CAPTURE = 6,
CAPTURE_PROMOTE = 7,
}
WHITE = 8,
BLACK = 16,
export enum Promotion {
QUEEN = 0,
ROOK = 1,
BISHOP = 2,
KNIGHT = 3,
}
export enum Capture {
NONE = 0,
PAWN = 1,
KNIGHT = 2,
BISHOP = 3,
ROOK = 4,
QUEEN = 5,
}
export enum Piece {
// bit 0-2: piece type (0-6)
EMPTY = 0,
QUEEN = 1,
ROOK = 2,
BISHOP = 3,
KNIGHT = 4,
PAWN = 5,
KING = 6,
// bit 3: color (0-1)
WHITE = 0<<3,
BLACK = 1<<3,
}
export const CHAR_TO_PIECE: Record<string, number> = {

View file

@ -1,6 +1,6 @@
<script lang="ts">
import { PIECE_TO_CHAR } from "$lib/chess/types";
import { boardToAscii, Game, startFEN } from "$lib/chess/utils";
import { boardToAscii, Game, startFEN } from "$lib/chess/game";
let showIndex = $state(false);
let fen = $state(startFEN);