Teaching Reinforcement Learning with LegoNumeric

Machine Learning (ML) and Artificial Intelligence (AI) are mostly difficult subjects to teach or breakdown to the understanding of all learners. But this is even impossible when learners are in areas of no-tech or low-tech. Tech is inaccessible in most places in the world. Plus, there are people who have no access due to economic factors. LegoNumeric is a project inspired by TerraNumerica and Maison de l’Intelligence Artificielle. This project is to help educators and students design machine learning algorithms for playing the NIM Game using Lego or other objects such as colored round objects and cardboard. In the lesson we’re going to look at Reinforcement Learning (LI) with the machine you will be creating.

What is Reinforcement Learning

Reinforcement learning is the training of machine learning models to make a sequence of decisions. The machine uses probability to provide a solution to the problem. It provides some form of rewards for wins.

Reinforcement Learning
Photo by Roohollah Amiri

In a certain environment, the machine learns to achieve a certain goal. When the machine achieves this goal it uses the best method or way to keep on winning.

What is a NIM game

Nim, ancient game of obscure origin in which two players alternate in removing objects from different piles, with the player who removes the last object winning in the normal play variant and losing in another common variant.

Photo by GeeksforGeeks

The normal game is between two players and is played with three heaps of any number of objects. The two players alternate taking any number of objects from any one of the heaps. The goal is to be the last to take an object.

The Objective

The goal to train the machine (A box with pieces of lego) to learn how to win the NIM game. We will first train the machine by making two individuals play the game about 5 to 7 times before the machine will adopt the best strategy to win always against any opponent. At the end of this lesson:

  • Learner will know and understand what AI is
  • Learner will identify variable and data
  • Learner will understand how data is being processed and algorithms
  • Learner will understand how AI is not intelligent and how the machine actually works

Designing your Machine

As a student, you can easily create this machine using the following steps.

Step 1 — Preparation

Get a cardboard, 18 pieces of red lego and 21 pieces of red legos.

Step 2— Container

Make a rectangular box with seven divisions

Step 3— Setup

Place three pieces of yellow and three pieces of red lego into each of the division. The last division should contain only three pieces of yellow lego.

Step 4— Container

Cover the box and make a round hole that enters each division and can be accessed by one hand. Place 16 match sticks on the box. The match sticks should have intervals of at least 3 centimeters.

Step 5— Game Play

Each stands at opposite sides of the box. First player puts the hand inside first whole. If he picks yellow, he takes 2 match sticks. and if he picks red he take 1 match stick. This continues until the last division with only three yellow legos. Who ever wins puts their piece(s) of lego back into the corresponding box, while the loser puts his/hers in a separate box.

Step 5 — Continue and Review

Players continue the process for 5–6 times. One wins, the other loses.

After 5–6 repetition of the, the division of the box will contain pieces of lego with the best strategy. At this point, when the machine plays with any opponent (An individual will stand in at the side of the machine), it will win because it has been trained and the best strategies for winning are employed.

Assessment

Evaluate yourself with the following criteria.

References