SamuKata
Pybricks
Pybricks

patreon


Programming a Tic-Tac-Toe game with Pybricks

A good way to practice more interesting coding concepts is to mimic a well known board game. There’s no stress to get a robot mission right, and it’s easy to check if your code behaves according to the rules of the game.

In this article, we’ll show you how you can make Tic Tac Toe game for two players!

Requirements

If you want to build exactly the same Tic Tac Toe game, you’ll need the LEGO Education Spike Essential (45345) set. However, you can build it with any hub if you combine it with the Color Light Matrix to display the game.

To build it, place the motor and the hub on the base plate using some bricks and pins, as shown above. Add a beam to the motor to indicate whose turn it is.

Running and playing the game

Instead of noughts and crosses, you’ll use the blue and green colors to indicate each player’s turn on the SPIKE Color Light Matrix.

You’ll use the hub button to choose your position, and then confirm your choice by handing the flag to the other player for their turn. You can see this in the video above.

The example below includes numerous comment blocks to help you learn how this program works. If you prefer to download the ready-made program, you can do so here. Have fun!

Programming a Tic-Tac-Toe game with Pybricks

More Creators