Mathematics Scratch
Enrichment
60 mins
Teacher/Student led
+225 XP
What you need:
Chromebook/Laptop/PC or iPad/Tablet

Maze - Artificial Intelligence

In this lesson we will program a sprite to figure out how to navigate a maze using random decision making and we will time the beetle to see how fast it can complete the maze.

Teacher Class Feed

Load previous activity

    1 - Create a new Scratch project

    Create a new Scratch project and delete the cat.

    2 - Add the maze sprite

    Save the maze picture in this step to your computer and upload it into Scratch as a new sprite. Once it appears, drag it into the centre of the stage area.

    If you cannot upload the maze image as a sprite, you can use the starter project here.


    3 - Add the beetle sprite

    Add the beetle
    Add the 'Beetle' sprite from the sprite library. Drag the beetle to the start of the maze (the gap at the left of the maze).

    Shrink the beetle
    As the beetle sprite is too large to fit in the corridors of the maze, we'll need to add the following code to the beetle to shrink it:

    when green flag clicked set size to (15) %

    Position and point the beetle
    Once you have added this code, click the green flag to shrink your beetle and then drag it to the start of the maze (near the bottom left of the maze). Now add the following code to your existing code block so that the beetle always starts in this location and is pointed in the right direction.

    when green flag clicked set size to (15) % //add new code under here go to x(0) y(0)//set these to the start of the maze point in direction (0) // point upwards

    It's important to drag the beetle to the start of the maze before you add the go to x: 0 y: 0  block as when you add this block it's pre-populated with the coordinates of where the sprite currently is.


    4 - Edit the maze sprite

    We need something at the exit of the maze that we can detect when our beetle sprite gets there, so we're going to add a small green circle by editing the maze. 

    Click on the maze sprite in the sprite list below the stage area and then click on the 'Costumes' tab, this will open the sprite editor. To add a green circle follow these steps:

    1. Click 'Convert to Vector'
    2. Click the 'Circle' tool
    3. Choose a green colour
    4. Turn off the outline
    5. At the exit of the maze draw a circle by:
    6. - holding down the Shift button
      - and holding down the left click button
      - and dragging across to draw a circle
    7. Drag the circle to the exit of the maze

    If you make a mistake just click the back button (a rounded arrow pointing left).


    123learn · Online learning platform

    Unlock the full learning experience

    You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2026. 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