Arduino Tic Tac Toe

Home/Arduino Projects/Arduino Tic Tac Toe

Arduino Tic Tac Toe

In this Arduino project video we are going to build an Arduino Game, an Arduino Tic Tac Toe game with a touchscreen. It is an easy and fun project for all ages. Let’s start!

Arduino Tic Tac Toe game project

In this video we are going to build an Arduino Tic Tac Toe game. As you can see, we are using a touch screen and we are playing against the computer. A simple game like Tic Tac Toe is is a great introduction to game programming and Artificial Intelligence. Even though we won’t be using any Artificial Intelligence Algorithms in this game, we will understand why Artificial Intelligence Algorithms are required in more complex games.

——————–
WHERE TO BUY
——————–

Arduino Uno: http://bit.ly/Cheap_Uno

Touch Screen: http://bit.ly/ArduinoTouch

Power Bank: http://bit.ly/PowerBank_XiaoMi

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

After connecting the screen to the Arduino Uno, we can load the code and we are ready to play. At first, we press the “Start Game” button and the game starts. The Arduino plays first. We can then play our move simply by touching the screen. The Arduino then plays its move and so on. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game. When the game is over, the Game Over screen appears. We can then press the play again button to start the game again.

The Arduino is very good at this game. It will win most of the games, or if you are a very good player the game will end in a draw. I intentionally designed this algorithm to make some mistakes in order to give the human player a chance to win. By adding two more lines to the code of the game, we can make the Arduino impossible to lose the game. But how can a 2$ chip, the Arduino CPU, beat the human brain?  Is the program we developed smarter than the human brain?

——————–

LIBRARIES
——————–

📥 Modified Adafruit TFTLCD: Download here

📥  Adafruit GFX: https://github.com/adafruit/Adafruit-GFX-Library

📥 Touchscreen: https://github.com/adafruit/Touch-Screen-Library

Let’s take a quick look at the code of the project. We need three libraries in order the code to compile. You can find links for the all the libraries in the description below. As you can see, even a simple game like this, require more than 600 lines of code. The code is complex, so I won’t try to explain it in a 5 minute video. I will show you the implementation of the algorithm for the Arduino moves though.

At first, we play two random corners. Next, in each round we check if the player can win in the next move. If yes we block that move, most of the times. We don’t block all the moves in order to give the human player a chance to win. Can you find which moves are not blocked? After blocking the move, we play a remaining corner, or a random move. You can study the code, and implement your own unbeatable algorithm easily. As always you can find the code of the project in a link in the description of the video below.
As you can see, even with an Arduino Uno, we can build an unbeatable algorithm for simple games. This Arduino Tic Tac Toe game project is great, because it is easy to build, and at the same time a great introduction to Artificial intelligence and game programming. I will try to build some more advanced projects with Artificial Intelligence in the future using the more powerful Raspberry Pi so stay tuned! I would love to hear your opinion about this project. Please post your comments below and don’t forget to like the video if you find interesting. Thanks!

——————–

CODE OF THE PROJECT
——————–

Download

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv

2017-03-31T11:53:23+00:00

5 Comments

  1. Salahedin Abdelaziz March 20, 2017 at 12:56 am - Reply

    Can u publish an unbeatable version pls.

  2. Giampaolo April 2, 2017 at 7:41 pm - Reply

    I downloaded the game of tic tac toe code from your site but does not work:
    When checking and loading the game code does not give me any error but the display 2.8 TFT LCD touch screen driver 9341 and nothing appears on the serial monitor
    I get the message “starting” and pressing the display will start the game on the serial monitor but the display is blank.
    Can you give me some advice, thanks.

  3. MICHAEL April 20, 2017 at 6:43 pm - Reply

    Change the function to following values:

    void initDisplay()
    {
    tft.reset();
    tft.begin(0x9341);
    tft.setRotation(3);
    }

    • Anon November 11, 2017 at 11:05 am - Reply

      Thanks that worked for me!!

  4. reza November 12, 2017 at 9:47 am - Reply

    problem is
    why here… Error compiling for board arduino? can u tall me what happening bro

Leave A Comment

Close