I would like to generate a text file containing all 19,683 Tic-Tac-Toe board layouts in the structure of 0 = Blank, 1 = X, and 2 = O. Unfortunately math is not my strong su
My Minimax for Tic Tac Toe implementation generates a tree of 5477 nodes. Each node contains a Tic Tac Toe board state and satisfies the following conditions:
the board state is valid as per Tic Tac Toe rule that players must take turns in placing Xs and Os. i.e. there's no board positions like:
XXX
XXX
XXO
all leafs of the tree contain board states that are consider end-game states as per Tic Tac Toe rules (player 1 wins, player 2 wins or draw). i.e. there's no branch of the tree like:
XOX
OXO
X
|
|
XOX
OXO <-- no point in having this node, since its parent has an end-game position (X won)
XO
A given tree node may have multiple parents (multiple tree nodes may have the same child).
i.e. since a given board state can be obtained through multiple different move sequences, when the tree nodes are being created, if there's already a node containing the board state that I'm about to (re)generate, I reuse (reattach) that existing node. This way, when I score the tree nodes bottom-to-top (as per Minimax theory), I don't have to calculate the same score multiple times for some subset of tree branches (which would be identical if I didn't reuse existing nodes).
I've also found a book which mentions the 5477 unique, distinct, valid Tic Tac Toe board states. :
Tic-Tac-Toe is has 5477 valid states excluding the empty position