(I'm trying to create basic brute force A.I. for tic-tac-toe)
I'm having a problem with this code producing the right countermove.
Code:
def create_strat(b,t,n):
g_perm = 0
g_temp = 0
k = 0
q = 0
for i in r:
for j in r:
if b[i][j] == 0:
#you get an available move
b[i][j] = t
if check_victory(b) != 0:
g_temp = g_temp + (256/(2**n))
elif check_victory(b) == 0 and n < 9:
g_temp = create_strat(b,-t,n+1)[0]
b[i][j] = 0
if g_temp > g_perm:
g_perm = g_temp
k = i
q = j
print n
g_temp = 0
return [g_perm,k,q]
b is the game face (3x3 list)
t is player turn (1 is player 1, -1 is player 2)
All other functions have been tested to operate correctly.
For a situation where the input is ([[1,1,0],[0,0,0],[0,0,0]],-1,0)
the game would look like this:
however, the program outputs [128,1,0], clearly the wrong move.
if you input the same box, with the player turn on 1 (t = 1), the correct output ([256,0,2]) is given.
if you would like me to post the entire program I can do that.
thanks in advance.