Introduction: 3D4x Game: 3D 4x4x4 Tic-Tac-Toe

Are you tired of playing the same, old, boring, 2-dimensional tic-tac-toe?? Well we have the solution for you! Tic-tac-toe in 3-dimensions!!! For 2 players, in this 4x4x4 cube, get 4 LEDs in a row (in any direction) and you win! You make it. You play it.

Step 1: Gather Components and Tools

The most essential component of this 3D Tic-Tac-Toe is the LED. We chose the PL9823 which already has an integrated controller inside. It has four pins (Data-in, Voltage-Supply, Ground, Data-Out), and allows you to easily address and control the color of the LED. The grid structure can be built in many different ways, but for us this was the cheapest, sturdiest, and most aesthetic option.

Component List:

  • Arduino (we used Uno)
  • PL9823 LEDs (at least 64)
  • Wooden skewer sticks (24cm long)
  • Wiring (we used the insides of an old ethernet cable)
  • Buttons (momentary state)
  • 7 Resistors (220Ohm)
  • Breadboards (1 for buttons and playing, 1 for easy panel connections to Arduino)
  • Foam polystyrene board (~2x30x30cm to make the panels)
  • Foam polystyrene block (~7x25x25cm as the base for the entire grid)

Tool List:

  • Soldering iron
  • Soldering tin
  • Glue
  • Straightedge with ruler
  • Pliers
  • Wire strippers
  • Wire cutters
  • Scissors
  • Marker
  • Pen
  • Tweezers

Step 2: Make the Grid

We make 4 panels of 4x4 LEDs individually.

  • 00: Get styrofoam to make the panel layout. Draw the pattern. In this case, we used 6cm spacing between LEDs with 2cm on the ends.
  • 01: Insert the LED pins into the styrofoam. Important! Make sure you insert all the LEDs with the same orientation. In our case, we chose the output pin to be towards the left.
  • 02: Now place the wooden rod skewer sticks on both sides of the LEDs in rows, making sure the points all face the same direction. Glue the stick to the sides of the LED bulbs and let dry.
  • 03: Do the same for the columns of wooden rod skewer sticks on both sides of the LEDs, making sure the points all face the same direction. Glue and let dry.
  • 04: Gently remove by loosening the LEDs all around. Lift the panel out and flip over. Glue the backside so it is more secure.
  • 05: After everything is dry, bend the pins to make the soldering easier and help to avoid any electrical lines from crossing. We use a tweezer and bend the pin from close to the base.
  • 06: Now prepare the wires. We used an old ethernet cable which has 4-twisted-pair wires inside. Remove the insulation being careful not to cut the small wires. Then untwist, choose your colors to correspond to the different lines, and cut to the right length between the LEDs. Then strip a little bit of the insulation off the ends. We chose ground=green, Vdc=blue, data in/out=white.
  • 07: Solder! There's a lot of connections (64x4), so be careful to solder correctly.
  • 08: Remove the panel, and place on the foam base!

Step 3: Make the Joystick

We used a breadboard to make the joystick for navigating the grid and making the selection. We placed jumpers, resistors, and buttons in order to form the circuit (see diagram) that defines the direction controller (6 buttons, 1 for each direction) and the selection button (enters the player's move). The 5V and the ground are connected to the relative ports on Arduino. For the analog and digital input pins we chose the Arduino ports A5 and 2, respectively.

The selection button has a basic scheme with the anti-bunching resistor. The direction command is based on a resistor ladder that works as voltage divider circuit: the voltage to the analog input depends on the pressed button and is interpreted by Arduino as one command direction.

Step 4: Write the Code

We have uploaded our code for you to use :) First, make the electrical connections to the Arduino. We put a mini breadboard next to the Arduino to make it a little easier. We connected the Arduino "GND" and "5V" to 2 lines of the breadboad where we then plugged the respective ground and Vdc from each panel. For the Data-In and Data-Out we chose 4 different Arduino pins, 13, 10, 7, and 4 for each of the panels. The PL9823 LEDs can be individually addressed by the numerical order of the LED in series. For example, if you want to turn the 1st LED on to a certain color, address LED[0]. For the 16th LED, address LED[15]. Now you are ready to code and play with the pretty lights! Below is a general explanation of the code of the 3D tic-tac-toe game.

The Code of the 3D4x Game

We utilize the fastled.h library that allows us to manage the micro-controlled LEDs.

The cube is memorized virtually in the 3D integer array “TTTMap”, where each element can be in 1 of 5 states according to the corresponding light is owned by: 0= no player, 1= player 1, 2= player 2, 3= player 1 in a winning combination, and 3= player 2 in a winning combination. In order to map the elements of the virtual cube in TTTMap to the real LEDs, the integer arrays LEDMap0, LEDMap1, LEDMap2, LEDMap3 are used.

The “setup” function initializes the Arduino ports connected to the panel, initializes all the LEDs to “black”, and initializes the elements of the TTTMap array to 0.

The “loop” function runs the functions “ReadButtonInput()”, “SendLED()”, and, in case one player wins, the function “VictoryAnimation()”. The first function reads the analog input of the direction command and the digital input of the selection button. The boolean variables “ButtonPushed” and “SelectPushed” are used in order to avoid that the movement is repeated at the loop speed when the button is held. The function “SendLED()” refreshes the LEDs statuses by sending the serial control signal according to the data in the TTTMap. A fundamental function is “CheckVictory()” that is called by “ReadButtonInput()” every time the select button is pushed. This function checks if the selected point in the space makes a winning combination with the surrounding pins. In case of winning combination, the points in the TTTMap are signed with number 3 or 4, according to the player that wins, and the exciting “VictoryAnimation()” runs!

To play again, just hit the reset button on the Arduino :)

Step 5: Play With Your Friends!

No explanation here needed... ENJOY!

Arduino Contest 2019

Participated in the
Arduino Contest 2019