There are 255,168 ways to play this game.
The creative and strategic minds of Tic Tac Toe seekers can now rejoice, for our favorite game has been calculated to have a whopping 255,168 possible outcomes. Of these many games only 131,184 are won by the first player; 77,904 go to the opponent; leaving 46 drawn in which neither side is able to claim victory. This supports the intuition that it’s an advantage beginning play as both corners allow you access into three other squares – but what if this was on another shape? These numbers do not take positions with mirroring or rotating boards into account- so no matter where your initial corner placement may be (i.e tipping over one square) there still exists plenty of opportunity for success!
I use a recursive approach to play against the computer.
Within this program I want to have some degree of randomness, but not too much where it becomes absurdly difficult for computers or people to compete with each other. In short: enough randomness for fun, but not so much that things become unfair or unfun.
The way you would normally implement a game like tic tac toe is as follows:
Define the nine possible states (in our case the rows and columns) Each state has a function that returns the winner If two moves are possible choose one at random Try all the outcomes and see which one leads to victory If there are no more possible moves then we lose! Otherwise, go back to number 2.