Skip to content

andredisa/chess_AI_agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

♟️ Chess AI Agents

Welcome to chess AI agents — an interactive AI vs AI chess game built with Streamlit, Python-Chess, and AutoGen (OpenAI). Two powerful language models face off on the board, making moves in real time, while you watch the strategy unfold! 🤖⚔️🤖


🚀 Features

  • ✅ AI vs AI chess match powered by GPT models
  • ✅ Real-time chessboard visualization with SVG rendering
  • ✅ User-friendly web interface via Streamlit
  • ✅ Game coordination via AutoGen's ConversableAgent framework
  • ✅ Full move history and end-of-game detection (checkmate, stalemate, etc.)
  • ✅ Configurable number of turns and full reset capability
  • ✅ Modular, clean codebase for easy extension

📦 Installation

1. Clone the Repository

git clone https://github.com/andredisa/chess_AI_agents.git
cd chess_AI_agents

2. Create a Virtual Environment (Optional but recommended)

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

📂 Project Structure

chess_AI_agents/
├── app.py              # 🚀 Main Streamlit app that runs the interface and integrates all components.
├── config/        # 📂 Configuration files.
│   └── settings.py     # 🛠️ Contains the number of turns
├── agents/        # 📂 Agent-related files.
│   ├── base.py         # 🧠 Abstract class for all chess agents.
│   └── game_agents.py  # 🤖 Concrete AI chess agents.
├── chess_logic/   # 📂 Chess game logic.
│   ├── board_utils.py  # ⚙️ Chessboard utilities (e.g., move validation).
│   └── game_state.py   # 🕹️ Tracks game state (checkmate, stalemate).
├── ui/            # 📂 User interface components.
│   └── sidebar.py      # 📝 Sidebar for user configuration (API keys, settings).
├── utils/         # 📂 General utilities.
│   └── session.py      # ⏳ Manages session state and interactions.
├── requirements.txt    # 📜 Python dependencies.
├── README.md           # 📄 Project documentation.
└── LICENSE             # 📝 MIT License.


🔑 Requirements

  • Python 3.8+
  • An OpenAI API key
  • An Internet connection to access OpenAI models (GPT-4o or GPT-3.5-turbo)

🧠 How It Works

  • Two agents (Agent_White and Agent_Black) are powered by OpenAI LLMs using AutoGen.
  • A Game_Master agent handles validation and game coordination.
  • Each agent queries available moves, selects one, and executes it.
  • The board state is visualized after each move.
  • The user configures the number of moves and watches the AI play!

💻 Running the App

Run the Streamlit app with:

streamlit run app.py

Then open http://localhost:8501 in your browser.


⚙️ Configuration

  • 🔐 Enter your OpenAI API key in the sidebar

  • ♟️ Choose the number of turns (recommended: 5–10 for demo)

    • You can also set the default number of turns in the config file:

      In config/settings.py, modify the constant:

      DEFAULT_MAX_TURNS = 5
  • ▶️ Click Start Game to begin the AI chess match


🛠️ Future Improvements

  • 🎮 Add human vs AI mode

  • 📄 PGN export of games

  • 🤖 Local model support (e.g., LLaMA, Mistral)

  • 🔁 Multiple game modes and agent personalities


✨ Contributing

🎉 Contributions are more than welcome!

If you find a bug 🐞, have a feature request ✨, or want to improve the code 💻:

💬 Feel free to reach out on GitHub or by email!

Let’s build this together!


📜 License

📄 This project is released under the MIT License.
Please refer to the LICENSE file for full details.


☕ Support Me

If you find my work useful and would like to support me, you can buy me a coffee! Your support helps me keep creating and improving my projects. Thank you! 😊

Buy Me A Coffee


🧑‍💻✨ Happy coding

About

♟️ An interactive AI vs AI chess game built with Streamlit, Python-Chess, and AutoGen (OpenAI). Two powerful language models face off on the board, making moves in real time, while you watch the strategy unfold!

Topics

Resources

License

Stars

10 stars

Watchers

1 watching

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors

Languages