A beautiful, feature-rich chess game with AI opponent powered by Stockfish
Train against 7 difficulty levels โข Real-time move analysis โข Professional move ratings
๐ Quick Start โข ๐ Features โข ๐ฎ Controls โข โ๏ธ Setup
- 7 Difficulty Levels: From complete beginner to grandmaster strength
- Powered by Stockfish: World's strongest chess engine
- Adaptive Thinking Time: 0.1s to 5s based on difficulty
- Dynamic Level Switching: Change difficulty mid-game
- Real-time Evaluation: Every move is analyzed and rated
- Professional Ratings:
- โญโญโญ Brilliant - Outstanding moves
- โญโญ Great - Excellent moves
- โญ Good - Solid moves
- โโ Inaccuracy - Minor mistakes
- โ Mistake - Significant errors
- โโ Blunder - Major mistakes
- Score Evaluation: See how each move affects your position
- Modern Design: Clean, professional chess board
- Move History Panel: Complete game notation with ratings
- Visual Highlights: Last move, selected piece, legal moves
- Coordinate Labels: File and rank indicators
- Responsive UI: Smooth animations and feedback
- Complete Chess Rules: All standard chess rules implemented
- Automatic Promotion: Pawns promote to queen (customizable)
- Check Detection: Visual and textual check indicators
- Game Over Detection: Checkmate, stalemate, and draw conditions
- Move Validation: Only legal moves allowed
-
Install Dependencies
pip install pygame python-chess
-
Install Stockfish
- Windows: Download from stockfishchess.org and add to PATH
- Mac:
brew install stockfish - Linux:
sudo apt install stockfishorsudo pacman -S stockfish
-
Run the Game
python main.py
-
Choose Your Challenge
- Select AI difficulty level
- Start playing as White
- Watch your moves get rated in real-time!
| Key | Action |
|---|---|
| Mouse Click | Select piece / Make move |
| R | Restart game |
| L | Change AI difficulty level |
| ESC | Quit game |
- Select a Piece: Click on your piece (White)
- See Legal Moves: Available moves highlighted in yellow
- Make Your Move: Click destination square
- Watch AI Respond: AI thinks and makes its move
- Analyze: See move ratings and evaluations in real-time
- Python 3.8 or higher
- Pygame 2.0+
- python-chess library
- Stockfish engine
git clone https://github.com/KaTOxDev/PlayChessWithAI.git
cd PlayChessWithAIpip install pygame python-chessWindows:
- Download Stockfish from stockfishchess.org
- Extract to a folder (e.g.,
C:\stockfish\) - Add to PATH or place executable in project folder
macOS:
brew install stockfishLinux (Ubuntu/Debian):
sudo apt update
sudo apt install stockfishLinux (Arch):
sudo pacman -S stockfishFor premium visuals, create a chess/ folder and add PNG files:
chess/
โโโ white_pawn.png
โโโ white_rook.png
โโโ white_knight.png
โโโ white_bishop.png
โโโ white_queen.png
โโโ white_king.png
โโโ black_pawn.png
โโโ black_rook.png
โโโ black_knight.png
โโโ black_bishop.png
โโโ black_queen.png
โโโ black_king.png
Note: Game works perfectly with built-in text pieces if images aren't provided
| Level | Name | Think Time | Depth | Strength |
|---|---|---|---|---|
| 1 | Beginner | 0.1s | 5 | ~800 ELO |
| 2 | Easy | 0.2s | 8 | ~1200 ELO |
| 3 | Medium | 0.5s | 10 | ~1600 ELO |
| 4 | Hard | 1.0s | 12 | ~2000 ELO |
| 5 | Expert | 2.0s | 15 | ~2400 ELO |
| 6 | Master | 3.0s | 18 | ~2800 ELO |
| 7 | Grandmaster | 5.0s | 20 | ~3200+ ELO |
- Board Colors: Professional tournament colors
- Piece Highlighting: Selected pieces shown in green
- Legal Move Indicators: Yellow highlights for valid moves
- Last Move Display: Orange highlights for previous move
- Check Warnings: Visual and text indicators
The game uses Stockfish's evaluation to rate every move:
- Evaluation Depth: 12 moves ahead for accurate analysis
- Score Tracking: Position evaluation in centipawns
- Rating Algorithm: Compares move quality to best possible moves
- Real-time Feedback: Instant move ratings as you play
- Human vs AI: Play against Stockfish
- Analysis Mode: Review and learn from your games
- Difficulty Progression: Start easy and work your way up
โ "Stockfish engine not found"
- Ensure Stockfish is installed and in your system PATH
- Try placing stockfish executable in the same folder as the game
โ "No module named 'pygame'"
pip install pygame python-chessโ Game runs but pieces look like text
- This is normal! Add PNG images to
chess/folder for better graphics - Game is fully functional with text pieces
โ AI takes too long to move
- Lower the difficulty level
- Ensure you're not running other CPU-intensive programs
- Slow Computer? Use levels 1-3 for faster gameplay
- Want Challenge? Levels 5-7 provide tournament-strength opposition
- Learning? Level 3-4 is perfect for intermediate players
- Move Ratings Help: Learn what makes moves good or bad
- Pattern Recognition: See how the AI responds to different positions
- Mistake Analysis: Understand your blunders and inaccuracies
- Progress Tracking: Challenge higher difficulties as you improve
- Opening Principles: AI demonstrates sound opening play
- Tactical Awareness: Spot tactical motifs through AI play
- Endgame Technique: Learn proper endgame technique
- Positional Understanding: See how small advantages accumulate
- Engine: Stockfish 15+ compatible
- GUI Framework: Pygame
- Chess Logic: python-chess library
- Move Generation: Full legal move validation
- Position Evaluation: Stockfish UCI protocol
- Threading: Non-blocking AI calculations
- Performance: 60 FPS smooth gameplay
- Opening Book: Common opening variations
- Time Controls: Blitz, rapid, and classical time formats
- Game Database: Save and replay games
- Multiple Themes: Different board and piece sets
- Sound Effects: Audio feedback for moves
- Online Play: Challenge friends remotely
- Tournament Mode: Multi-game matches
- Puzzle Mode: Tactical training exercises
We welcome contributions! Whether it's:
- ๐ Bug fixes
- โจ New features
- ๐จ UI improvements
- ๐ Documentation
- ๐งช Testing
Feel free to open issues and pull requests!
This project is open source and available under the MIT License.
Made with โค๏ธ for chess enthusiasts
Train โข Play โข Improve โข Master
โญ Star this repo if you enjoyed playing! โญ