@chess-labs/core
Version:
A lightweight, framework-agnostic chess engine written entirely in TypeScript
1 lines • 86.3 kB
Source Map (JSON)
{"version":3,"sources":["/Users/wook/Desktop/dev/core/dist/index.cjs","../src/types.ts","../src/board.ts","../src/helper.ts","../src/moves/pawn.ts","../src/moves/rook.ts","../src/moves/knight.ts","../src/moves/bishop.ts","../src/moves/queen.ts","../src/moves/king.ts","../src/moves/index.ts","../src/game.ts","../src/fen.ts"],"names":["PieceType","Color","getMovesInDirection","movePiece"],"mappings":"AAAA,6EAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;AACxF;AACA;ACAO,IAAK,UAAA,kBAAL,CAAA,CAAKA,UAAAA,EAAAA,GAAL;AACL,EAAAA,UAAAA,CAAA,MAAA,EAAA,EAAO,MAAA;AACP,EAAAA,UAAAA,CAAA,MAAA,EAAA,EAAO,MAAA;AACP,EAAAA,UAAAA,CAAA,QAAA,EAAA,EAAS,QAAA;AACT,EAAAA,UAAAA,CAAA,QAAA,EAAA,EAAS,QAAA;AACT,EAAAA,UAAAA,CAAA,OAAA,EAAA,EAAQ,OAAA;AACR,EAAAA,UAAAA,CAAA,MAAA,EAAA,EAAO,MAAA;AANG,EAAA,OAAAA,UAAAA;AAAA,CAAA,CAAA,CAAA,UAAA,GAAA,CAAA,CAAA,CAAA;AAYL,IAAK,MAAA,kBAAL,CAAA,CAAKC,MAAAA,EAAAA,GAAL;AACL,EAAAA,MAAAA,CAAA,OAAA,EAAA,EAAQ,OAAA;AACR,EAAAA,MAAAA,CAAA,OAAA,EAAA,EAAQ,OAAA;AAFE,EAAA,OAAAA,MAAAA;AAAA,CAAA,CAAA,CAAA,MAAA,GAAA,CAAA,CAAA,CAAA;ADGZ;AACA;AEdO,IAAM,UAAA,kBAAY,MAAA,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A,IAAA;AACA,IAAA;AAAc;AACd,IAAA;AAAS;AACT,IAAA;AAAa;AACb,IAAA;AAAa;AACb,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AAEO,EAAA;AAvCqB;AA6CjB;AZ8vBH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/wook/Desktop/dev/core/dist/index.cjs","sourcesContent":[null,"/**\n * Enumeration defining chess piece types\n */\nexport enum PieceType {\n PAWN = 'pawn',\n ROOK = 'rook',\n KNIGHT = 'knight',\n BISHOP = 'bishop',\n QUEEN = 'queen',\n KING = 'king',\n}\n\n/**\n * Enumeration defining chess piece colors\n */\nexport enum Color {\n WHITE = 'white',\n BLACK = 'black',\n}\n\n/**\n * Interface representing a position on the chess board\n * col: 0-7 (a-h)\n * row: 0-7 (1-8)\n */\nexport interface Position {\n col: number;\n row: number;\n}\n\n/**\n * Interface representing a chess piece\n */\nexport interface Piece {\n type: PieceType;\n color: Color;\n hasMoved?: boolean; // Used for castling, pawn's 2-square move, etc.\n}\n\n/**\n * Type representing a chess board\n * Implemented as a 2D array (8x8)\n * null means an empty square\n */\nexport type Board = Array<Array<Piece | null>>;\n\n/**\n * Type for special chess moves\n */\nexport type SpecialMove = 'castling' | 'en-passant' | 'promotion' | 'two-square-advance';\n\n/**\n * Type representing a possible move\n */\nexport interface Move {\n from: Position;\n to: Position;\n capture?: boolean; // Whether this move captures an opponent's piece\n special?: SpecialMove; // Special move type\n capturedPiecePosition?: Position; // Position of the captured piece (used for en-passant)\n}\n\n/**\n * Interface representing the state of a chess game\n */\nexport interface GameState {\n board: Board;\n currentTurn: Color;\n moveHistory: Array<{\n from: Position;\n to: Position;\n piece: Piece;\n captured?: Piece;\n special?: SpecialMove;\n promotedTo?: PieceType; // Type of piece that a pawn was promoted to\n }>;\n isCheck: boolean;\n isCheckmate: boolean;\n isStalemate: boolean;\n // FEN-specific fields\n castlingRights?: {\n whiteKingside: boolean;\n whiteQueenside: boolean;\n blackKingside: boolean;\n blackQueenside: boolean;\n };\n enPassantTarget?: string; // Algebraic notation (e.g., \"e3\") or null\n halfmoveClock?: number; // Moves since last capture or pawn move\n fullmoveNumber?: number; // Incremented after Black's move\n}\n","import { type Board, Color, type Piece, PieceType, type Position } from './types';\n\n/**\n * Initialize an 8x8 chess board for a standard chess game.\n */\nexport const initBoard = (): Board => {\n // Create an empty 8x8 chess board\n const board: Board = Array(8)\n .fill(null)\n .map(() => Array(8).fill(null));\n\n // Place pawns\n for (let col = 0; col < 8; col++) {\n placePiece(board, { col, row: 1 }, { type: PieceType.PAWN, color: Color.BLACK });\n placePiece(board, { col, row: 6 }, { type: PieceType.PAWN, color: Color.WHITE });\n }\n\n // Place rooks\n placePiece(board, { col: 0, row: 0 }, { type: PieceType.ROOK, color: Color.BLACK });\n placePiece(board, { col: 7, row: 0 }, { type: PieceType.ROOK, color: Color.BLACK });\n placePiece(board, { col: 0, row: 7 }, { type: PieceType.ROOK, color: Color.WHITE });\n placePiece(board, { col: 7, row: 7 }, { type: PieceType.ROOK, color: Color.WHITE });\n\n // Place knights\n placePiece(board, { col: 1, row: 0 }, { type: PieceType.KNIGHT, color: Color.BLACK });\n placePiece(board, { col: 6, row: 0 }, { type: PieceType.KNIGHT, color: Color.BLACK });\n placePiece(board, { col: 1, row: 7 }, { type: PieceType.KNIGHT, color: Color.WHITE });\n placePiece(board, { col: 6, row: 7 }, { type: PieceType.KNIGHT, color: Color.WHITE });\n\n // Place bishops\n placePiece(board, { col: 2, row: 0 }, { type: PieceType.BISHOP, color: Color.BLACK });\n placePiece(board, { col: 5, row: 0 }, { type: PieceType.BISHOP, color: Color.BLACK });\n placePiece(board, { col: 2, row: 7 }, { type: PieceType.BISHOP, color: Color.WHITE });\n placePiece(board, { col: 5, row: 7 }, { type: PieceType.BISHOP, color: Color.WHITE });\n\n // Place queens\n placePiece(board, { col: 3, row: 0 }, { type: PieceType.QUEEN, color: Color.BLACK });\n placePiece(board, { col: 3, row: 7 }, { type: PieceType.QUEEN, color: Color.WHITE });\n\n // Place kings\n placePiece(board, { col: 4, row: 0 }, { type: PieceType.KING, color: Color.BLACK });\n placePiece(board, { col: 4, row: 7 }, { type: PieceType.KING, color: Color.WHITE });\n\n return board;\n};\n\n/**\n * Check if the position is within the chess board.\n */\nexport const isValidPosition = (position: Position): boolean => {\n return position.col >= 0 && position.col < 8 && position.row >= 0 && position.row < 8;\n};\n\n/**\n * Return the piece at the specified position.\n * Returns null if the position is invalid or there is no piece.\n */\nexport const getPieceAt = (position: Position, board: Board): Piece | null => {\n if (!isValidPosition(position)) {\n return null;\n }\n\n return board[position.row][position.col];\n};\n\n/**\n * Place a piece at the specified position on the board.\n * Returns true if successful, false if the position is invalid.\n */\nexport const placePiece = (board: Board, position: Position, piece: Piece): boolean => {\n if (!isValidPosition(position)) {\n return false;\n }\n\n board[position.row][position.col] = piece;\n return true;\n};\n\n/**\n * Remove a piece from the specified position on the board.\n * Returns the removed piece if successful, null if the position is invalid or empty.\n */\nexport const removePiece = (board: Board, position: Position): Piece | null => {\n if (!isValidPosition(position)) {\n return null;\n }\n\n const piece = board[position.row][position.col];\n board[position.row][position.col] = null;\n return piece;\n};\n\n/**\n * Move a piece from one position to another.\n * Returns the captured piece (if any) or true if the move was successful,\n * false if the source position is invalid or empty.\n */\nexport const movePiece = (board: Board, from: Position, to: Position): Piece | boolean => {\n const piece = getPieceAt(from, board);\n if (!piece || !isValidPosition(to)) {\n return false;\n }\n\n const capturedPiece = removePiece(board, to);\n removePiece(board, from);\n placePiece(board, to, piece);\n\n return capturedPiece || true;\n};\n\n/**\n * Clear a position on the board by setting it to null.\n * Returns true if successful, false if the position is invalid.\n */\nexport const clearPosition = (board: Board, position: Position): boolean => {\n if (!isValidPosition(position)) {\n return false;\n }\n\n board[position.row][position.col] = null;\n return true;\n};\n\n/**\n * Clear the entire chess board by setting all positions to null.\n * @param board - The chess board to clear\n * @returns The cleared board\n */\nexport const clearBoard = (board: Board): Board => {\n for (let row = 0; row < 8; row++) {\n for (let col = 0; col < 8; col++) {\n board[row][col] = null;\n }\n }\n return board;\n};\n\n/**\n * Check if all positions between two positions (from, to) are empty.\n * Works only on straight paths (horizontal, vertical, diagonal).\n */\nexport const isPathClear = (from: Position, to: Position, board: Board): boolean => {\n const deltaCol = Math.sign(to.col - from.col);\n const deltaRow = Math.sign(to.row - from.row);\n\n if (deltaCol === 0 && deltaRow === 0) return true; // Same position\n\n // Validate that the path is straight (horizontal, vertical, or diagonal)\n const xDiff = Math.abs(to.col - from.col);\n const yDiff = Math.abs(to.row - from.row);\n const isStraightPath = deltaCol === 0 || deltaRow === 0 || xDiff === yDiff;\n if (!isStraightPath) {\n throw new Error('Path must be straight (horizontal, vertical, or diagonal)');\n }\n\n let col = from.col + deltaCol;\n let row = from.row + deltaRow;\n\n while (col !== to.col || row !== to.row) {\n if (board[row][col] !== null) {\n return false; // There is a piece in the path\n }\n\n col += deltaCol;\n row += deltaRow;\n }\n\n return true;\n};\n\n/**\n * Convert algebraic notation (e.g., \"e4\") to coordinates\n */\nexport const algebraicToPosition = (algebraic: string): Position => {\n if (!/^[a-h][1-8]$/.test(algebraic)) {\n throw new Error('Invalid algebraic notation. Expected format like \"e4\".');\n }\n\n const file = algebraic.charCodeAt(0) - 'a'.charCodeAt(0);\n const rank = 8 - Number.parseInt(algebraic[1], 10);\n\n return { col: file, row: rank };\n};\n\n/**\n * Clone a chess board deeply to avoid reference issues.\n * This creates a completely new copy of the board with all pieces.\n */\nexport const cloneBoard = (board: Board): Board => {\n return board.map((row) => row.map((piece) => (piece ? { ...piece } : null)));\n};\n\n/**\n * Convert coordinates to algebraic notation\n */\nexport const positionToAlgebraic = (position: Position): string => {\n // Validate that the position is within bounds\n if (!isValidPosition(position)) {\n throw new Error('Invalid position. Coordinates must be between 0 and 7.');\n }\n\n const file = String.fromCharCode('a'.charCodeAt(0) + position.col);\n const rank = 8 - position.row;\n\n return `${file}${rank}`;\n};\n","import { Position } from './types';\n\nexport const arePositionsEqual = (a: Position, b: Position): boolean => {\n return a.col === b.col && a.row === b.row;\n};\n","import type { Board, Move, Piece, Position, GameState } from '../types';\nimport { Color, PieceType } from '../types';\nimport { getPieceAt, isValidPosition } from '../board';\n\n/**\n * Get all possible moves for a pawn at the given position\n */\nexport const getPawnMoves = (position: Position, gameState: GameState): Move[] => {\n const { board } = gameState;\n const piece = getPieceAt(position, board);\n if (!piece || piece.type !== PieceType.PAWN) return [];\n\n const moves: Move[] = [];\n const direction = piece.color === Color.WHITE ? -1 : 1; // White moves up (-y), Black moves down (+y)\n const startingRank = piece.color === Color.WHITE ? 6 : 1;\n const promotionRank = piece.color === Color.WHITE ? 0 : 7; // Promotion rank (row 0 for white, row 7 for black)\n\n // Forward moves\n const forwardMoves = getForwardMoves(position, direction, startingRank, promotionRank, board);\n moves.push(...forwardMoves);\n\n // Capture moves\n const captureMoves = getCaptureMoves(position, direction, piece.color, promotionRank, board);\n moves.push(...captureMoves);\n\n // En passant moves\n const enPassantMoves = getEnPassantMoves(position, direction, piece.color, gameState);\n moves.push(...enPassantMoves);\n\n return moves;\n};\n\n/**\n * Get possible forward moves for a pawn\n */\nconst getForwardMoves = (\n position: Position,\n direction: number,\n startingRank: number,\n promotionRank: number,\n board: Board\n): Move[] => {\n const moves: Move[] = [];\n const oneSquareForward: Position = { col: position.col, row: position.row + direction };\n\n // Check one square forward\n if (isValidPosition(oneSquareForward) && !getPieceAt(oneSquareForward, board)) {\n // Check if the move results in promotion\n if (oneSquareForward.row === promotionRank) {\n moves.push({\n from: position,\n to: oneSquareForward,\n special: 'promotion',\n });\n } else {\n moves.push({\n from: position,\n to: oneSquareForward,\n });\n }\n\n // Check two squares forward from starting position\n if (position.row === startingRank) {\n const twoSquaresForward: Position = { col: position.col, row: position.row + direction * 2 };\n if (isValidPosition(twoSquaresForward) && !getPieceAt(twoSquaresForward, board)) {\n moves.push({\n from: position,\n to: twoSquaresForward,\n special: 'two-square-advance',\n });\n }\n }\n }\n\n return moves;\n};\n\n/**\n * Get possible capture moves for a pawn\n */\nconst getCaptureMoves = (\n position: Position,\n direction: number,\n color: Color,\n promotionRank: number,\n board: Board\n): Move[] => {\n const moves: Move[] = [];\n const capturePositions: Position[] = [\n { col: position.col - 1, row: position.row + direction }, // Left capture\n { col: position.col + 1, row: position.row + direction }, // Right capture\n ];\n\n for (const capturePos of capturePositions) {\n if (!isValidPosition(capturePos)) continue;\n\n const targetPiece = getPieceAt(capturePos, board);\n if (targetPiece && targetPiece.color !== color) {\n // Check if the capture results in promotion\n if (capturePos.row === promotionRank) {\n moves.push({\n from: position,\n to: capturePos,\n capture: true,\n special: 'promotion',\n });\n } else {\n moves.push({\n from: position,\n to: capturePos,\n capture: true,\n });\n }\n }\n }\n\n return moves;\n};\n\n/**\n * Get possible en passant moves for a pawn\n */\nconst getEnPassantMoves = (position: Position, direction: number, color: Color, gameState: GameState): Move[] => {\n const moves: Move[] = [];\n const { moveHistory } = gameState;\n\n // En passant is only possible if there is a previous move\n if (moveHistory.length === 0) return moves;\n\n const lastMove = moveHistory[moveHistory.length - 1];\n\n // Check if the last move was a pawn's two-square advance\n if (\n lastMove.piece.type === PieceType.PAWN &&\n lastMove.piece.color !== color &&\n lastMove.special === 'two-square-advance' &&\n Math.abs(lastMove.from.row - lastMove.to.row) === 2 &&\n position.row === lastMove.to.row\n ) {\n // Check if our pawn is adjacent to the opponent's pawn\n const colDiff = lastMove.to.col - position.col;\n if (Math.abs(colDiff) === 1) {\n moves.push({\n from: position,\n to: { col: lastMove.to.col, row: position.row + direction },\n capture: true,\n special: 'en-passant',\n capturedPiecePosition: lastMove.to, // Add this to help with move execution\n });\n }\n }\n\n return moves;\n};\n\n/**\n * Check if a pawn move is valid\n */\nexport const isValidPawnMove = (from: Position, to: Position, gameState: GameState): boolean => {\n const possibleMoves = getPawnMoves(from, gameState);\n return possibleMoves.some((move) => move.to.col === to.col && move.to.row === to.row);\n};\n","import type { Board, GameState, Move, Position } from '../types';\nimport { Color, PieceType } from '../types';\nimport { getPieceAt, isPathClear, isValidPosition } from '../board';\n\n/**\n * Get all possible moves for a rook at the given position\n */\nexport const getRookMoves = (position: Position, gameState: GameState): Move[] => {\n const { board } = gameState;\n const piece = getPieceAt(position, board);\n if (!piece || piece.type !== PieceType.ROOK) return [];\n\n const moves: Move[] = [];\n\n // Directions: horizontal (left, right) and vertical (up, down)\n const directions = [\n { deltaCol: -1, deltaRow: 0 }, // left\n { deltaCol: 1, deltaRow: 0 }, // right\n { deltaCol: 0, deltaRow: -1 }, // up\n { deltaCol: 0, deltaRow: 1 }, // down\n ];\n\n for (const direction of directions) {\n moves.push(...getMovesInDirection(position, direction.deltaCol, direction.deltaRow, piece.color, board));\n }\n\n return moves;\n};\n\n/**\n * Determines whether a rook move is valid based on chess rules.\n *\n * A valid rook move must:\n * - Be either horizontal or vertical (not diagonal).\n * - Have a clear path between the starting and ending positions.\n * - End on an empty square or capture an opponent's piece.\n *\n * @param {Position} from - The starting position of the rook.\n * @param {Position} to - The target position of the rook.\n * @param {GameState} gameState - The current state of the game, including the board and pieces.\n * @returns {boolean} True if the move is valid, false otherwise.\n */\nexport const isValidRookMove = (from: Position, to: Position, gameState: GameState): boolean => {\n const { board } = gameState;\n\n // Basic checks\n const piece = getPieceAt(from, board);\n if (!piece || piece.type !== PieceType.ROOK) return false;\n if (!isValidPosition(to)) return false;\n\n // Check if the move is horizontal or vertical\n const isHorizontal = from.row === to.row && from.col !== to.col;\n const isVertical = from.col === to.col && from.row !== to.row;\n if (!isHorizontal && !isVertical) return false;\n\n // Check if the path is clear\n if (!isPathClear(from, to, board)) return false;\n\n // Check if the destination is empty or has an opponent's piece\n const targetPiece = getPieceAt(to, board);\n if (targetPiece && targetPiece.color === piece.color) return false;\n\n return true;\n};\n\n/**\n * Get all moves in a specific direction\n */\nconst getMovesInDirection = (\n position: Position,\n deltaCol: number,\n deltaRow: number,\n pieceColor: Color,\n board: Board\n): Move[] => {\n const moves: Move[] = [];\n let currentCol = position.col + deltaCol;\n let currentRow = position.row + deltaRow;\n\n while (true) {\n // Check if position is valid (within board)\n if (!isValidPosition({ col: currentCol, row: currentRow })) break;\n\n const targetPosition: Position = { col: currentCol, row: currentRow };\n const targetPiece = getPieceAt(targetPosition, board);\n\n if (targetPiece === null) {\n // Empty square - can move here\n moves.push({\n from: position,\n to: targetPosition,\n capture: false,\n });\n } else {\n // Square has a piece\n if (targetPiece.color !== pieceColor) {\n // Opponent's piece - can capture\n moves.push({\n from: position,\n to: targetPosition,\n capture: true,\n });\n }\n // Either way, can't move further in this direction\n break;\n }\n\n currentCol += deltaCol;\n currentRow += deltaRow;\n }\n\n return moves;\n};\n","import type { Position, GameState } from '../types';\nimport { PieceType } from '../types';\nimport { getPieceAt } from '../board';\n\n/**\n * Calculates all possible moves for a knight.\n * Knight moves in an L-shape and can jump over other pieces.\n */\nexport const getKnightMoves = (position: Position): Position[] => {\n const { col, row } = position;\n\n // 8 possible L-shaped movement patterns for a knight\n const possibleMoves = [\n { col: col - 2, row: row - 1 },\n { col: col - 2, row: row + 1 },\n { col: col - 1, row: row - 2 },\n { col: col - 1, row: row + 2 },\n { col: col + 1, row: row - 2 },\n { col: col + 1, row: row + 2 },\n { col: col + 2, row: row - 1 },\n { col: col + 2, row: row + 1 },\n ];\n\n // Filter for moves within the chessboard range (0-7)\n return possibleMoves.filter((move) => move.col >= 0 && move.col <= 7 && move.row >= 0 && move.row <= 7);\n};\n\n/**\n * Checks if a move from source to destination position is valid for a knight.\n * Knights move in an L-shape (2 squares in one direction and then 1 square perpendicular)\n * and can jump over other pieces.\n */\nexport const isValidKnightMove = (from: Position, to: Position, gameState: GameState): boolean => {\n // 1. Check if there is a knight at the from position\n const piece = getPieceAt(from, gameState.board);\n if (!piece || piece.type !== PieceType.KNIGHT) {\n return false;\n }\n\n // 2. Check if destination is occupied by a piece of the same color\n const destPiece = getPieceAt(to, gameState.board);\n if (destPiece && destPiece.color === piece.color) {\n return false;\n }\n\n // 3. Check if the move is an L-shape (2 squares in one direction and 1 in perpendicular)\n const colDiff = Math.abs(to.col - from.col);\n const rowDiff = Math.abs(to.row - from.row);\n const isLShape = (colDiff === 2 && rowDiff === 1) || (colDiff === 1 && rowDiff === 2);\n\n if (!isLShape) {\n return false;\n }\n\n return true;\n};\n","import type { Position, GameState, Move } from '../types';\nimport { PieceType } from '../types';\nimport { getPieceAt, isValidPosition, isPathClear } from '../board';\n\n/**\n * Calculates all possible moves for a bishop.\n * Bishops move diagonally and are blocked by other pieces.\n */\nexport const getBishopMoves = (from: Position, gameState: GameState): Move[] => {\n const piece = getPieceAt(from, gameState.board);\n\n // Check if there is a bishop at the position\n if (!piece || piece.type !== PieceType.BISHOP) {\n return [];\n }\n\n const moves: Move[] = [];\n const directions = [\n { col: 1, row: 1 }, // down-right\n { col: 1, row: -1 }, // up-right\n { col: -1, row: 1 }, // down-left\n { col: -1, row: -1 }, // up-left\n ];\n\n // Check each diagonal direction\n for (const dir of directions) {\n let currentPos: Position = { col: from.col, row: from.row };\n\n // Move in the current direction until reaching the edge or a piece\n while (true) {\n currentPos = { col: currentPos.col + dir.col, row: currentPos.row + dir.row };\n\n // Stop if position is outside the board\n if (!isValidPosition(currentPos)) {\n break;\n }\n\n const targetPiece = getPieceAt(currentPos, gameState.board);\n\n // If there's a piece of the same color, can't move here\n if (targetPiece && targetPiece.color === piece.color) {\n break;\n }\n\n // Add the move (with capture flag if there's an opponent's piece)\n const move: Move = {\n from,\n to: { ...currentPos },\n capture: targetPiece !== null,\n };\n\n moves.push(move);\n\n // Stop after capturing an opponent's piece\n if (targetPiece) {\n break;\n }\n }\n }\n\n return moves;\n};\n\n/**\n * Checks if a move from source to destination position is valid for a bishop.\n * Bishops move diagonally and are blocked by pieces in their path.\n */\nexport const isValidBishopMove = (from: Position, to: Position, gameState: GameState): boolean => {\n const piece = getPieceAt(from, gameState.board);\n\n // Check if there is a bishop at the from position\n if (!piece || piece.type !== PieceType.BISHOP) {\n return false;\n }\n\n // Check if destination is occupied by a piece of the same color\n const destPiece = getPieceAt(to, gameState.board);\n if (destPiece && destPiece.color === piece.color) {\n return false;\n }\n\n // Check if the move is diagonal\n const xDiff = Math.abs(to.col - from.col);\n const yDiff = Math.abs(to.row - from.row);\n\n // Bishop moves diagonally (col and row differences must be equal)\n if (xDiff !== yDiff) {\n return false;\n }\n\n // Check if the path is clear\n return isPathClear(from, to, gameState.board);\n};\n","import type { Board, GameState, Move, Position } from '../types';\nimport { Color, PieceType } from '../types';\nimport { getPieceAt, isPathClear, isValidPosition } from '../board';\n\n/**\n * Get all possible moves for a queen at the given position.\n * The queen combines the movement of the rook (horizontal/vertical)\n * and the bishop (diagonal).\n */\nexport const getQueenMoves = (position: Position, gameState: GameState): Move[] => {\n const { board } = gameState;\n const piece = getPieceAt(position, board);\n if (!piece || piece.type !== PieceType.QUEEN) return [];\n\n const moves: Move[] = [];\n\n // Directions: horizontal, vertical, and diagonal\n const directions = [\n { deltaCol: -1, deltaRow: 0 }, // left\n { deltaCol: 1, deltaRow: 0 }, // right\n { deltaCol: 0, deltaRow: -1 }, // up\n { deltaCol: 0, deltaRow: 1 }, // down\n { deltaCol: -1, deltaRow: -1 }, // up-left\n { deltaCol: 1, deltaRow: -1 }, // up-right\n { deltaCol: -1, deltaRow: 1 }, // down-left\n { deltaCol: 1, deltaRow: 1 }, // down-right\n ];\n\n for (const direction of directions) {\n moves.push(...getMovesInDirection(position, direction.deltaCol, direction.deltaRow, piece.color, board));\n }\n\n return moves;\n};\n\n/**\n * Determines whether a queen move is valid based on chess rules.\n *\n * A valid queen move must:\n * - Be either horizontal, vertical, or diagonal.\n * - Have a clear path between the starting and ending positions.\n * - End on an empty square or capture an opponent's piece.\n *\n * @param {Position} from - The starting position of the queen.\n * @param {Position} to - The target position of the queen.\n * @param {GameState} gameState - The current state of the game, including the board and pieces.\n * @returns {boolean} True if the move is valid, false otherwise.\n */\nexport const isValidQueenMove = (from: Position, to: Position, gameState: GameState): boolean => {\n const { board } = gameState;\n\n // Basic checks\n const piece = getPieceAt(from, board);\n if (!piece || piece.type !== PieceType.QUEEN) return false;\n if (!isValidPosition(to)) return false;\n\n // Check if the move is horizontal, vertical, or diagonal\n const deltaCol = Math.abs(to.col - from.col);\n const deltaRow = Math.abs(to.row - from.row);\n const isHorizontal = deltaRow === 0 && deltaCol > 0;\n const isVertical = deltaCol === 0 && deltaRow > 0;\n const isDiagonal = deltaCol === deltaRow && deltaCol > 0;\n\n if (!isHorizontal && !isVertical && !isDiagonal) return false;\n\n return (\n isPathClear(from, to, board) && (getPieceAt(to, board) === null || getPieceAt(to, board)?.color !== piece.color)\n );\n};\n\n/**\n * Get all moves in a specific direction\n */\nexport const getMovesInDirection = (\n position: Position,\n deltaCol: number,\n deltaRow: number,\n pieceColor: Color,\n board: Board\n): Move[] => {\n const moves: Move[] = [];\n let currentCol = position.col + deltaCol;\n let currentRow = position.row + deltaRow;\n while (true) {\n // Check if position is valid (within board)\n if (!isValidPosition({ col: currentCol, row: currentRow })) break;\n const targetPosition: Position = { col: currentCol, row: currentRow };\n const targetPiece = getPieceAt(targetPosition, board);\n if (targetPiece === null) {\n // Empty square - can move here\n moves.push({\n from: position,\n to: targetPosition,\n capture: false,\n });\n } else {\n // Square has a piece\n if (targetPiece.color !== pieceColor) {\n // Opponent's piece - can capture\n moves.push({\n from: position,\n to: targetPosition,\n capture: true,\n });\n }\n // Either way, can't move further in this direction\n break;\n }\n currentCol += deltaCol;\n currentRow += deltaRow;\n }\n return moves;\n};\n","import { type GameState, type Move, type Position, Color, PieceType } from '../types';\nimport { getPieceAt, isPathClear, cloneBoard, clearPosition, placePiece } from '../board';\nimport { isPlayerInCheck } from '../game';\n\n/**\n * Returns all possible moves for a king at the given position.\n */\nexport const getKingMoves = (position: Position, gameState: GameState): Move[] => {\n const { col, row } = position;\n const { board } = gameState;\n\n const kingPiece = getPieceAt(position, board);\n\n // If there's no king at the current position, return an empty array\n if (!kingPiece || kingPiece.type !== PieceType.KING) {\n return [];\n }\n\n const kingColor = kingPiece.color;\n const moves: Move[] = [];\n\n // Kings can move one square in any direction (8 directions)\n const directions = [\n { deltaCol: -1, deltaRow: -1 }, // top-left\n { deltaCol: 0, deltaRow: -1 }, // top\n { deltaCol: 1, deltaRow: -1 }, // top-right\n { deltaCol: -1, deltaRow: 0 }, // left\n { deltaCol: 1, deltaRow: 0 }, // right\n { deltaCol: -1, deltaRow: 1 }, // bottom-left\n { deltaCol: 0, deltaRow: 1 }, // bottom\n { deltaCol: 1, deltaRow: 1 }, // bottom-right\n ];\n\n for (const { deltaCol, deltaRow } of directions) {\n const newCol = col + deltaCol;\n const newRow = row + deltaRow;\n\n // Check board boundaries\n if (newCol < 0 || newCol > 7 || newRow < 0 || newRow > 7) {\n continue;\n }\n\n const targetSquare = board[newRow][newCol];\n\n // Can move to empty squares or capture opponent pieces\n if (!targetSquare || targetSquare.color !== kingColor) {\n const move: Move = {\n from: { col, row },\n to: { col: newCol, row: newRow },\n };\n\n // If there's an opponent piece, it's a capture\n if (targetSquare && targetSquare.color !== kingColor) {\n move.capture = true;\n }\n\n moves.push(move);\n }\n }\n\n // Add castling moves\n if (!kingPiece.hasMoved) {\n // Kingside castling\n const kingsideRookPos = { col: 7, row };\n if (canCastle(position, kingsideRookPos, gameState)) {\n moves.push({\n from: position,\n to: { col: col + 2, row },\n special: 'castling',\n });\n }\n\n // Queenside castling\n const queensideRookPos = { col: 0, row };\n if (canCastle(position, queensideRookPos, gameState)) {\n moves.push({\n from: position,\n to: { col: col - 2, row },\n special: 'castling',\n });\n }\n }\n\n return moves;\n};\n\n/**\n * Checks if a king move is valid.\n */\nexport const isValidKingMove = (from: Position, to: Position, gameState: GameState): boolean => {\n const { board } = gameState;\n\n const kingPiece = getPieceAt(from, board);\n\n // If there's no king at the source position, the move is invalid\n if (!kingPiece || kingPiece.type !== PieceType.KING) {\n return false;\n }\n\n // Calculate the distance of the move\n const deltaCol = Math.abs(to.col - from.col);\n const deltaRow = Math.abs(to.row - from.row);\n\n // Kings can only move one square in any direction\n if (deltaCol > 1 || deltaRow > 1) {\n // Handle castling exception\n if (deltaRow === 0 && deltaCol === 2) {\n // Potential castling move\n const rookCol = to.col > from.col ? 7 : 0;\n const rookPos = { col: rookCol, row: from.row };\n return canCastle(from, rookPos, gameState);\n }\n return false;\n }\n\n const kingColor = kingPiece.color;\n const targetSquare = board[to.row][to.col];\n\n // Cannot move to a square occupied by a piece of the same color\n if (targetSquare && targetSquare.color === kingColor) {\n return false;\n }\n\n // Check if the king would be in check after the move\n // Create a cloned board to simulate the move\n const clonedBoard = cloneBoard(board);\n\n // First clear the king's current position\n clearPosition(clonedBoard, from);\n\n // If there's a piece at the target position (capture scenario), clear it first\n if (targetSquare && targetSquare.color !== kingColor) {\n clearPosition(clonedBoard, to);\n }\n\n // Place the king at the new position\n placePiece(clonedBoard, to, kingPiece);\n\n // Create a temporary game state with the king moved\n const clonedGameState = { ...gameState, board: clonedBoard };\n\n // If the king would be in check after the move, it's invalid\n if (isPlayerInCheck(clonedGameState, kingColor)) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Checks if castling is possible between king and rook positions.\n * @param kingPosition The position of the king\n * @param rookPosition The position of the rook\n * @param gameState Current game state\n * @returns True if castling is allowed, false otherwise\n */\nexport const canCastle = (kingPosition: Position, rookPosition: Position, gameState: GameState): boolean => {\n const { board } = gameState;\n\n // 1. Check if king and rook are present and have not moved\n const king = getPieceAt(kingPosition, board);\n const rook = getPieceAt(rookPosition, board);\n\n if (!king || king.type !== PieceType.KING || king.hasMoved) {\n return false;\n }\n\n if (!rook || rook.type !== PieceType.ROOK || rook.hasMoved) {\n return false;\n }\n\n // King and rook must be of the same color\n if (king.color !== rook.color) {\n return false;\n }\n\n // King and rook must be on the same row for castling\n if (kingPosition.row !== rookPosition.row) {\n return false;\n }\n\n // 2. Check if the king is currently in check\n if (isPlayerInCheck(gameState, king.color)) {\n return false;\n }\n\n // 3. Check if there are pieces between king and rook\n if (!isPathClear(kingPosition, rookPosition, board)) {\n return false;\n }\n\n // 4. King cannot pass through or end up on a square that is under attack\n // Determine the path the king will take\n const direction = rookPosition.col > kingPosition.col ? 1 : -1; // 1 for ki