A complete chess game implementation in Python with GUI and AI player.
- Complete chess rule implementation with all legal moves
- Special moves: castling, en passant, pawn promotion
- Chess AI with minimax algorithm and alpha-beta pruning
- Position evaluation based on material and strategic factors
- Network multiplayer over local network (LAN)
- Local multiplayer on the same computer
- Game state detection (checkmate, stalemate, draw conditions)
- Simple and clean GUI using Pygame
- Python 3.6+
- Pygame 2.5.2+
- Clone this repository or download the source code.
- Install the required dependencies:
pip install -r requirements.txt
Run the game with:
python main.py
The game offers three playing modes:
- Singleplayer - Play against the AI with three difficulty levels
- Local Multiplayer - Play against a friend on the same computer
- Network Multiplayer - Play against a friend over a local network
To play over a local network:
- Select "Network Multiplayer" from the main menu
- Click "Host Game"
- Your computer will start both a server and act as a client
- Tell your friend your IP address to connect to
- Select "Network Multiplayer" from the main menu
- Click "Join Game"
- Enter the IP address of the host computer
- Click "Connect"
You can also run a dedicated server (without GUI) on a computer:
python main.py --server
This will display the server's IP address which players can connect to.
- Click on a piece to select it
- Click on a highlighted square to move the selected piece
- The game automatically checks for valid moves, check, checkmate, and stalemate
- White plays first, followed by the AI (black)
main.py- Main entry pointfixed_menu.py- Menu system with multiple game modeschess_game/- Main package containing game logicgame.py- Game loop and UI managementboard.py- Chess board representation and game rulespieces.py- Individual chess piece classes and movement rulesplayer.py- Player base classai.py- AI implementation with minimax and position evaluationconstants.py- Game constants and evaluation tablesnetwork.py- Network multiplayer implementationnetwork_game.py- Network game management
assets/- Directory for piece images
The AI uses a minimax algorithm with alpha-beta pruning to search for the best move. It evaluates positions based on:
- Material count - Basic piece values
- Piece position - Positional tables for each piece type
- King safety - Evaluation of king's safety including castling and pawn shield
- Pawn structure - Evaluation of pawn formations including doubled pawns, isolated pawns, and passed pawns
- Mobility - Count of available legal moves
The game looks for chess piece images in the assets directory. If you want to add your own piece images:
- Create PNG images for each piece with these filenames:
- White pieces: wP.png, wR.png, wN.png, wB.png, wQ.png, wK.png
- Black pieces: bP.png, bR.png, bN.png, bB.png, bQ.png, bK.png
- Place them in the assets/ directory
If no images are found, the game will use text-based pieces as a fallback.
This project is available under the MIT License.