A fully-featured chess game implementation in Python with an advanced computer opponent, comprehensive game rules, and a modern user interface.
- All standard piece movements (pawns, rooks, knights, bishops, queens, kings)
- Special moves:
- Castling (king-side and queen-side)
- En Passant capture
- Pawn Promotion to queen
- Check and checkmate detection
- Stalemate detection
- Draw conditions:
- Insufficient material
- Fifty-move rule
- Threefold repetition
- Multiple difficulty levels: Easy, Medium, Hard
- Minimax algorithm with Alpha-Beta pruning for efficient move search
- Piece-square tables for positional evaluation
- Move ordering (MVV-LVA) for optimal pruning
- Quiescence search to avoid horizon effect
- Iterative deepening for better time management
- Transposition table for position caching
- Real-time evaluation showing position advantage
- Clean, intuitive chessboard design
- Dashboard displaying:
- Current turn indicator
- Position evaluation bar
- Move history in algebraic notation
- Captured pieces
- Current opening name
- Legal move highlighting
- Smooth piece selection and movement
- Multiple game modes:
- Player vs Player
- Player vs Computer (multiple difficulties)
- Recognition of common chess openings:
- Italian Game
- Ruy Lopez
- Sicilian Defense
- French Defense
- Caro-Kann Defense
- Queen's Gambit
- King's Indian Defense
- English Opening
- Python 3.7 or higher
- pip (Python package installer)
pip install pygame numpypython3 __init__.pyOr:
python -m Chess- Run the game executable
- Select your preferred game mode:
- Player vs Player: Play against another human
- Player vs Computer: Challenge the computer opponent (select difficulty)
- Click on a piece to select it (must be your turn)
- Legal moves will be highlighted:
- Blue = normal move
- Green = capture
- Click on a highlighted square to move
- Click the selected piece again to deselect
- Z: Undo last move
- R: Return to main menu / Restart game
- ESC: Quit game
Classic chess where two players take turns on the same computer.
Challenge the computer opponent with three difficulty levels:
- Easy (Depth 2): Suitable for beginners
- Medium (Depth 3): Balanced challenge
- Hard (Depth 4): Strong opponent for experienced players
Chess/
|-- __init__.py # Main game loop and UI
|-- Game/
| |-- __init__.py # Board class and game state
| |-- Piece.py # Piece data structure
| |-- MoveGenerator.py # Move generation for all pieces
| |-- CheckFunctions.py # Check and pin detection
| +-- GameEndFunctions.py # Checkmate/stalemate detection
|-- ai.py # Computer opponent engine
|-- opening_book.py # Opening recognition
|-- tests.py # Comprehensive test suite
+-- images/ # Piece graphics
The computer opponent uses several advanced algorithms:
Searches the game tree to find the best move, using alpha-beta pruning to eliminate unnecessary branches and dramatically improve performance.
Evaluates positions based on:
- Material: Piece values (pawn=100, knight=320, bishop=330, rook=500, queen=900)
- Position: Piece-square tables reward good piece placement
- King Safety: Encourages castling and keeping king safe in middlegame
Prioritizes moves for better pruning:
- Captures (sorted by MVV-LVA)
- Promotions
- Special moves (castling)
Extends search in tactical positions to avoid the horizon effect, ensuring the engine doesn't miss obvious captures.
Caches previously evaluated positions to avoid redundant calculations.
Run the comprehensive test suite:
python3 tests.pyTests include:
- Checkmate detection (Fool's Mate)
- Stalemate detection
- Draw by insufficient material
- Computer opponent move generation
- Special moves (en passant, castling)
- Move undo functionality
- Evaluation function
The computer opponent can search:
- Easy: ~1,000 positions in <0.1s
- Medium: ~10,000 positions in ~0.5s
- Hard: ~50,000 positions in ~2-3s
Performance varies based on position complexity.
Recently added modules (integrated in next release):
- Chess Clock with multiple time controls (bullet, blitz, rapid, classical)
- Pawn promotion piece selection UI
- Save/load games in PGN format
- FEN position import/export
- Comprehensive settings system
- Statistics tracking with Elo rating
- Chess puzzle mode with 8+ tactical puzzles
- Game statistics (wins, losses, draws, rating history)
Future enhancements:
- Move animations
- Sound effects
- Tutorial mode for beginners
- Position analysis mode
- Game review/replay with navigation
- Multiple visual themes
- Last move highlighting
- Online multiplayer
- Chess engine UCI protocol support
- Extended opening book database
Chess piece graphics are used in accordance with standard chess piece designs.
Implementation based on standard chess programming techniques:
- Minimax algorithm
- Alpha-beta pruning
- Piece-square tables
- Move ordering heuristics
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
git clone https://github.com/yourusername/chess.git
cd chess
pip install -r requirements.txt
python3 tests.py # Run tests
python3 __init__.py # Run game- Added chess clock system with multiple time controls
- Implemented pawn promotion piece selection UI
- Added PGN save/load functionality
- Implemented FEN notation support for position import/export
- Created comprehensive settings system with persistence
- Added statistics tracking with Elo rating system
- Implemented chess puzzle mode with 8+ tactical puzzles
- Added game statistics dashboard tracking wins/losses/draws
- Added advanced computer opponent with multiple difficulty levels
- Implemented comprehensive dashboard with evaluation bar
- Added move history in algebraic notation
- Added captured pieces display
- Added opening book recognition
- Implemented all draw conditions
- Added comprehensive test suite
- Fixed castling rights bug
- Improved UI with better color scheme
- Basic chess rules implementation
- Check detection
- Special moves (castling, en passant, promotion)
- Simple GUI
Enjoy playing chess!
