A Python-based Chess implementation featuring multiple game modes and AI opponents using the Minimax algorithm with Alpha-Beta pruning. The project includes a graphical user interface built with Pygame and supports different gameplay modes with varying levels of AI optimization.
- Multiple Game Modes:
- Human vs Human: Play against another person on the same computer
- Human vs AI: Play against a computer opponent with adjustable difficulty
- AI vs AI (CPU): Watch two AI opponents battle it out using CPU-optimized algorithms
- AI vs AI (GPU): Experience faster gameplay with GPU-accelerated AI moves
- Advanced AI: Utilizes the Minimax algorithm with Alpha-Beta pruning for smart move selection
- Performance Optimizations:
- CPU-optimized implementation using Numba JIT compilation
- GPU-accelerated version for faster move calculations
- Clean GUI: Simple and intuitive graphical interface built with Pygame
- Standard Chess Rules: Implements all standard chess rules and piece movements
- Python 3.7 or higher
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/yourusername/Chess-minimax.git cd Chess-minimax -
Install the required dependencies:
pip install -r requirements.txt
Play against another person on the same computer.
python chess-human-vs-human.pyPlay against the computer AI. Choose your color and test your skills!
python chess_human_vs_ai.pyWatch two AI opponents battle it out using CPU-optimized algorithms.
python chess_minimax.pyExperience faster gameplay with GPU-accelerated AI moves.
python chess_gui_withgpu.py- Left-click: Select and move pieces
- Right-click: Deselect a piece
- ESC: Exit the game
The AI opponents use the following algorithms and optimizations:
- Minimax Algorithm: For decision making
- Alpha-Beta Pruning: To optimize the search space
- Position Evaluation: Custom evaluation function with piece-square tables
- Move Ordering: Sorts moves to improve alpha-beta pruning efficiency
-
CPU Version:
- Numba JIT compilation for CPU acceleration
- Optimized move generation
- Efficient board representation using NumPy arrays
-
GPU Version:
- CUDA acceleration for parallel move evaluation
- Optimized for NVIDIA GPUs with CUDA support
- Significantly faster move calculations for deeper search depths
Chess-minimax/
├── pieces/ # Chess piece images
│ ├── black/ # Black pieces
│ └── white/ # White pieces
├── chess_minimax.py # AI vs AI (CPU) implementation
├── chess_human_vs_ai.py # Human vs AI game mode
├── chess-human-vs-human.py # Human vs Human game mode
├── chess_gui_withgpu.py # AI vs AI (GPU-accelerated) implementation
├── chess_gui.py # Shared GUI components
└── requirements.txt # Python dependencies
pygame: For the graphical user interfacenumpy: For efficient array operationsnumba: For JIT compilation and performance optimizationasyncio: For asynchronous operations
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Chess piece images from public domain sources
- Inspired by various open-source chess implementations