PyChess is a modular chess game built in Python and Pygame featuring full chess mechanics, an AI opponent, a progression and points system, guest and registered account support with SQLite persistence, multiple board visual themes, and a responsive modern user interface.
- Full Chess Engine & Mechanics:
- Valid move generation for all piece types (Pawns, Knights, Bishops, Rooks, Queens, Kings).
- Proper check, checkmate, and stalemate detection.
- Automatic pawn promotion to Queen on back rank.
- Turn system with responsive AI opponent for Black.
- Visual valid-move indicators and check warnings.
- Account & Guest System:
- Guest Mode: Play instantly without registration. Session points are tracked during current gameplay.
- Registered Accounts: Create or log into user accounts. Points are permanently saved in a local SQLite database (
pychess.db).
- Points & Rewards Engine:
- Configurable points rewards for piece captures, promotions, delivering check, checkmate, and winning matches.
- Real-time match score calculation and breakdown summary on game conclusion.
- Modern User Interface:
- Interactive Main Menu with hover animations and player profile status.
- In-game Side Panel displaying current turn, match score, captured pieces list, and controls.
- Points & Leaderboard Screen with scoring guide and top players ranking.
- Game Settings Screen with customizable board themes (Classic Slate, Emerald Forest, Ocean Breeze, Warm Wood) and audio/visual toggles.
- Result Screen detailing match outcome and points breakdown.
- Modular & Maintainable Architecture:
- Clean separation of concerns across
config/,database/,player/,game/, andui/.
- Clean separation of concerns across
PyChess/
โโโ main.py # Main application entry point
โโโ requirements.txt # Python dependencies
โโโ pychess.db # SQLite database (auto-generated)
โ
โโโ config/ # Settings and point values
โ โโโ settings.py # Display, board themes, UI palette
โ โโโ points_config.py # Centralized point values & reward rules
โ
โโโ database/ # SQLite data persistence layer
โ โโโ db.py # DB connection & schema initialization
โ โโโ models.py # User and score models
โ โโโ repository.py # UserRepository CRUD operations & leaderboards
โ
โโโ player/ # Player state & session handling
โ โโโ session.py # Guest vs Authenticated user session manager
โ
โโโ game/ # Core chess game logic
โ โโโ constants.py # Piece identifiers, colors, board layout
โ โโโ board.py # Board 8x8 matrix representation & state
โ โโโ moves.py # Move generation for all 6 piece types
โ โโโ rules.py # Check, checkmate, and stalemate validation
โ โโโ ai.py # AI move selection for Black
โ โโโ points_engine.py # Match events & score calculation
โ โโโ game_state.py # Turn coordinator & match state manager
โ
โโโ ui/ # Pygame graphical user interface
โ โโโ screen_manager.py # Screen transition & state manager
โ โโโ components/ # Reusable UI widgets (Buttons, Inputs, Cards, Theme)
โ โโโ screens/ # UI Screens (Home, Account, Game, Points, Settings, Result)
โ
โโโ assets/ # Game assets
โ โโโ images/
โ โโโ pieces/ # Chess piece PNG graphics
โ
โโโ tests/ # Automated test suite
โโโ test_chess_logic.py # Move generation, check, checkmate, points tests
โโโ test_database.py # SQLite persistence & session tests
โโโ test_ui_smoke.py # Screen lifecycle & navigation smoke tests
- Python 3.8+ installed.
- Clone the repository:
git clone https://github.com/K1lluaZk/pychess.git cd pychess - Install dependencies:
pip install -r requirements.txt
Run the application:
python main.py- Home Screen: Start game, manage accounts, view points & rules, or adjust settings.
- Move Pieces: Click on any of your white pieces to see highlighted valid moves, then click a valid destination square.
- Capture & Score: Earn points by capturing enemy pieces, delivering checks, and winning by checkmate.
- End Game: When the game concludes, review your earned points and return to the main menu or play again.
| Event | Reward |
|---|---|
| Capture Pawn | +10 pts |
| Capture Knight | +30 pts |
| Capture Bishop | +30 pts |
| Capture Rook | +50 pts |
| Capture Queen | +90 pts |
| Pawn Promotion | +40 pts |
| Deliver Check | +20 pts |
| Deliver Checkmate | +100 pts |
| Victory Bonus | +200 pts |
To run the automated unit test suite:
python -m unittest discover -s testsThis project is licensed under the MIT License.