PyChess is a classic chess game built with Python and the Pygame library. It provides a fully functional 2D chess board where two players can compete. The game enforces standard chess rules, including move validation, check, checkmate, and stalemate conditions.
- Complete Chess Logic: Implements movement rules for all standard pieces: Pawns, Rooks, Knights, Bishops, Queens, and Kings.
- Move Validation: Automatically highlights all legal moves for a selected piece.
- Check and Checkmate Detection: The game visually indicates when a King is in check and can determine checkmate or stalemate to end the game.
- Pawn Promotion: Pawns are automatically promoted to Queens upon reaching the opposite end of the board.
- Intuitive UI: A simple, clickable interface for selecting and moving pieces.
- Game Over Screen: Displays the result of the game (win/loss/draw).
The game is structured into several modules that handle different aspects of the gameplay:
main.py: The entry point of the application. It contains the main game loop, handles user input (mouse clicks), manages the game state (turns, game over conditions), and orchestrates the drawing of all elements on the screen.Sprites.py: Defines thePieceandSquareclasses, which are the core visual components of the game. It manages their appearance, position, and interactions on the board.Move_Analyzer.py: The brain of the game. This module contains all the logic for calculating valid moves for each piece. It performs threat analysis to determine which squares are under attack, which is crucial for check detection and ensuring a move does not leave the King in check.Constants.py: Holds the initial starting positions of all pieces on the chessboard.Assets/: This directory contains all the image files for the chess pieces and the board squares.
To run the game on your local machine, follow these steps.
- Python 3.x
- Pygame
-
Clone the repository:
git clone [https://github.com/ErenKeles0/PyChess.git](https://github.com/ErenKeles0/PyChess.git) cd PyChess -
Install Pygame:
pip install pygame
-
Run the game:
python Scripts/main.py
- Select a Piece: Click on one of your pieces. Legal moves will be highlighted with dots.
- Move a Piece: Click on one of the highlighted squares to move your selected piece to that location.
- Deselect a Piece: If you want to choose a different piece, simply click on an invalid square or another one of your own pieces.
- The game starts with White's turn. Play continues until one player achieves checkmate or the game ends in a stalemate.