A fully-functional chess game built from scratch using Python and PyGame, featuring complete chess rule implementation, interactive GUI, and smooth animations.
- Features
- Demo
- Installation
- How to Play
- Technical Implementation
- Project Structure
- Controls
- Future Enhancements
- Contributing
- License
- ♟️ Complete Rule Implementation: All standard chess rules including piece movements, captures, and turn-based gameplay
- 👑 Special Moves:
- Pawn promotion (automatic queen promotion)
- En passant captures
- Castling (kingside and queenside)
- 🎯 Game State Detection: Real-time check, checkmate, and stalemate detection
- ✅ Move Validation: Prevents illegal moves and ensures king safety
- 🎨 Clean Visual Design: 512x512 pixel board with alternating white/gray squares
- 🖱️ Click-to-Move Interface: Intuitive point-and-click piece selection and movement
- 💡 Visual Feedback:
- Blue highlight on selected piece
- Yellow highlights showing all valid moves for the selected piece
- 🎬 Smooth Animations: Fluid piece movement transitions at 60 FPS
- 📝 Chess Notation: Displays algebraic notation for each move in console
- ⏮️ Undo Move: Press
Zto undo the last move - 🔄 Reset Game: Press
Rto start a new game - 🏁 Game Over Screen: Clear victory/draw messages on game completion
- 📊 Move History: Complete move log tracking throughout the game
The game provides an interactive chess experience where players can:
- Practice chess strategies in a virtual environment
- Visualize and predict moves with highlighted valid squares
- Learn chess rules through real-time validation feedback
- Analyze gameplay with move history and undo functionality
- Python 3.x
- PyGame library
-
Clone the repository
git clone https://github.com/s-cube-15/GUI-based-chess-engine.git cd GUI-based-chess-engine -
Install dependencies
pip install pygame
-
Run the game
python ChessMain.py
- Starting the Game: Run
ChessMain.pyto launch the chess board - Making Moves:
- Click on a piece to select it (blue highlight appears)
- Valid move squares are highlighted in yellow
- Click on a highlighted square to move the piece
- Click the same piece again to deselect
- Special Moves: The engine automatically handles pawn promotion, en passant, and castling when valid
- Game End: The game detects and announces checkmate or stalemate
The project follows object-oriented design principles with three main components:
- Manages the 8x8 board representation
- Tracks piece positions, turn order, and game status
- Implements move generation algorithms for all piece types
- Handles special move logic (castling rights, en passant)
- Detects check, checkmate, and stalemate conditions
- Encapsulates move information (start/end positions)
- Converts between array indices and chess notation
- Identifies special move types (promotion, en passant, castling)
- Provides move comparison and unique move ID generation
- Renders the game board and pieces using PyGame
- Handles user input (mouse clicks, keyboard commands)
- Implements move animations and visual highlights
- Manages game loop and display updates
- Move Generation: Piece-specific movement patterns with boundary checking
- Move Validation: Simulates moves to prevent king exposure to check
- Check Detection: Analyzes opponent attacks on king position
- Castling Logic: Validates empty squares and no-check path requirements
GUI-based-chess-engine/
├── ChessEngine.py # Core game logic and rules
├── ChessMain.py # GUI and game loop
├── images/ # Chess piece images (PNG format)
│ ├── wp.png # White Pawn
│ ├── wR.png # White Rook
│ ├── wN.png # White Knight
│ ├── wB.png # White Bishop
│ ├── wQ.png # White Queen
│ ├── wK.png # White King
│ ├── bp.png # Black Pawn
│ ├── bR.png # Black Rook
│ ├── bN.png # Black Knight
│ ├── bB.png # Black Bishop
│ ├── bQ.png # Black Queen
│ └── bK.png # Black King
└── README.md # Project documentation
| Key | Action |
|---|---|
| Mouse Click | Select piece / Make move |
| Z | Undo last move |
| R | Reset game (start new) |
Potential improvements for future versions:
- AI opponent with minimax algorithm and alpha-beta pruning
- Difficulty levels (Easy, Medium, Hard)
- Move timer and clock
- Save/load game functionality
- Move history display on GUI
- Custom piece themes and board colors
- Sound effects for moves and captures
- PGN (Portable Game Notation) export
- Online multiplayer support
- Opening book integration
Contributions are welcome! Feel free to:
- Fork the repository
- Create a 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 open source and available under the MIT License.
Sudhanshu Sabale
- GitHub: @s-cube-15
- LinkedIn: Sudhanshu Sabale
- Email: sudhanshussable2@gmail.com
- Chess piece images sourced from open chess resources
- Built as a learning project to understand game development and chess algorithms
- Inspired by the classic game of chess and Python's versatility
⭐ If you found this project helpful, please consider giving it a star! ⭐