Skip to main content

A fully-featured chess engine with graphical user interface and AI opponent

Project description

♟️ ChessyAI - Chess Engine

A fully-featured chess engine with graphical user interface and AI opponent built with Python and Pygame.

Python Pygame License Version

✨ Features

Complete Chess Rules

  • ✅ All piece movements (Pawn, Rook, Knight, Bishop, Queen, King)
  • ✅ Check detection
  • ✅ Checkmate & Stalemate detection
  • ✅ Castling (Kingside & Queenside)
  • ✅ En Passant
  • ✅ Pawn Promotion with piece selection dialog

🤖 AI Opponent

  • ✅ Minimax algorithm with Alpha-Beta pruning
  • ✅ Position evaluation with piece-square tables
  • ✅ Configurable search depth
  • ✅ Play as White against AI (Black)

User Interface

  • ✅ Visual highlighting of valid moves
  • ✅ Selected piece highlighting
  • ✅ Last move highlighting
  • ✅ Check warning (King highlighted in red)
  • ✅ Game over dialog
  • ✅ Move log panel
  • ✅ Chess clock (10 min per player)

🔊 Sound Effects

  • ✅ Move sounds
  • ✅ Capture sounds
  • ✅ Check warning
  • ✅ Castling sound
  • ✅ Game over sound

💾 Save & Export

  • ✅ PGN export (save games)

Controls

Key Action
Z Undo last move
R Restart game
S Save game as PGN
F Force AI move (hint)
Mouse Select and move pieces

🚀 Installation

Using uv (Recommended)

# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone the repository
git clone https://github.com/redbasecap/ChessyAI.git
cd ChessyAI

# Install dependencies
uv sync

# Generate sound effects (first time only)
uv run python generate_sounds.py

# Run the game
uv run python ChessMain.py

Using pip

# Clone the repository
git clone https://github.com/redbasecap/ChessyAI.git
cd ChessyAI

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install pygame

# Generate sound effects (first time only)
python generate_sounds.py

# Run the game
python ChessMain.py

🎮 How to Play

  1. Start the game with uv run python ChessMain.py
  2. Click on a piece to select it (valid moves will be highlighted in green)
  3. Click on a highlighted square to move the piece
  4. White (you) moves first, AI (Black) responds automatically
  5. Pawn promotion: When a pawn reaches the last rank, click on the piece you want
  6. The game ends when checkmate, stalemate, or time runs out

Player Configuration

Edit ChessMain.py to change who plays:

player_one = True   # White: True = Human, False = AI
player_two = False  # Black: True = Human, False = AI

📁 Project Structure

ChessyAI/
├── ChessEngine.py      # Game logic and state management
├── ChessMain.py        # GUI and user input handling
├── ChessAI.py          # AI opponent (Minimax + Alpha-Beta)
├── generate_sounds.py  # Sound effect generator
├── images/             # Chess piece sprites (PNG)
├── sounds/             # Sound effects (WAV)
├── games/              # Saved PGN files
├── pyproject.toml      # Project configuration
└── README.md

🔧 Technical Details

Piece Notation

w = White, b = Black
K = King, Q = Queen, R = Rook, B = Bishop, N = Knight, p = Pawn
Example: "wK" = White King, "bp" = Black Pawn

Board Representation

The board is represented as an 8x8 2D array where "--" indicates an empty square.

AI Evaluation

Piece Value
King
Queen 900
Rook 500
Bishop 330
Knight 320
Pawn 100

The AI also uses position tables to prefer central control and piece development.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Possible Enhancements

  • PGN import (load games)
  • Move animations
  • Online multiplayer
  • Opening book
  • Endgame tablebase

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chessyai-2.0.0.tar.gz (119.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chessyai-2.0.0-py3-none-any.whl (132.4 kB view details)

Uploaded Python 3

File details

Details for the file chessyai-2.0.0.tar.gz.

File metadata

  • Download URL: chessyai-2.0.0.tar.gz
  • Upload date:
  • Size: 119.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chessyai-2.0.0.tar.gz
Algorithm Hash digest
SHA256 967b859ec73ef0da457ba95f78ec04b2cc68c44b9e5b28f4fc76969f668dd490
MD5 357f721585aeb67f371fc734c5ba2d3c
BLAKE2b-256 2ea0caceed3e7b0f7c352adf44ed3b5b087c08a587ae704dbae37c04d17df559

See more details on using hashes here.

Provenance

The following attestation bundles were made for chessyai-2.0.0.tar.gz:

Publisher: release.yml on redbasecap/chessyAI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chessyai-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: chessyai-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 132.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chessyai-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e750902886927024fbfd0cfb589e73f99d907032fd6684cf39b590537ca791bb
MD5 5a6e1091853a97503a4dca5997faa370
BLAKE2b-256 0c294dd5492c106743e3835e4945b40bdb62bf1a583b0182c5b4aad7095efd55

See more details on using hashes here.

Provenance

The following attestation bundles were made for chessyai-2.0.0-py3-none-any.whl:

Publisher: release.yml on redbasecap/chessyAI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page