$3^9$ is actually $19683$ which is $1000000000$ in base $9$.
The numbers in the range $0,3^9-1$ all have an expression of length $9$ in base $3$.
What you want to do is label the spots in the tick tack toe as follows:
9 | 8 | 7
---------
6 | 5 | 4
---------
3 | 2 | 1
And then, assign to every number in the range $0,3^n-1$ a tick tack toe board depending on its base $3$ expression.
So for example $1234$ is $001200201$ in base $3$. So we assing the following board to $1234$:
0 | 0 | 1
---------
2 | 0 | 0
---------
2 | 0 | 1