Game Update: Tic Tac Toe

After finishing up my Tic Tac Toe AI, I was left wondering: “Is this bot really the best Tic Tac Toe competitor I can create?”, so I went to work towards another concept of AI to compete in my game versus the original bot. Below are details of the 2 bots, as well as a link to the .pdf showing the outcome of their 10,000 matchups.


CPU 1 is the original bot I created a few days back. The code can be accessed in the link above. This bot takes a unique approach every turn, excluding the final two turns. The first turn it will default to the middle box (spot 5), or, if that is occupied, the bottom right box (spot 9). From there it will place its next 2 pieces according to how it’s opponent is trying to play. If the opponent is aggressive in trying to get 3 in a row, it will play defensively. If the opponent is more lax in their approach, the bot will go for the win. The bot has every possible situation, and the appropriate response, hard coded into it’s programming for turns 2 & 3. Turns 4 & 5 the bot looks for any possible opportunity, by either player, to win the match, and places it’s piece in the spot that would complete the 3 in a row. If none can be found, it simply places in a random open space.


CPU 2 is the bot I created in an attempt to out play my previous bot. The bot’s moves are decided very basically on whether or not the bot has a chance to win. In a kind of “bogo sort” fashion, the bot will make it’s first move at complete random, since the first move is rather insignificant. From there it gauges the opponent’s move, decides whether or not the opponent has a chance to win (not by using specific spot numbers but instead the overall state of the board), and if so defends the move, and if not places it’s piece in the way it deems easiest to get a 3 in a row. This move is the repeated for the rest of the game.


Click here to view the stat sheet.


In conclusion, as of now the original AI is by far the superior, but it would be preferable to decrease the overall number of draws, and perhaps make the bot more aggressive, resulting in more wins.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s