TicTacToe-Ception

Saturday, January 3, 2016


Nearly everybody has heard of the game tic-tac-toe. You know, that classic pen-and-paper game consisting of X's and O's on a 3x3 grid that people only ever play when they've reached a sufficient level of boredom. Admittedly, tic-tac-toe is an extremely dull game. A naive observer might note that there are 9!, or 9*8*7*.. = 362880, different possible games of tic-tac-toe, but when you think about the symmetry of the board (for instance, starting a game in any corner space is the same as starting in any of the other corners) you can easily conclude that the real number of games is much less. In fact, there are 31896 possible games according to this site. Well.. that's still a reasonably high number. You might even suggest that tic-tac-toe-ers can have hours of fun and still never play all of these 31896 games, then you'd only be half right. It's true that a pair of decently skilled players would never complete much of these possible games in normal playthroughs. Due to the nature of the game, however, they certainly won't be having the time of their lives playing for so long. The players will end up making many of the same playing choices and will nearly always end their game in a draw. In fact, games of tic-tac-toe played between two perfect players will ALWAYS end a draw. Just try to beat a perfect computer in a game of tic-tac-toe. Go ahead, try. You can play here, I'll wait for you.... See, IT'S IMPOSSIBLE! Who would want to play a game like this? Luckily, there exists a much better version of tic-tic-toe, one I've come to call Tic-Tac-Toe-Ception.

One day last year, in an affliction of desperate boredom and poor judgement, a friend and I played a game of tic-tac-toe. After a few disappointing games we had an idea to play a game of tic-tac-toe on a 4x4 grid, then a 5x5 grid, and so on. We continued this trend and realized that games on larger boards only made ending in a draw more and more likely. Somewhere along we had the inspiration to play a game on a 9x9 board consisting of 9 smaller boards, like this:

9x9 Tic-Tac-Toe Board

To win this version a player would need to win 3 smaller boards in a row. While this version of the game gave us a much greater challenge, it wasn't quite what we had hoped it would be. In a moment of utter genius, however, I came up with the most important rule for this version of 9x9 tic-tac-toe. After looking at the repeated pattern of the board (smaller boards making up a larger board) I realized that cells within these smaller boards can correspond to cells of the larger board. From this, I created the rule that after a player marks a certain cell of a smaller board, the next player must play their mark in the corresponding smaller board of the larger board. Uhhh.. Well maybe this gif can clear up what I'm trying to say:

Tic-Tac-Toe-Ception Example Play

This new way of playing added a lot of depth and strategy to the basic idea of tic-tac-toe. Finally! We have a version of tic-tac-toe that can actually give players a challenge! Hold on though, because that wasn't the end of it. Filled with newfound inspiration, I set out to program this new game on a computer. I succeeded in writing the program in java, but I didn't stop at just the 9x9 board. Using recursion I created a way to add more layers to the board. By adding even smaller 3x3 boards in each cell of the smaller 3x3 boards I can have an unlimited number of cells in the board. Yet, due to the limits of computers and the size of the cells, I stopped my recursion at an 81x81 sized board. This monstrous board consists of four layers of 3x3 boards - the black outer layer, a yellow second layer, a green third layer, and a blue fourth layer - all pictured here:

9x9 Tic-Tac-Toe Board

I named this monster of a game Tic-Tac-Toe-Ception, and you are welcome to study the (admittedly inefficient) code here. Now although I certainly discovered this game myself, I can't claim to be the first person to ever do so. While creating this post, I discovered that there already exists many games like this one across the internet. Other people call it by different names and have slightly different rules than those I play by. One example is this version called Ultimate Tic-Tac-Toe. Besides a different name, this version includes the rule that if an opponent sends you to a board that's already been won you can choose to play in any board you want, whereas in my version I allow players to play in boards that are already won, but only the first player to win on that board will count as the winner of that board. If you are interested in a full description of the rules for my version of Tic-Tac-Toe-Ception come back later as I will post a link to it here.

Currently, I am trying to write a version of this game in javascript, so that it may run in a web browser. I am adapting the code of the simple tic-tac-toe game I linked above. That code can be found here. I also plan to create an artificial intelligence for the game, so that players may play against a computer. I have also thought about using machine learning to teach this artificial intelligence how to play, which will involve having the a.i. play many games over and over, where each game teaches it how to play better and better. I might not have a clear idea of what I'm getting myself into, but I am going to try it anyways. You can see my progress here!


Comments are coming soon!