@maadesh124/chess-engine
v1.0.0
Published
Core JavaScript Chess Engine implementation. The main entry point is the `Chess` class.
Readme
♟️ ChessEngine
Core JavaScript Chess Engine implementation.
The main entry point is the Chess class.
🚀 Getting Started
1. Clone the Repository
git clone https://github.com/maadesh124/ChessEngine.git
cd ChessEngine2. Import the Chess Class
import Chess from "./Chess.js";
const game = new Chess();📦 Chess Class API
new Chess()
Creates a new chess game.
move(src, dst)
Moves a piece from source to destination.
src,dstare arrays[row, col](0-indexed).- Returns a status code (one of the static constants).
Example:
game.move([6, 4], [4, 4]); // Pawn e2 → e4promote(pos, type)
Promotes a pawn at pos to a new piece.
pos→[row, col]type→"Queen" | "Rook" | "Bishop" | "Knight"- Returns a promotion status code.
Example:
game.promote([0, 0], "Queen");whoseTurn()
Returns whose turn it is (0 or 1).
0 for white and 1 for black
Example:
console.log(game.whoseTurn()); // "White"getBoardState()
Returns the current board as a 2D array (8×8).
Each cell contains either null or a string like "Pawn0", "King1", etc.
Example:
console.log(game.getBoardState());🔢 Static Status Codes
Chess.INVALID_MOVEChess.ILLEGAL_MOVEChess.VALID_MOVEChess.CHECKMATEChess.WRONG_PLAYChess.STALE_MATEChess.INVALID_PROMOTIONChess.VALID_PROMOTIONChess.PROMOTE
Example:
const result = game.move([6, 4], [4, 4]);
if (result === Chess.VALID_MOVE) {
console.log("Move accepted");
}