I’m creating a tic tac toe program which is player vs pc.
The pc needs to calculate the best move he can do, and do it.
To calculate every possible step a TreeNode sounds perfect but the problem is that after each level the amount of childrens is gettting smaller for example:
^ means empty
^ X O
O O X
^ X ^
for this situation I will need a tree with 3 childrens
but for this situation:
^ ^ ^
^ X ^
^ ^ ^
I will need a tree with 8 childrens.
So is it possible to change the amount of childrens?
While asking the question I thought putting a null on the unwanted childrens would be a solution but do you have a better suggestion?or even the tree is not the best option for my situation?
You should implement your own Tree object, made of nodes which contains an array to children. This way you can also implement an Euristic method to get an approximate distance measure from the optimal solution.