An interactive, AI-powered Connect 4 game controlled entirely by hand gestures! Built using Python, OpenCV, MediaPipe, and Pygame, this project allows you to battle against a Minimax-based AI agent using nothing but your hands.
- Hand Gesture Control: Play the game without touching your mouse or keyboard! Uses your webcam and MediaPipe to track hand movements.
- Smart AI Opponent: Battle an AI powered by the Minimax Algorithm.
- Alpha-Beta Pruning: Optimized decision-making through optional Alpha-Beta pruning, which drastically improves search speed.
- Dynamic Skill Level: Choose the AI's search depth dynamically at the start of the game, letting you control the difficulty.
- Real-Time Decision Tree Visualization: An interactive on-screen tracing log displays the AI's calculation process under the playing board, with mouse scroll capabilities.
- Heuristics Scoring: The AI evaluates non-terminal board states using specialized window-based scoring rules.
Ensure you have the following Python libraries installed:
opencv-python(cv2)mediapipepygamenumpy
You can install them via pip:
pip install opencv-python mediapipe pygame numpy- Run the script:
python Connect4.py
- When prompted in the console, enter the desired AI Search Depth (e.g., 3 or 4).
- Choose whether to enable Alpha-Beta Pruning (
y/n). - A Pygame window and a Webcam window will appear.
- Use your hand to control the game:
- Move: Move your index finger left and right to select a column.
- Drop Piece: Form a fist (fold fingers) to drop your piece into the highlighted column.
- Use the scroll wheel on your mouse over the game window to scroll through the AI's Minimax calculation tree!
Enjoy defeating the AI with the power of your hands! 🚀