Skip to content

ayush-jadaun/ChessEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess Game with AI Advantage Prediction

A modern chess game implementation with real-time AI-powered position evaluation and a beautiful graphical interface. The game features a professional design, intuitive controls, and machine learning-based position analysis.

Features

Gameplay

  • Interactive chess board with legal move validation
  • Real-time position evaluation using machine learning
  • Visual advantage bar showing current game state
  • Move history display (last 10 moves)
  • Current player indicator
  • Chess coordinates (a-h, 1-8)
  • Reset game functionality (R key)
  • Cancel selection (ESC key)
  • Pawn promotion with visual piece selection dialog

User Interface

  • Modern, clean design with professional color scheme
  • Smooth hover effects and piece selection highlighting
  • Side panel with game information
  • Responsive board sizing and centering
  • Shadow effects and visual feedback
  • Alternating move history background
  • Board coordinates for easy move reference
  • Centered promotion dialog with piece selection

AI Integration

  • Machine learning model for position evaluation
  • Real-time advantage prediction
  • Feature extraction from board positions
  • Gradient-based advantage visualization

Technical Features

  • Pygame-based graphical interface
  • Python-chess library for game logic
  • RandomForest model for position evaluation
  • Efficient board state management
  • Frame rate limiting for smooth gameplay
  • Error handling for resource loading

Requirements

  • Python 3.8+
  • pygame>=2.5.0
  • python-chess>=1.10.0
  • scikit-learn>=1.3.0
  • numpy>=1.24.0
  • joblib>=1.3.0

Installation

  1. Clone the repository:
git clone https://github.com/ayush-jadaun/chess-game.git
cd chess-game
  1. Set up a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the game:
python src/game/main.py

Project Structure

chess-game/
├── src/
│   ├── game/
│   │   ├── __init__.py
│   │   └── main.py           # Main game implementation
│   ├── engine/
│   │   ├── __init__.py
│   │   └── model.py          # Chess engine and ML model
│   └── utils/
│       ├── __init__.py
│       └── constants.py      # Game constants
├── assets/
│   ├── images/              # Chess piece images
│   │   ├── bB.png          # Black bishop
│   │   ├── bK.png          # Black king
│   │   ├── bN.png          # Black knight
│   │   ├── bP.png          # Black pawn
│   │   ├── bQ.png          # Black queen
│   │   ├── bR.png          # Black rook
│   │   ├── wB.png          # White bishop
│   │   ├── wK.png          # White king
│   │   ├── wN.png          # White knight
│   │   ├── wP.png          # White pawn
│   │   ├── wQ.png          # White queen
│   │   └── wR.png          # White rook
│   └── models/
│       └── chess_model.pkl  # Trained ML model
├── data/
│   └── pgn/                # PGN game data for training
├── requirements.txt        # Project dependencies
└── README.md              # Project documentation

How to Play

  1. Starting the Game:

    • Run the game using python src/game/main.py
    • The board will appear with pieces in their starting positions
  2. Making Moves:

    • Click on a piece to select it
    • Valid moves will be highlighted with circles
    • Click on a highlighted square to move
    • Press ESC to deselect a piece
  3. Pawn Promotion:

    • When a pawn reaches the opposite end of the board (8th rank for White, 1st rank for Black)
    • A promotion dialog will appear in the center of the screen
    • Click on the piece you want to promote to (Queen, Rook, Bishop, or Knight)
    • Press ESC to cancel the promotion and choose a different move
  4. Game Controls:

    • R: Reset the game
    • ESC: Cancel piece selection or promotion dialog
    • Mouse: Select and move pieces
  5. Game Features:

    • The side panel shows the current player and advantage
    • Move history displays the last 10 moves
    • The advantage bar shows the current position evaluation
    • Chess coordinates help identify squares
    • Hover effects show which square you're pointing at
    • Visual feedback for piece selection and legal moves

Model Training

The chess engine uses a machine learning model trained on:

  • PGN game data
  • Position features (768 binary features representing piece positions)
  • RandomForest regressor for position evaluation

Future Improvements

  • Add multiplayer support
  • Implement game saving/loading
  • Add difficulty levels
  • Improve AI model accuracy
  • Add sound effects
  • Implement undo/redo
  • Add game statistics
  • Create tutorial mode
  • Add keyboard shortcuts for moves
  • Implement move validation hints

Author

Support

For support, please open an issue in the GitHub repository or contact the author.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published