This project is a modern chess game built with Next.js, React, TypeScript, pnpm, and ESLint. It features full chess gameplay, including check, checkmate, stalemate, piece promotion, and AI opponent powered by chess-api.com.
- Full gameplay: Check, checkmate, stalemate, and complete move validation.
- AI Opponent: Play against a remote chess engine powered by chess-api.com with Stockfish 17 NNUE.
- Smart Bot Logic: Bot automatically determines its color based on your first move.
- Piece promotion: Choose which piece to promote to (coming soon: popup for all options).
- Drag-and-drop: Move pieces intuitively with drag-and-drop interface.
- Sound effects: Audio feedback for moves, captures, check, and game end.
- Loading indicators: Visual feedback while the bot calculates its move.
- Error handling: Graceful handling of API errors with automatic reconnection.
- Responsive design: Works seamlessly on desktop and mobile devices.
- Configurable AI: Adjust bot strength and behavior via environment variables.
The chess bot is powered by chess-api.com, providing access to Stockfish 17 NNUE calculation power with up to 80 MNPS performance.
- Remote Engine: No local CPU usage for chess calculations
- Configurable Strength: Adjust search depth (1-18) for different difficulty levels
- Real-time Analysis: Progressive move evaluation via WebSocket connection
- Automatic Reconnection: Handles network issues gracefully with retry logic
- Smart Color Detection: Bot plays opposite color of your first move
Bot behavior can be customized via environment variables in .env.local:
# Chess API Configuration
NEXT_PUBLIC_CHESS_API_URL=wss://chess-api.com/v1
NEXT_PUBLIC_CHESS_API_DEPTH=12 # 1-18 (12 ≈ 2350 elo)
NEXT_PUBLIC_CHESS_API_VARIANTS=1 # 1-5 variant lines
NEXT_PUBLIC_CHESS_API_MAX_THINKING_TIME=50 # 1-100 milliseconds
NEXT_PUBLIC_CHESS_API_MAX_RECONNECTS=3 # Retry attempts- Depth 12: ~2350 FIDE elo (International Master level)
- Depth 18: ~2750 FIDE elo (Grandmaster level)
- Depth 20: ~2850 FIDE elo (Super-GM level)
- Next.js – Full-stack React framework for SSR, static export, and routing.
- React – UI library for building interactive interfaces.
- TypeScript – Type safety and better developer experience.
- pnpm – Fast, efficient package management.
- ESLint – Code quality and consistency.
- chess-api.com – Remote Stockfish 17 NNUE engine for AI opponent.
- Move Detection: After user makes a move, bot color is determined
- FEN Generation: Current board position converted to FEN notation
- API Request: Position sent to chess-api.com via WebSocket
- Move Calculation: Stockfish evaluates position at configured depth
- Response Parsing: Best move received in long algebraic notation (LAN)
- Move Execution: Bot's move applied to board with sound effects
- Error Handling: Connection issues handled with automatic retry logic
- Automatic Reconnection: Up to 3 retry attempts with exponential backoff
- User Notification: Clear feedback when API is unavailable
- Graceful Degradation: Game continues in human-vs-human mode if API fails
- Future Enhancement: Local Stockfish fallback (planned)
-
Enhanced AI Features:
- ✅ Remote engine integration via chess-api.com
- ✅ Configurable bot strength and behavior
- ✅ Smart color detection and loading indicators
- ⏳ Local Stockfish fallback for offline play
- ⏳ Multiple AI personality modes
-
Game Features:
- Castling logic (implemented in engine)
- Piece promotion popup (enhanced UI)
- En passant (implemented in engine)
- Enhanced endgame screen
- Move history and analysis
-
Multiplayer & Social:
- Online multiplayer (planned)
- User accounts and authentication
- Game analysis and review
- Rating system
-
UI/UX Improvements:
- Better accessibility
- Smooth animations
- Themes and customization
- Mobile optimizations
To run this project locally:
-
Clone the repository:
git clone https://github.com/notdutra/Chess-game.git cd Chess-game -
Install dependencies:
pnpm install
-
Configure environment (optional): Create a
.env.localfile to customize bot behavior:cp .env.local.example .env.local # Edit values as needed -
Run the development server:
pnpm run dev
-
Open the app: Visit http://localhost:3000 in your browser.
- Start a new game - the game defaults to AI mode
- Make your first move - the bot will automatically play the opposite color
- Watch the "Bot is thinking..." indicator while it calculates
- The bot will respond automatically after each of your moves
Bot not responding:
- Check browser console for WebSocket connection errors
- Verify internet connection (bot requires chess-api.com access)
- Try refreshing the page to reconnect
Performance issues:
- Lower
NEXT_PUBLIC_CHESS_API_DEPTHin.env.localfor faster responses - Increase
NEXT_PUBLIC_CHESS_API_MAX_THINKING_TIMEfor stronger play
| Variable | Default | Description |
|---|---|---|
NEXT_PUBLIC_CHESS_API_URL |
wss://chess-api.com/v1 |
WebSocket endpoint for chess API |
NEXT_PUBLIC_CHESS_API_DEPTH |
12 |
Search depth (1-18, higher = stronger) |
NEXT_PUBLIC_CHESS_API_VARIANTS |
1 |
Number of variant lines (1-5) |
NEXT_PUBLIC_CHESS_API_MAX_THINKING_TIME |
50 |
Max thinking time in ms (1-100) |
NEXT_PUBLIC_CHESS_API_MAX_RECONNECTS |
3 |
Max reconnection attempts |
This app is ready for deployment on Vercel:
- Build Command:
pnpm run buildornext build - Install Command:
pnpm install - Output Directory: (leave blank for Next.js default)
Contributions are welcome! Whether you’re fixing bugs, adding features, or improving documentation, your help is appreciated.
- Fork the repository
- Clone your fork
- Create a new branch
- Make your changes
- Commit and push
- Open a Pull Request
- Discuss and review
All contributors are expected to follow the Code of Conduct to ensure a welcoming and respectful environment.