This repository is an AI course project: a Harry-Potter-themed Connect Four web game with an intelligent opponent.
- 🎮 Web game (Flask) with an interactive 6×7 Connect Four board.
- 🧠 Multiple AI options:
- Minimax
- Minimax v2 (alternative evaluation)
- Minimax + Alpha–Beta pruning
- Minimax v2 + Alpha–Beta pruning
- Heuristic / Heuristic v2 (fast greedy)
- 🎚️ Difficulty levels mapped to search depth:
- Easy → depth 2
- Medium → depth 4
- Hard → depth 7
- ⚡ Harry Potter vibe:
- Intro video + music
- HP font and themed assets
- Python 3
- Flask (backend / routes)
- NumPy (board representation & computation)
- HTML/CSS/JS (frontend)
git clone <YOUR_REPO_URL>
cd An-Intelligent-Connect-Four-Player-mainpython -m venv .venv
# Windows:
.venv\Scripts\activate
# macOS / Linux:
source .venv/bin/activateIf you have a requirements.txt:
pip install -r requirements.txtOtherwise install directly:
pip install flask numpypython app.pyThen open:
http://127.0.0.1:5000/
If the app fails immediately with an import error, ensure app.py uses render_template (Flask’s correct function name):
Replace:
from flask import Flask, render_templates, request, jsonify
...
return render_templates("index.html")With:
from flask import Flask, render_template, request, jsonify
...
return render_template("index.html")- Start from the landing page
/then click Start Game. - Choose:
- Algorithm
- Difficulty
- Your character & AI opponent
- Click any column to drop your piece.
- The AI responds using the selected algorithm.
Board encoding:
0→ empty1→ human player2→ AI
The AI lives in connect4.py and supports:
- Minimax: explores the game tree up to a chosen depth and picks the move that maximizes the AI score.
- Alpha–Beta Pruning: speeds up minimax by skipping branches that cannot affect the final decision.
- Two evaluation strategies:
score_position()(classic window scoring + center preference)future_chance_score()(counts future chances / open windows)
The frontend calls:
POST /move
Payload:
{
"board": [[0,0,0,0,0,0,0], ...],
"difficulty": "MED",
"algorithm": "alpha_beta"
}Response:
{ "column": 3 }Supported algorithm values:
minimaxminimax2alpha_betaalpha_beta2hurestichurestic2
.
├─ app.py # Flask app (routes + AI selection)
├─ connect4.py # Game logic + AI algorithms
├─ templates/
│ ├─ index.html # Intro page (video + start)
│ └─ game.html # Game UI & settings
└─ static/
├─ css/ # Styles (Harry Potter theme)
├─ js/ # Frontend logic
├─ images/ # Characters, icons, backgrounds
├─ sounds/ # Music & effects
└─ video/ # Intro video
This project is made for educational purposes as part of an AI course.