A modern, web-based Connect 4 game featuring an intelligent AI opponent powered by the Minimax algorithm with Alpha-Beta Pruning. Challenge yourself against a strategic AI that thinks 5 moves ahead!
- ๐ง Intelligent AI Opponent โ Minimax with Alpha-Beta Pruning for strategic gameplay
- ๐ฅ Multi-User Support โ Each browser gets its own game session
- ๐ฑ Responsive Design โ Seamless experience on desktop, tablet, and mobile devices
- โก Fast Performance โ AI makes decisions in under 1 second
- ๐จ Modern UI โ Clean interface with smooth animations and visual feedback
- ๐ฏ Strategic Depth โ AI analyzes up to 5 moves ahead for challenging gameplay
| Metric | Value |
|---|---|
| Search Depth | 5 levels |
| Average Response | < 1 second |
| Nodes Evaluated | 10,000 - 50,000 per move |
| Algorithm | Minimax + Alpha-Beta Prune |
| Difficulty Level | Challenging |
- Python 3.7 or higher
- Git
-
Clone the repository
git clone https://github.com/viliusjan/connect4-ai.git cd connect4-ai -
Install the project's requirements
pip install flask
-
Generate a Flask secret key
Run this in Python:import secrets print(secrets.token_hex(32))
Copy the generated string.
-
Set your secret key in
connect4.pyapp = Flask(__name__) app.secret_key = 'paste_your_generated_secret_key_here'
-
Run the game locally
python3 connect4.py
-
Open your browser
Navigate to: http://localhost:8000
connect4-ai/
โโโ connect4.py # Main Flask application (session-based, multi-user)
โโโ templates/ # HTML templates
โโโ README.md # Project documentation
Connect 4 is a classic strategy game where players take turns dropping colored pieces into a grid:
- Objective: Be the first to get 4 pieces in a row
- Winning Conditions: Horizontal, vertical, or diagonal connections
- Grid Size: 7 columns ร 6 rows
- Turn-based: Players alternate dropping pieces
- Gravity Effect: Pieces fall to the lowest available position
The AI uses a sophisticated decision-making process:
- Minimax Algorithm: Evaluates all possible future game states
- Alpha-Beta Pruning: Optimizes search by eliminating inferior branches
- Evaluation Function: Scores board positions based on strategic value
- Depth Limitation: Searches 5 moves ahead for optimal performance balance
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Found a bug or have a suggestion? Please:
- Check existing issues
- Create a new issue with detailed description
- Include steps to reproduce (if applicable)
This project is licensed under the MIT License - see the LICENSE file for details.
- Classic Connect 4 game concept by Milton Bradley
- Minimax algorithm implementation inspired by AI game theory
- Thanks to the Python and Flask communities
Enjoy playing Connect 4 AI! ๐
Challenge yourself against an intelligent opponent and improve your strategic skills.