A little background: as a way to learn multinode trees in C++, I decided to generate all possible TicTacToe boards and store them in a tree such that the branch beginning at a n
Tic-Tac-Toe can be solved using a greedy algorithm and doesn't really require a decision tree.
If you want to continue using your current algorithm, do as patros suggests, and minimize the possibility of losing at each decision.
If you want a simpler approach have the AI do the following each turn:
Rate each square for its desirability, for each other taken square (by the AI) on a line, add one point of desirability for that square. For each square taken by the opponent, remove one point of desirability.
For example, if the board is currently:
_|O|X
_|X|_
O| |
The top-left corner has a desirability of 0 (1 for the X in the same row, and 1 for the X in the diagonal, but -1 for each of the Os).
Play on the most desirable square. Breaking ties arbitrarily.
In the example from above, the AI would choose the mid-right square, since it has a desirability of 2, which would lead to a win the following turn.
If the game has just begun, play the center square, if the center square is taken, choose a corner at random.
This was my grade 10 Visual Basic term project. It's impossible to beat and requires far less memory than storing a decision tree.