A Python-based chess engine implementation featuring player vs. player gameplay and AI opponents using minimax and alpha-beta pruning algorithms.
- Complete chess rule implementation including:
- All standard piece movements
- Special moves (castling, en passant, pawn promotion)
- Check and checkmate detection
- Stalemate detection
- Multiple game modes:
- Player vs Player
- Player vs AI (Basic Minimax)
- Player vs Enhanced AI (Alpha-Beta Pruning)
- Console-based chess board visualization
- Piece-position evaluation tables for intelligent AI gameplay
- Advanced board evaluation with multiple heuristics
The engine uses an object-oriented approach with a ChessPiece parent class and individual classes for each piece type:
PawnRookKnightBishopQueenKing
Each piece implements its own valid_moves() method defining legal movements according to chess rules.
- 8x8 grid implemented as a 2D array
- Algebraic notation support (e.g., "e2 e4")
- Piece positions tracked with coordinate system (0-7, 0-7)
- Uses Minimax algorithm
- Configurable depth for move searching
- Basic position evaluation
- Implements Alpha-Beta Pruning
- Deeper search depth capability
- Enhanced evaluation function including:
- Piece-square tables
- Material value
- Position evaluation
- Special bonuses/penalties for:
- Doubled pawns
- Isolated pawns
- Bishop pairs
- Knight positioning
The engine uses sophisticated position evaluation including:
- Base piece values
- Position-dependent scoring using piece-square tables
- Tactical considerations:
- Pawn structure analysis
- Bishop pair bonus
- Knight positioning relative to pawn structure
if __name__ == "__main__":
play_chess_with_improved_ai() # For AI game
# or
play_chess() # For PvP gameMoves are input using algebraic notation:
Enter your move (e.g., 'e2 e4'): e2 e4
- Player vs Player:
play_chess()- Player vs Basic AI:
play_chess_with_ai()- Player vs Improved AI:
play_chess_with_improved_ai()- Legal move checking for all pieces
- Check detection and prevention
- Move simulation for check prevention
- Special move validation
- Piece Values:
- Pawn: 100
- Knight: 320
- Bishop: 330
- Rook: 500
- Queen: 900
- King: 20000
The engine uses piece-square tables for position evaluation, considering:
- Pawn advancement and structure
- Knight centralization
- Bishop diagonal control
- Rook positioning
- Queen mobility
- King safety
Potential enhancements could include:
- GUI implementation
- Opening book integration
- Endgame tablebase support
- Move time control
- ELO rating system
- PGN game notation support
- Python 3.x
- Standard library modules:
- copy (for board state management)