A feature-rich and extensible Python chess game with local, online, and AI modes.
Python Multiplayer Chess is a comprehensive chess game implemented in Python using the Pygame library. It supports local multiplayer, online gameplay, and an AI opponent powered by the Stockfish chess engine. The project aims to provide a clean, modular, and extensible codebase, making it suitable for both playing and learning about game development.
- Local Multiplayer: Play against a friend on the same computer.
- Online Gameplay: Challenge other players online.
- AI Opponent: Test your skills against the Stockfish chess engine.
- Customizable Timers: Set time limits for games.
- User Preferences: Customize the game's appearance and behavior.
- Clean and Modular Codebase: Easy to understand and extend.
- Chess enthusiasts looking for a digital version of the game.
- Python developers interested in game development.
- Students learning about AI and game programming.
- Multi-Mode Gameplay: Offers local, online, and AI modes in one application.
- Extensible Architecture: Designed for easy modification and addition of new features.
- Well-Documented Code: Includes detailed comments and documentation to aid understanding.
- Stockfish Integration: Provides a strong AI opponent for challenging gameplay.
- Python 3.6+
- Pygame 2.0+
- Stockfish (for AI opponent)
-
Clone the repository:
git clone https://github.com/muhammadhamzagova666/multiplayer-chess-game.git cd multiplayer-chess-game
-
Install dependencies:
pip install -r requirements.txt
Create a
requirements.txt
file with the following content:pygame>=2.0 # Add any other dependencies here
-
Configure Stockfish (Optional):
-
Download and install the Stockfish chess engine for your operating system from the Stockfish website.
-
Update the path to the Stockfish executable in
res/stockfish/path.txt
. The game provides instructions for setting this up, as seen in loader.py. -
Example
res/stockfish/path.txt
(Linux):/usr/games/stockfish
-
Example
res/stockfish/path.txt
(Windows):C:\\Stockfish\\stockfish.exe
-
-
Run the game:
python Source/pychess.py
- Main Menu: Use the main menu to select game modes (Local, Online, AI), configure preferences, and adjust timer settings.
- Local Multiplayer: Select "Local" from the main menu and start playing.
- Online Gameplay:
- Select "Online" from the main menu.
- Enter the server address and port.
- Connect to the server and wait for an opponent.
- AI Opponent: Select "AI" from the main menu to play against Stockfish.
- Preferences: Customize game settings such as sound, board orientation, and move highlighting via the preferences menu.
PyChessMP/
├── Multiplayer Chess Game Project Proposal.docx
├── Multiplayer Chess Game Project Proposal.pdf
├── Multiplayer Chess Game Project Report.docx
├── Source/
│ ├── chess/
│ │ ├── __init__.py
│ │ ├── lib/
│ │ │ ├── __init__.py
│ │ │ ├── core.py # Core chess logic (move generation, validation)
│ │ │ ├── gui.py # Pygame-based GUI implementation
│ │ │ └── utils.py # Utility functions (encoding, decoding, board setup)
│ │ ├── multiplayer.py # Local multiplayer game logic
│ │ ├── online.py # Online game logic
│ │ └── onlinelib/ # Networking utilities for online play
│ ├── ext/
│ │ └── pyBox.py # Custom text box for user input
│ ├── menus/
│ │ ├── __init__.py
│ │ ├── online.py # Online menu implementation
│ │ ├── pref.py # Preferences menu implementation
│ │ └── timer.py # Timer menu implementation
│ ├── pychess.py # Main application entry point
│ ├── res/
│ │ ├── Asimov.otf # Font file
│ │ ├── img/ # Image resources
│ │ ├── preferences.txt # User preferences file
│ │ ├── sounds/ # Sound resources
│ │ └── texts/ # Text resources (instructions, messages)
│ ├── server.py # Server-side code for online play
│ └── tools/
│ ├── loader.py # Resource loading module
│ ├── sound.py # Sound management module
│ └── utils.py # General utility functions
├── tools/
│ ├── loader.py
│ └── sound.py
└── README.md
Source/chess/lib/core.py
: Contains the core chess logic, including move generation, validation, and game state management.Source/chess/lib/gui.py
: Implements the graphical user interface using Pygame.Source/chess/lib/utils.py
: Provides utility functions for encoding moves, initializing the board, and other helper tasks.Source/pychess.py
: The main entry point of the application, responsible for initializing Pygame, loading resources, and managing the main game loop.- menus: Contains the implementation of the various menus in the game, such as the online menu, preferences menu, and timer menu.
- res: Stores all the resources used by the game, including images, sounds, fonts, and text files.
- tools: Contains helper modules for loading resources and managing sound.
-
res/preferences.txt
: Stores user preferences such as sound settings, board orientation, and move highlighting. See pref.py for how these preferences are managed. -
res/stockfish/path.txt
: Specifies the path to the Stockfish executable. -
Environment Variables (for online play):
CHESS_SERVER_HOST=localhost CHESS_SERVER_PORT=5000
Instructions for deploying the project (e.g., Docker, Kubernetes, cloud services). CI/CD integration steps if applicable.
-
Unit Tests: (Example using
pytest
)pip install pytest pytest tests/
-
Debugging Tips:
- Enable debug mode in the preferences menu.
- Check the console output for error messages.
- Use the built-in move validation to verify move legality.
- Surface Caching: Pygame surfaces are cached to improve rendering performance. See loader.py.
- Efficient Move Generation: The core chess engine uses optimized algorithms for move generation.
- Input validation is performed on all user inputs.
- The online gameplay uses secure socket connections.
We welcome contributions to multiplayer-chess-game! Please follow these guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Write clear and concise commit messages.
- Submit a pull request with a detailed description of your changes.
- Reference
- Contribution Guidelines
- Stockfish Setup
- Implement a more sophisticated AI opponent.
- Add support for different chess variants.
- Improve the user interface and add more customization options.
- Implement a rating system for online players.
Q: How do I configure Stockfish?
A: Download the Stockfish engine for your operating system and update the path in res/stockfish/path.txt
. See also the Stockfish setup instructions in mac.txt and other files in that directory.
Q: Can I play the game offline?
A: Yes, you can play local multiplayer and against the AI opponent offline.
- GitHub: muhammadhamzagova666