Here is my python code, since the problem was small enough there was no issues with recursion depth or speed.
Code: Select all
draws=0.0
game=0.0
def move(L,player):
global draws,game
if(L[0]==L[1]==L[2]!=0 or L[3]==L[4]==L[5]!=0 or L[6]==L[7]==L[8]!=0 or L[0]==L[4]==L[8]!=0 or L[2]==L[4]==L[6]!=0 or L[2]==L[5]==L[8]!=0 or L[1]==L[4]==L[7]!=0 or L[0]==L[3]==L[6]!=0):
game+=1
return
empty=[]
for i,p in enumerate(L):
if(p==0):
empty.append(i)
if(empty==[]):
draws+=1
game+=1
return
else:
for k in empty:
newL=L[:]
newL[k]=player
move(newL,player%2+1)
L=[0 for i in range(9)]
L[4]=1
move(L,2)
print draws/game
[/quote]