Skip to content

AmZzPYJS/Python-Chess-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

♟ Python Chess AI

A chess engine built from scratch in Python with a graphical interface (Pygame) and an AI opponent powered by the Minimax algorithm with alpha-beta pruning.

Personal project — built to explore game theory, tree search algorithms, and board evaluation heuristics.

Python Pygame License


Features

  • Full chess GUI with drag-and-drop piece movement
  • Legal move validation using python-chess
  • AI opponent playing as Black
  • Minimax search with configurable depth
  • Alpha-beta pruning for performance optimization
  • Position evaluation based on piece values and positional tables

How the AI works

The AI evaluates every possible move using a recursive tree search:

  1. Minimax — explores the game tree by alternating between maximizing (White) and minimizing (Black) scores
  2. Alpha-beta pruning — cuts off branches that can't influence the final decision, reducing the number of positions evaluated
  3. Evaluation function — assigns a score to each board state based on material (piece values) and positional bonuses (center control, king safety)

Tech stack

Component Technology
Language Python
GUI Pygame
Chess logic python-chess
Algorithm Minimax + Alpha-Beta pruning

Getting started

git clone https://github.com/AmZzPYJS/Python-Chess-AI.git
cd Python-Chess-AI
pip install -r requirements.txt
python main.py

Project structure

Python-Chess-AI/
├── main.py              # Entry point — game loop and GUI rendering
├── requirements.txt     # Dependencies
├── screen/              # Screenshots
├── LICENSE
└── README.md

What I learned

  • Implementing a tree search algorithm (Minimax) and understanding its time complexity
  • How alpha-beta pruning drastically reduces the search space
  • Designing a board evaluation function with piece-square tables
  • Building an interactive GUI with Pygame's event loop
  • Working with the python-chess library for move generation and validation

License

MIT

About

Chess engine in Python with Pygame GUI — Minimax algorithm with alpha-beta pruning, piece-square evaluation, and legal move validation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages