tic tac blah
Posted: Thu Nov 13, 2008 5:54 am
So anybody else thinks the "clarification" in parenthesis for what not to do is actually the same as the problem?!?
Here is my python code, since the problem was small enough there was no issues with recursion depth or speed.
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]