Optimal Games of Tic Tac Torus
JavaScript (ES6), 266 308 317 334 341
A function returning a string.
Edit Found an arithmetic solution for function M (at last!)
F=(n,x=[],M=(a,b,t=-a-b)=&gt;(a-b)%3?a&lt;3&amp;b&lt;3?3+t:a&gt;5&amp;b&gt;5?21+t:12+t:9+t+a%3*3)=&gt;
[for(a of z='012345678')for(b of z)for(c of z)for(d of z) 
a-b&amp;&amp;c-a&amp;&amp;c-b&amp;&amp;(b-(y=M(a,c))?d==y:d-a&amp;&amp;d-b&amp;&amp;d-c)&amp;&amp;(
f=M(c,e=M(b,d)),g=M(a,e),g&lt;f?[f,g]=[g,f]:0,r=a+b+c+d+e,x.push(r+f+g,r+g+f))]
&amp;&amp;x[n]

Very naive , it can be shortened in many ways. It simply enumerates all the possible legal values and returns what find at place n.
The M function returns the position in between two cells, that is the mandatory move to block an opposite player.
More readable
F=(n,x=[],
  M=(a,b,t=-a-b)=&gt;(a-b)%3? 
     a&lt;3&amp;b&lt;3?
       3+t // first row
       :a&gt;5&amp;b&gt;5?
          21+t // last row
          :12+t // middle row and diags
     :9+t+a%3*3 // columns
  )=&gt;
  [for(a of z='012345678') // enumerate the first 4 moves
     for(b of z)
       for(c of z)
         for(d of z) 
           a-b&amp;&amp;c-a&amp;&amp;c-b // avoid duplicates
           &amp;&amp;(b-(y=M(a,c))?d==y:d-a&amp;&amp;d-b&amp;&amp;d-c) // and check if d must block a-c or it's free
           &amp;&amp;(
             e=M(b,d), // forced to block b-d
             f=M(c,e),g=M(a,e),g&lt;f?[f,g]=[g,f]:0, // f and g could be in the wrong order
             r=a+b+c+d+e, // start building a return string
             x.push(r+f+g,r+g+f) // store all values in x
  )]&amp;&amp;x[n] // return value at requested position