Skip to content
Introducing Day of AI USA! Powered by MIT RAISE + Day of AI!

How Do Machines Learn? (with Coding)

In this short unit, students learn the difference between rule-based programming and reinforcement learning using Scratch block coding.

Age:

Approximate Total Time: 2-3 hours


Summary

In this hands-on coding unit, students explore how machines learn through trial and error—the core idea behind reinforcement learning (RL). Using Scratch, students build their own side-scrolling game, create opponents, and then integrate a real reinforcement learning agent that learns to play the game over time.

The unit helps students understand how computers make decisions, how rules differ from learning systems, and how AI agents use rewards to improve their performance. Students also discuss the ethical implications of RL—such as when fast learning vs. slow learning is beneficial, and when trial-and-error systems may be risky in real-world situations.

Students finish by showcasing their games in an arcade-style and comparing how different RL configurations change how an AI opponent learns.

Lesson Flow

Lesson 1 — Build a Scratch Game & Add a Rule-Based Opponent

Students build a scroller-style game using Scratch and then program a simple rule-based opponent. They compare human-designed rules to computer decision-making.

Lesson 2 — Integrate Reinforcement Learning

Students activate a built-in RL opponent, test different Q-tables, and observe how the agent learns through rewards. They explore how sensors and learning rates affect performance and discuss the advantages and risks of fast vs. slow learning.

Lesson 3 — Share, Compare & Reflect

Students play each other’s games in an arcade-style setup, evaluating which RL setups learn fastest or most effectively. They then explore ethical questions: When is RL helpful? When is it unsafe? What is the cost of failure in different real-world scenarios?

Materials

This text will show when the visitor is not logged in. It is managed in the Miscellaneous single entry.