How We Programmed a Believable AI for a Silly TicTacToe Game

Hello, Johan from Pastille here!

One of the first games we made was called Bill Ball Boll, it started out as a Tic-Tac-Toe board game that you could play with a friend on your phone or tablet.

The twist was that you played on 9 grids instead of one, so the game could be played simultaneously on 9 3×3 boards. You could choose what board to place a mark on and jump around between them however you wanted.

As we started testing the game we quickly realized we needed to have a multiplayer mode or the ability to play against the computer.

The cost associated with creating a multiplayer was just to high for us and since we just started our journey as a game studio we did not have a fanbase. The last thing we wanted was for people to be stuck in a waiting room for someone to play with. But we were unsure of how fun it would be to only play against the game itself. Who wants to play board games alone?

Enter the AI, or rather, enter Mikael who could not stand that there was no-one to play against. We poked fun at him and joked that is was just because he did not have any friends to play with, (sad face) but we were secretly really happy that he spent an entire evening proving the rest of us wrong.

We created a monster

He had researched how to create the smartest system to play against and found a list of all the best moves. Of course, we had to do some adjustments since the game was played on 9 boards at the same time. But they were not that hard to make, what was hard though was to play against our creation.

It was way too hard and also boring, the best you could hope for on the highest level was to get a tie.

It’s super smart and super fast!

We made an initial change to slow down the AI, and not just make it wait for exactly 2 seconds and then plays. Instead, we added a randomized sleep mode that made it “think” for a random amount of time.

Without telling the users who were testing it about the change, we got a very positive response. The testers felt really good when they did a smart move that made the game think longer.

The test-leader just smiled and nodded. Revealing the logic behind it would have broken that illusion.

Ties make no-one happy

To solve the problem with the best outcome being a tie, we again added some randomness. Instead of the computer always picking the best move, it sometimes chooses a lesser one. This really throws people off because when it does that and your opponent can play on 9 boards, it gets almost impossible to predict what the next move is going to be. And trying to remain logical in your moves is all that harder.

We also noticed that really smart people who tried the game before and quickly grew tired of it now played for longer sessions and asked questions about this new AI we had implemented.

One final thing we did with the AI is that we put in three different difficulty settings that you can choose between, these actually get harder with every won game. So the more you play and “get to know” the game, it will change and make better moves. Even if you start playing at easy difficulty you will end up on medium and eventually hard. Creating a more dynamic playing session then if the challenged stayed the same.

Friends or no friends

In conclusion, adding a little random “thinking time” for the AI will make your players feel superior. Have an increasing difficulty for a better user experience. If you have the possibility to have your rules behave irrational, your players will feel like they are playing against something a little more human, making it a little more fun.

Of course, you can still play the game with a friend, but if you find yourself alone that’s ok too, we have the AI for it!


Bill Ball Boll is available globally on the App Store and Google Play priced at just $0.99.