Setting out to code a Tic Tac Toe

A.E.Veltstra
Feb. 2007

You may all know the game of Tic Tac Toe: a fairly simple game of naughts and crosses, and a game board that consists of 4 lines in order to create 9 fields. The objective: to create a line of similar symbols. 2 players act as opponents, taking turns to enter a symbol in a field. A symbol can only be entered in an empty field. The strategy: to prevent one's opponent from creating a line, whilst creating one's own line.

We can work this out in our head, and using a sheet of paper and a pencil probably is the easiest way of playing, whereas a flat surface of sand and a finger suffice in times of trouble. However, playing it when alone presents a bit of a problem: where do we get an opponent? Since 30 years or so that problem can be answered with: computers!

Thus we creed to create a computed Tic Tac Toe consort. Using this as an example, I'm hoping to provide an insight into the mind of one application developer.

First thing to do: analyse the game-play, figure out whether the amount of possible movements and strategies is limited and if so, compile them into a knowledge base.

Why?

Because in most cases, choosing an existing move from an existing strategy is faster than computing the best movement each and every time. For Tic Tac Toe this might not be apparant, but think of a more intricate strategy game like Chess.

Method: play the game a few hundred times and register every movement, plus which party won and in how many moves. Keep on playing untill you start repeating movements.

Next thing to do: figure out how the computer is going to match known strategies with situations presented in real time. Options:

Deciding arguments:

Obviously the method of strategy registration is going to depend on the representation system. Why start out writing down strategies using one method, when you know you will have to convert it into a different representation system?

Third: decide how to enter data into the knowledge base if one can be used. Options:

Obviously this part can be omitted if the strategy amount proves unlimited.

Fourth action: to design an interface for the game-play (a layout, a look, something to interact with the computer). Options:

Deciding arguments:

Fifth action to take: design the strategy system. If we decided to have the computer match real situations to stored ones, design how. Otherwise, design a pseudo-intelligent strategy system that figures out the next move in real time.

More to consider: How will we present our game to our users? Will we be installing an application onto their computers or mobile phones (for instance)? Will we allow them to play it on line, using their web browser? Will we be using a voice-assisted interface for the visually impaired? Will we build a service that can be queried by other computed processes? (Ooh, web services: all the new hype. It's nothing more than a command-line tool via the internet.)

Almost last on the to-do list: deciding on programming methods and environment. Options:

And finally: set out to realise the application. This itself breaks down into a couple steps:

So there you have it: we set out to make Yet Another Tic Tac Toe, or Yattte for short. We didn't write a single line of code, yet we managed to fill up about 75 lines of text. And the "we" in that sentence is just one person. Imagine employing a task force, imagine having a real customer and attending and registering sales meetings, specification and requirement discussions, prototype sessions, training, testing and improvement sessions, requests for change...