A fully functional chess game implemented in Python with complete rule validation, check/checkmate detection, and an intuitive console interface. Experience the classic strategy game right in your terminal!
- All Standard Pieces - King, Queen, Rook, Bishop, Knight, and Pawn with authentic movement patterns
- Rule Validation - Full implementation of official chess rules and move validation
- Check Detection - Automatic detection and prevention of moves that leave the king in check
- Game End Conditions - Checkmate and stalemate detection with automatic game termination
- Turn Management - Proper alternating turns between white and black players
- Unicode Chess Pieces - Beautiful visual representation using ♔♕♖♗♘♙ symbols
- Algebraic Notation - Standard chess notation (e.g., e2-e4) for move input
- Clear Board Display - Clean 8x8 grid with coordinate labels (a-h, 1-8)
- Game Status Updates - Real-time notifications for check, checkmate, and stalemate
- Input Validation - Robust error handling and user guidance
- Path Validation - Intelligent pathfinding for sliding pieces (rook, bishop, queen)
- Piece-Specific Movement - Each piece type follows its unique movement rules
- King Safety - Prevents any move that would result in check
- Game State Tracking - Maintains complete game state including piece positions and move history
- Python 3.6 or higher
- No external dependencies required!
# Clone the repository
git clone https://github.com/yourusername/python-chess-game.git
cd python-chess-game
# Run the game
python chess_game.pypython chess_game.py- Move Format: Use algebraic notation (e.g.,
e2-e4) - Quit Game: Type
quitat any time - Coordinate System:
- Files (columns): a-h (left to right)
- Ranks (rows): 1-8 (bottom to top)
a b c d e f g h
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 8
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
6 · · · · · · · · 6
5 · · · · · · · · 5
4 · · · · · · · · 4
3 · · · · · · · · 3
2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ 2
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
a b c d e f g h
Blancas, ingresa tu movimiento: e2-e4
Movimiento realizado: e2 -> e4
a b c d e f g h
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ 8
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ 7
6 · · · · · · · · 6
5 · · · · · · · · 5
4 · · · · ♙ · · · 4
3 · · · · · · · · 3
2 ♙ ♙ ♙ ♙ · ♙ ♙ ♙ 2
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ 1
a b c d e f g h
Negras, ingresa tu movimiento: d7-d5
Represents individual chess pieces with properties:
class ChessPiece:
def __init__(self, color, piece_type, symbol):
self.color = color # 'white' or 'black'
self.piece_type = piece_type # 'pawn', 'rook', etc.
self.symbol = symbol # Unicode chess symbol
self.has_moved = False # For special moves trackingMain game engine handling:
- Board state management
- Move validation and execution
- Check/checkmate detection
- Game flow control
| Method | Purpose |
|---|---|
setup_board() |
Initialize starting chess position |
is_valid_move() |
Comprehensive move validation |
is_piece_move_valid() |
Piece-specific movement rules |
is_in_check() |
Check detection algorithm |
is_checkmate() |
Checkmate detection algorithm |
make_move() |
Execute validated moves |
Each piece type has specialized validation:
- Pawn - Forward movement, diagonal capture, initial two-square move
- Rook - Horizontal and vertical lines with path clearing
- Bishop - Diagonal lines with path clearing
- Knight - L-shaped moves (2+1 or 1+2 squares)
- Queen - Combined rook and bishop movement
- King - One square in any direction
def is_in_check(self, color, king_pos=None):
"""Verify if the king is in check"""
# Scan all opponent pieces
# Test if any can capture the king
# Return True if king is threatened- Basic Validation - Valid coordinates, piece ownership
- Piece Rules - Movement pattern validation
- Path Clearing - No pieces blocking the path
- Check Prevention - Move doesn't expose own king
- Execute - Update board state and switch turns
| Feature | Status | Description |
|---|---|---|
| ✅ Basic Movement | Complete | All pieces move according to chess rules |
| ✅ Check Detection | Complete | Prevents illegal moves, detects check |
| ✅ Checkmate | Complete | Automatic game end detection |
| ✅ Stalemate | Complete | Draw condition detection |
| ⏳ Castling | Planned | King and rook special move |
| ⏳ En Passant | Planned | Pawn capture special rule |
| ⏳ Pawn Promotion | Planned | Pawn to queen/rook/bishop/knight |
| ⏳ AI Opponent | Planned | Single player vs computer |
- Castling - King and rook coordinated move
- En Passant - Special pawn capture
- Pawn Promotion - Transform pawns reaching the end
- Draw Conditions - 50-move rule, repetition, insufficient material
- Move History - Complete game notation recording
- Undo/Redo - Take back moves
- Save/Load Games - Game persistence
- Time Controls - Chess clocks and time limits
- AI Engine - Computer opponent with difficulty levels
- Opening Database - Common opening moves
- Position Analysis - Evaluate board positions
- Puzzle Mode - Chess tactics trainer
- GUI Version - Pygame or Tkinter interface
- Web Interface - Browser-based chess
- Mobile App - Smartphone compatibility
- Online Multiplayer - Network play capability
We welcome contributions! Here's how to get involved:
git clone https://github.com/yourusername/python-chess-game.git
cd python-chess-game
python -m pytest tests/ # Run tests (when added)- Follow PEP 8 Python style guidelines
- Add comprehensive docstrings to new functions
- Include unit tests for new features
- Update documentation for significant changes
- Create detailed pull request descriptions
- Special Moves Implementation (castling, en passant, promotion)
- Test Suite Development - Unit tests for game logic
- Performance Optimization - Algorithm improvements
- Documentation - Code comments and user guides
- Bug Reports - Issue identification and reproduction
- Move Generation: O(n²) for piece scanning
- Check Detection: O(n²) worst case
- Checkmate Detection: O(n⁴) exhaustive search
- Memory Usage: Minimal - single board state
- Object-Oriented Design - Clean separation of concerns
- Type Safety - Consistent data types and validation
- Error Handling - Robust input validation and error recovery
- Modularity - Easy to extend and modify
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License - Feel free to use, modify, and distribute
[Jaume Torra]
- 🌐 GitHub: @JaumeTorra
- 📧 Email: jaumetorra.pro@gmail.com
- Chess Programming Community - For algorithms and best practices
- Unicode Consortium - For chess piece symbols (♔♕♖♗♘♙)
- Python Community - For excellent documentation and libraries
- FIDE - For official chess rules and regulations
- Chess Programming Wiki
- Lichess Analysis - For testing positions
- Chess.com - Rules reference
- Python Chess Library - Advanced chess programming
- PEP 8 Style Guide
- Python Testing
# Clone and run
git clone https://github.com/yourusername/python-chess-game.git
cd python-chess-game && python chess_game.py
# Example moves to try
# White: e2-e4, d2-d4, g1-f3
# Black: e7-e5, d7-d5, b8-c6⭐ Star this repository if you enjoy chess and clean Python code!
"Chess is the struggle against error." - Johannes Zukertort ♟️