Welcome to the Custom Python Chess Engine! This project is a fully functional chess application developed in Python. It features a complete set of chess rules, a graphical user interface (GUI) built with Pygame, and an integrated AI opponent that uses advanced search algorithms to play against you.
- Complete Move Generation: Supports all standard piece movements.
- Advanced Rules: Fully implements Castling, En Passant, and automatic Pawn Promotion.
- Game States: Accurate detection of Checks, Checkmates, and Stalemates.
- Move Log: A dedicated panel that records and displays the move history using standard algebraic chess notation.
- Pygame-based UI: Clean, responsive, and interactive 2D chessboard.
- Square Highlighting: Highlights the currently selected piece and shows all its valid destination squares to assist the player.
- Smooth Animations: Pieces glide smoothly across the board when a move is executed.
- Keyboard Controls:
- Press
zto undo the last move. - Press
rto reset the board and start a new game.
- Press
- NegaMax with Alpha-Beta Pruning: The engine uses an optimized NegaMax search algorithm coupled with Alpha-Beta pruning to evaluate positions efficiently and choose the best moves.
- Multiprocessing: The AI calculates its moves on a separate background process. This ensures the GUI remains completely responsive while the AI is "thinking," allowing you to interact with the board or undo moves seamlessly.
ChessMain.py: The entry point of the application. Handles the Pygame GUI, user inputs, and multiprocessing for the AI.ChessEngine.py: The core backend. Manages the game state, validates moves, and enforces chess rules.smartmovefinder.py: The AI module. Contains the scoring functions and NegaMax alpha-beta search algorithms.
- Game State Management: The board is represented as a 2D list.
ChessEngine.pyevaluates the board state to generate valid moves based on whose turn it is, considering checks and pins. - Move Processing: When a player clicks to move a piece, the move is validated against the generated list. If valid, the move is applied, and turn control switches.
- AI Integration: When it's the AI's turn,
ChessMain.pyspawns a background process that callssmartmovefinder.py. The AI evaluates future possible board states up to a certain depth (default is depth 4), scoring them based on material advantages. The best found move is then passed back to the main thread via a queue and executed on the board.
- Python 3.x: Make sure you have Python installed on your system.
- Pygame: This project requires the Pygame library for rendering the UI.
- Clone the repository or download the project files.
- Open your terminal or command prompt.
- Install Pygame (if you haven't already):
pip install pygame
- Run the main application file:
python project_files/ChessMain.py
Enjoy playing against the engine or studying the move generations!