A classroom-friendly Python activity that turns a webcam into a game of Rock, Paper, Scissors, AI!
This repository has two useful branches:
main: the guided workshop version, with a few smallTODOsections to complete during the activitycomplete-solution: the finished fallback version, ready to run if you get stuck or want to compare your work
Use Python 3.11 or 3.12.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python src/main.pyOn Windows:
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python src\main.pyYou can also run ./start.sh on macOS/Linux or start.bat on Windows after installing the requirements.
If you previously installed the dependencies and see AttributeError: module 'mediapipe' has no attribute 'solutions', run pip install -r requirements.txt again. The requirements file pins MediaPipe to a classroom-compatible version that still supports the simple mp.solutions API.
On the main branch, follow TUTORIAL.md for the 45-minute step-by-step lesson.
- Activate the webcam feed.
- Draw hand landmarks.
- Count extended fingers.
- Classify rock, paper, and scissors.
- Generate the computer move.
- Decide the winner and update the score.
The main starting point runs before any TODOs are completed, but it will print a helpful camera message until you activate the webcam feed.
- Show a rock, paper, or scissors gesture to the camera.
- Press
Spaceto play a round. - Press
Rto reset the score. - Press
Qto quit.
- Rock: zero or one fingers extended
- Scissors: two fingers extended
- Paper: four fingers extended
Three fingers is treated as unknown so you get clear feedback when the gesture is not one of the game moves. The thumb is deliberately ignored because sideways thumb detection can be brittle in a quick classroom setup.
To switch to the finished version:
git checkout complete-solution
python src/main.pyTo return to the workshop starter:
git checkout main