A chess game implementation with a built-in AI opponent.
- Play chess against a built-in AI opponent
- Choose to play as white or black pieces
- Undo moves
- Restart game at any time
- Move history tracking
- Visual move highlighting
- Modern and clean UI
- Proper chess piece movement rules
- Turn-based gameplay
- Open
index.html
in your web browser - Choose your color:
- Click "Play as White" to move first
- Click "Play as Black" to let AI move first
- On your turn:
- Click on one of your pieces to select it
- Valid moves will be highlighted in green
- Click on a highlighted square to make your move
- The AI will automatically make its move after you
- Use the controls:
- "Undo Move" to take back your last move
- "Restart Game" to start a new game
- Standard chess piece movements:
- Pawns: Forward one square (or two on first move), capture diagonally
- Rooks: Any number of squares horizontally or vertically
- Knights: L-shaped movement (two squares in one direction, one square perpendicular)
- Bishops: Any number of squares diagonally
- Queens: Any number of squares in any direction
- Kings: One square in any direction
- White always moves first
- Players take turns moving one piece at a time
- Pieces capture by moving to an opponent's square
The AI makes decisions based on:
- Material value (pawns=1, knights/bishops=3, rooks=5, queens=9)
- Position evaluation:
- Capturing opponent pieces
- Controlling the center
- Advancing pawns
- Strategic positioning
- Includes some randomness for varied gameplay
- Built with vanilla JavaScript
- No external dependencies or API keys required
- Responsive design
- Unicode chess pieces
- Lightweight and fast
- Check and checkmate detection
- Special moves (castling, en passant)
- Pawn promotion
- More sophisticated AI strategy
- Game end conditions
- Save/load game state
MIT License