Author: Sepehr Bayat
A complete, open-source chess game built with Python and Pygame. Features move quality evaluation, AI opponent with minimax algorithm, and a clean, modular architecture. Perfect for learning chess programming, AI algorithms, and game development.
- Complete Chess Rules: All standard chess rules including special moves (castling, en passant, pawn promotion)
- Move Quality Scoring: Each move is evaluated and assigned a score from 0-100 based on material balance, position quality, and move impact
- Visual Feedback: Highlighted valid moves and selected pieces
- Game Status: Real-time display of check, checkmate, and stalemate conditions
- AI Opponent: Play against computer with minimax algorithm and alpha-beta pruning
- Multiple Game Modes:
- User vs User (two players)
- User vs AI (play as white or black)
- AI vs AI (watch computer play)
- High-Quality Piece Graphics: Beautifully drawn chess pieces with shadows and highlights
- Custom Piece Images: Support for custom piece images (falls back to drawn pieces if not available)
- Clean Architecture: Object-oriented design with separate classes for pieces, board, game logic, AI, and evaluation
- Python 3.7 or higher
- Pygame 2.5.0 or higher
- PyInstaller 6.0.0 or higher (optional, for building executable)
-
Clone the repository
git clone https://github.com/sepehrbayat/simple-chess-opensource.git cd simple-chess-opensourceOr download the ZIP file from the repository page and extract it.
-
Run the setup script:
- PowerShell:
.\setup.ps1 - Command Prompt:
setup.bat
This will:
- Check for Python installation
- Create a virtual environment
- Install all dependencies
- PowerShell:
-
Install Python 3.7+ from python.org
- Make sure to check "Add Python to PATH" during installation
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- Windows (PowerShell):
.\venv\Scripts\Activate.ps1 - Windows (CMD):
venv\Scripts\activate.bat - Linux/Mac:
source venv/bin/activate
- Windows (PowerShell):
-
Install dependencies:
pip install -r requirements.txt
Using the run script:
- PowerShell:
.\run.ps1 - Command Prompt:
run.bat
Or manually:
python main.pyTo create a standalone .exe file using PyInstaller:
pyinstaller --onefile --windowed --name ChessMVP main.pyThe executable will be created in the dist folder.
With icon:
pyinstaller --onefile --windowed --icon=icon.ico --name ChessMVP main.py-
Select Game Mode: When the game starts, choose your preferred game mode:
- User vs User: Play against another person
- User vs AI (White): You play as white, computer plays as black
- User vs AI (Black): You play as black, computer plays as white
- AI vs AI: Watch two computer players compete
-
Select a Piece: Click on one of your pieces (white moves first)
-
Make a Move: Click on a highlighted square to move the selected piece
-
Move Score: After each move, the quality score (0-100) is displayed in the side panel
-
Game Status: The panel shows the current turn, game status (check/checkmate/stalemate), and move scores
-
Quit: Press ESC to exit the game
The move evaluation system assigns scores based on:
- Material Balance (0-90 points): Value of captured pieces
- Position Quality (0-20 points): Center control and piece activity
- Move Impact (0-15 points): Checks, threats, and strategic value
Score Interpretation:
- 81-100: Excellent move (major capture, check, strong threat)
- 61-80: Good move (gains material, improves position)
- 31-60: Neutral move
- 0-30: Poor move (loses material, weakens position)
The AI uses a minimax algorithm with alpha-beta pruning to find the best moves. The default search depth is 3, which provides a good balance between skill and speed.
simple-chess-opensource/
โโโ chess/
โ โโโ __init__.py
โ โโโ game.py # Game class (main loop, rendering, menu)
โ โโโ board.py # Board class (grid, state management)
โ โโโ pieces.py # Piece base class + 6 subclasses
โ โโโ evaluator.py # Evaluator class (heuristic scoring)
โ โโโ ai.py # AI engine (minimax algorithm)
โ โโโ menu.py # Game mode selection menu
โ โโโ piece_images.py # Piece image loader and renderer
โ โโโ constants.py # Colors, dimensions, Unicode symbols
โโโ assets/
โ โโโ README.md # Instructions for adding custom piece images
โโโ main.py # Entry point
โโโ requirements.txt # Python dependencies
โโโ setup.ps1 # PowerShell setup script
โโโ setup.bat # Batch setup script
โโโ run.ps1 # PowerShell run script
โโโ run.bat # Batch run script
โโโ LICENSE # MIT License
โโโ README.md # This file
The project uses a modular OOP architecture:
- Piece Hierarchy: Base
Piececlass with 6 subclasses (Pawn, Rook, Knight, Bishop, Queen, King) - Board: Manages game state, move validation, and check/checkmate detection
- Evaluator: Calculates move quality scores using heuristic evaluation
- AI Engine: Implements minimax algorithm with alpha-beta pruning for computer player
- Game: Handles Pygame main loop, event handling, UI rendering, and game mode management
- Menu: Provides game mode selection interface
- Piece Images: Loads custom images or generates high-quality drawn pieces
You can add your own chess piece images to the assets/ folder. See assets/README.md for details.
Required files:
wp.png,wn.png,wb.png,wr.png,wq.png,wk.png(white pieces)bp.png,bn.png,bb.png,br.png,bq.png,bk.png(black pieces)
If images are not provided, the game will use beautifully drawn pieces with shadows and highlights.
Run the test suite:
python test_chess.pyThis project is licensed under the MIT License - see the LICENSE file for details.
Sepehr Bayat
- Email: sepehrbayat5@gmail.com
- Telegram: @bayatsepehr
- LinkedIn: linkedin.com/in/sepehrbayat
- GitHub: @sepehrbayat
Current version: 1.0.0
If you find this project useful, please consider giving it a โญ on GitHub!
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
See CHANGELOG.md for a list of changes and version history.
- Pygame community for the excellent game development library
- Chess.com for inspiration and chess rules reference
- Open source community for continuous support and feedback
Sepehr Bayat
- Email: sepehrbayat5@gmail.com
- Telegram: @bayatsepehr
- LinkedIn: linkedin.com/in/sepehrbayat
- GitHub: @sepehrbayat
Project Links:
- Repository: simple-chess-opensource
- Issues: Report a Bug
- Discussions: Join the Discussion
Made with โค๏ธ and Python | Enjoy playing Simple Chess! ๐ฎโ๏ธ