Tic-Tac-Toe is a nice example for AI programming because there are only a relative small number of possible moves.
Also if you play perfectly (what your AI hopefully does) you will always win or make a tie.
You can quite easily test every possible move until someone wins - and then you take the optimal move.
Perhaps you should take a look at the MinMax Algorithm
There are also a lot of example Implementations of Tic-Tac-Toe Algorithms. (If you want i could give you one in Pascal :D )
Edit: I found a really nice tutorial on making a Tic-Tac-Toe AI.