Chess Engine
A fully functional chess game with an AI opponent — built in vanilla JavaScript with zero external dependencies. Everything from the board rendering to the move generation to the AI search was written from scratch.
Features
- Full chess rule enforcement: castling, en passant, pawn promotion (with piece selection), check, checkmate, stalemate
- Draw detection: 50-move rule, threefold repetition
- Three AI difficulty levels using configurable search depth
- Algebraic notation move history (e.g.
e4,Nf3,O-O) - FEN string support for importing/exporting board positions
- Undo move functionality
- Docker support for local serving
How the AI Works
The AI uses minimax search with alpha-beta pruning, which prunes branches that can't affect the final decision — dramatically reducing the number of positions evaluated.
On top of that:
- Quiescence search extends the search at leaf nodes when captures are available, preventing the AI from stopping mid-sequence and misreading a position
- MVV-LVA move ordering (Most Valuable Victim, Least Valuable Attacker) sorts captures to try the best moves first, maximizing pruning efficiency
- Piece-square tables bias the evaluation function toward good piece placement — knights in the center score higher than knights on the rim, for example
At difficulty 3 (depth 4), the AI plays solid, aggressive chess and will punish obvious mistakes.
Tech Stack
- Language: Vanilla JavaScript (ES6+)
- UI: DOM manipulation, CSS Grid for the board
- AI: Minimax + alpha-beta pruning, quiescence search
- Serving: Docker + static HTTP server
- Dependencies: None