An interactive chess application developed in Python using Pygame.
The project implements chess-piece movement, turn-based gameplay, captures, special moves, pawn promotion, check indication, and graphical interaction.
- Interactive 8×8 chess board
- White and black piece movement
- Turn-based gameplay
- Legal movement calculation for:
- Pawns
- Rooks
- Knights
- Bishops
- Queens
- Kings
- Piece selection and valid-move indicators
- Piece capture
- Captured-piece display
- Check indication
- Pawn promotion
- Castling
- En passant
- Game restart functionality
- Checkmate detection
- Stalemate detection
- Legal-move validation to prevent moves that leave the king in check
- King safety validation
- Castling validation through attacked squares
- Python
- Pygame
chess-pygame/
│
├── assets/
│ └── images/
│ └── chess piece images
│
├── images/
│ └── demo.png
│
├── chess.py
├── constant.py
├── requirements.txt
├── .gitignore
└── README.md
Clone the repository:
git clone https://github.com/azelthong/chess-pygame.git
Navigate into the project:
cd chess-pygameInstall the required dependency:
pip install -r requirements.txt
Run:
python chess.py
The application maintains the position and state of each chess piece and calculates available moves according to the movement rules of the selected piece.
Pygame is used for:
- Rendering the chess board
- Displaying chess pieces
- Processing mouse input
- Highlighting available moves
- Displaying captured pieces
- Indicating check
- Handling game interaction
The project includes implementations for:
The game tracks whether the king and rooks have moved and determines whether the required squares are available for castling.
Pawn movement state is tracked to determine when an en-passant capture is available.
When a pawn reaches the opposite side of the board, the player can promote it to:
- Queen
- Rook
- Bishop
- Knight
Through this project, I gained experience with:
- Python game development
- Pygame
- Game-state management
- Event-driven programming
- Movement-validation algorithms
- Coordinate-based logic
- Managing interactions between graphical interfaces and application state
- Implementing rule-based systems
Potential improvements include:
- Move history
- Undo functionality
- Chess notation
- Computer opponent
- Improved user interface
- Unit tests for movement logic
Azel Thong
