A premium-quality, industry-grade chess game built from scratch with React, TypeScript, and HTML5 Canvas. Features a custom-built chess engine with no external chess libraries.
- Pass & Play: Play against a friend on the same device
- vs Computer: Challenge the AI with 5 difficulty levels
- Custom-built chess engine - No external chess libraries
- Alpha-Beta pruning with iterative deepening
- Transposition tables with Zobrist hashing
- Move ordering with MVV-LVA, killer moves, and history heuristic
- Quiescence search to avoid horizon effect
- Human-like behavior with configurable mistake probability
| Level | Description | Depth | Time |
|---|---|---|---|
| ๐ฑ Beginner | Learning the basics | 2 | 500ms |
| ๐ฎ Easy | Casual play | 3 | 1s |
| โก Medium | Moderate challenge | 4 | 2s |
| ๐ฅ Hard | Strong opponent | 5 | 4s |
| ๐ Expert | Maximum strength | 6 | 6s |
- Canvas-based board with smooth rendering
- Drag-and-drop and click-to-move piece movement
- Legal move highlighting
- Last move indicator
- Check highlighting
- Move history with navigation
- AI analysis panel with evaluation bar
- Dark/Light theme toggle
- Board flip option
- Responsive design - works on desktop and mobile
- Web Worker - Engine runs in separate thread for smooth UI
- TypeScript with strict mode
- Zero external chess dependencies
- Perft-verified move generation
- FEN support for position import/export
- Node.js 18+
- npm or yarn
# Clone the repository
git clone <repository-url>
cd CHESSGAME
# Install dependencies
npm install
# Start development server
npm run devOpen http://localhost:5173 to play!
# Build optimized production bundle
npm run build
# Preview production build
npm run preview- Start a game: Choose your game mode and settings, then click "Start Game"
- Move pieces: Click on a piece to select it, then click on a highlighted square to move
- Drag & Drop: Alternatively, drag pieces to their destination
- Undo/Redo: Use the toolbar buttons or Ctrl+Z / Ctrl+Y
- Flip board: Press F or use the flip button to change perspective
| Key | Action |
|---|---|
F |
Flip board |
Ctrl+Z |
Undo move |
Ctrl+Y |
Redo move |
Ctrl+N |
New game |
CHESSGAME/
โโโ src/
โ โโโ engine/ # Chess engine core
โ โ โโโ board/ # Board representation
โ โ โ โโโ constants.ts # Board constants, square utilities
โ โ โ โโโ utils.ts # Board manipulation functions
โ โ โ โโโ fen.ts # FEN parsing and generation
โ โ โโโ moves/ # Move generation
โ โ โ โโโ generator.ts # Legal move generation
โ โ โ โโโ notation.ts # SAN/coordinate notation
โ โ โโโ evaluation/ # Position evaluation
โ โ โ โโโ evaluate.ts # Piece-square tables, scoring
โ โ โโโ search/ # Search algorithms
โ โ โ โโโ zobrist.ts # Zobrist hashing
โ โ โ โโโ transposition.ts# Transposition table
โ โ โ โโโ ordering.ts # Move ordering heuristics
โ โ โ โโโ search.ts # Alpha-beta search
โ โ โโโ ai/ # AI personality
โ โ โโโ difficulty.ts # Difficulty levels
โ โโโ game/ # Game state management
โ โ โโโ GameController.ts # Central game controller
โ โโโ worker/ # Web Worker integration
โ โ โโโ engine.worker.ts # Worker entry point
โ โ โโโ engineWrapper.ts # Promise-based wrapper
โ โโโ ui/ # React UI components
โ โ โโโ components/ # React components
โ โ โ โโโ ChessBoard.tsx # Canvas board component
โ โ โ โโโ StatusBar.tsx # Game status display
โ โ โ โโโ MoveHistory.tsx # Move list with navigation
โ โ โ โโโ AIAnalysis.tsx # Engine analysis panel
โ โ โ โโโ Settings.tsx # Game settings panel
โ โ โโโ hooks/ # React hooks
โ โ โโโ styles/ # CSS styles
โ โ โโโ App.tsx # Main application
โ โโโ types/ # TypeScript type definitions
โ โโโ tests/ # Test files
โ โโโ main.tsx # Application entry point
โโโ package.json
โโโ tsconfig.json
โโโ vite.config.ts
โโโ README.md
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage- Move generation tests - All piece movements, special moves
- Perft tests - Verify move generation accuracy
- FEN tests - Parsing and generation
- Evaluation tests - Material and positional scoring
- Search tests - Tactical positions, mate finding
- 64-element array (a1=0, h8=63)
- Null for empty squares, Piece objects for occupied
- Full position state including castling, en passant, clocks
- Pseudo-legal move generation with legality filtering
- Special move handling: castling, en passant, promotion
- Attack detection for check/checkmate
Alpha-Beta with Iterative Deepening
โโโ Transposition Table (Zobrist hashing)
โโโ Move Ordering
โ โโโ Hash move (from TT)
โ โโโ Captures (MVV-LVA)
โ โโโ Killer moves
โ โโโ History heuristic
โโโ Quiescence Search
โโโ Time Management
- Material counting (standard piece values)
- Piece-square tables (position-based bonuses)
- Mobility scoring
- King safety
- Pawn structure analysis
- Center control
- Zobrist hashing for fast position comparison
- Transposition table with replacement strategy
- Move ordering to maximize alpha-beta cutoffs
- Iterative deepening for time management
- Web Worker for non-blocking UI
const controller = new GameController();
// Start a new game
controller.startNewGame(GameMode.VS_COMPUTER, DifficultyLevel.MEDIUM, Color.WHITE);
// Make a move
controller.makeMove(move);
// Undo/Redo
controller.undo();
controller.redo();
// Subscribe to state changes
controller.subscribe(callback);import { parseFEN, positionToFEN } from './engine/board/fen';
const position = parseFEN('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1');
const fen = positionToFEN(position);Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Chess piece SVG designs inspired by standard Staunton pieces
- Perft test positions from the chess programming wiki
- Piece-square table values adapted from Tomasz Michniewski's work
Built with โค๏ธ using React + TypeScript + HTML5 Canvas