PiStorms tic tac toe robot

This is my second tic tac toe robot, a lot more sophisticated than my first one. For this one I used the power of a Raspberry Pi 3B by using the PiStorms v2 from mindsensors.com.

The program is written in Python on the ev3dev operating system. You’ll find the code on Github.

For calculating the computer’s moves I used the Minimax. This way the computer will always win or the game ends in a draw. Of course, this way it’s no fun to play with, but if you like you can change the algorithm in such way that the computer does not always pick the best move out of all possibilities. You’ll find many suggestions for this on the internet.

Of course the computer knows where it puts its own moves. To determine the moves of the human player I use a picamera. This camera takes a picture when the human player presses the touchsensor. Then the program uses OpenCV to detect the circles the human player drawed. Now it can use the Minimax algorithm to calculate the best move.

Video

Photos

I didn’t make any building instructions, but when you look at the pictures below, I’m sure you can build your own tic tac toe machine. Be sure to adust the settings for all LEGO motors and sensors (ports, speed_sp, position_sp, etc.) and for the picamera.

Overview


Picamera


Turntable (bottom view)




Pen mechanism