Computer vision-powered chess game using hand tracking and gesture recognition for piece control. Real-time gameplay with AI opponent.
- Real-time hand tracking and gesture recognition
- Closed_Fist gesture for piece selection and movement
- Smart AI opponent with minimax search and alpha-beta pruning
- Complete chess rules implementation
- Dual-window interface: game board + camera view
git clone https://github.com/praisejamesx/gesture-chess.git
cd gesture-chess
pip install pygame opencv-python mediapipe python-chess numpy
python main.py- Python 3.7+
- Webcam
- gesture_recognizer.task (MediaPipe gesture model)
- Closed_Fist: Select piece / Confirm move
- Open_Palm: Hover mode
- SPACE: Start/restart game
- R: Reset game
- Q: Quit camera
Webcam → MediaPipe → 21 hand landmarks → Gesture classification → Board coordinates
- Algorithm: Minimax with alpha-beta pruning
- Search depth: 3-4 ply
- Evaluation function: Material + Position + Mobility + King Safety
- Move ordering: Captures → Checks → Center moves
- Frame rate: 30-60 FPS
- Gesture latency: <100ms
- AI response time: 1-2 seconds
- Gesture accuracy: 95%+
Given 21 hand landmarks L = {(xᵢ, yᵢ)}:
Hand center: (x̄, ȳ) = (1/21 Σxᵢ, 1/21 Σyᵢ)
Board coordinates: (⌊8x̄⌋, ⌊8ȳ⌋)
E(position) = Σ wᵢ·cᵢ·pᵢ(s) + 0.1·M + K
where:
wᵢ = piece weight {P:1, N:3, B:3.25, R:5, Q:9}
cᵢ = color multiplier (±1)
pᵢ(s) = piece-square table value at square s
M = mobility (number of legal moves)
K = king safety term
- Alpha-beta pruning: Reduces complexity from O(bᵈ) to O(√bᵈ)
- Move ordering: 70% reduction in nodes evaluated
- Iterative deepening: Time-controlled search
- Main thread: PyGame rendering, chess logic, AI calculation
- Camera thread: OpenCV capture, MediaPipe processing
- Synchronization: Thread-safe queues with lock protection
- 3D version with AR overlay
- Multiplayer gesture-based remote play
- Advanced AI with opening book and endgame tables
- Performance analytics and move suggestion heatmaps
Buy Me A Coffee: https://selar.com/showlove/judahx
Email: praisejames011@gmail.com
Blog: https://crive.substack.com
MIT License