Scratch Artificial Intelligence
Intermediate
60 mins
Teacher/Student led
220 points
What you need:
Chromebook/Laptop/PC or iPad/Tablet
Webcam/camera

Scratch AI Rock, Paper, Scissors Game

In this step-by-step lesson, you'll create a Rock, Paper, Scissors game using Scratch and Google Teachable Machine. You'll learn to set up Scratch, add sprites, create variables, randomise computer choice, load a Teachable Machine Model, set confidence threshold, determine game results, and enhance your project. You'll also learn to use your Teachable Machine Image model with hand gestures to play against the computer.
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Introduction

    In this lesson, you will create a fun Rock, Paper, Scissors game using Scratch and Google Teachable Machine.

    You will learn how to use your Teachable Machine Image model with rock, paper, and scissors hand gestures to play against the computer.

    If you don't have a Teachable Machine Image model, don't worry! You can use the provided model.


    2 - Setup Scratch and TM2Scratch

    Go to https://stretch3.github.io/ and start a new Scratch project and delete the Cat sprite.

    Then, add the TM2Scratch extension by clicking on the Extensions button at the bottom left corner of the screen and selecting TM2Scratch. This extension allows you to use Google Teachable Machine Image models in your Scratch projects.

    When you add this extension, it will automatically try and use your computer's camera. If necessary, click on 'Allow' to give it permission to use your camera. You should see what the camera is showing in the stage area.



    3 - Add a Sprite

    Add a new sprite to the project that will represent the computer's choice in the game. You can choose any sprite you like, but for this example, we'll use the 'Gobo' sprite.


    4 - Create Variables

    Create three new variables:

    • playerChoice - to store the player's choice.
    • computerChoice - to store the computer's choice.
    • result - to store the result of the game.

    5 - Randomize Computer Choice

    In this step, you will add code to your sprite to randomly set the computer's choice to 1, 2, or 3. These numbers will represent the computer's choice of rock, paper, or scissors, respectively:

    • 1 = Rock
    • 2 = Paper
    • 3 = Scissors

    Add the following code to your sprite:

    when green flag clicked set [computerChoice v] to (pick random (1) to (3))

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

    Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more