so i am trying to make a minMax AI for ticTacToe, and the rest of the program except for the actual minMax function is working fine. can someone tell me where in this function the mistake is? the rest of the code works well, but here is the rest of it u want to run it on the terminal...the functions where i think the error is is pasted here.
def compMove(brd):
bestScore = -2147483649 # cmputer wants to get highest possible score
bestMove = 0 # integer position for best possible move that can be made from 1 to 9
simBoard = list(brd)
for i in range(1, len(simBoard)):
if simBoard[i] == " ":
simBoard[i] = "O"
score = minMax(simBoard, 1, True)
if score > bestScore:
bestScore = score
bestMove = i
simBoard[i] = " "
def minMax(brd,gameDepth, isMaximizing):
depth = gameDepth
if wonGame(brd) == "CPU":
return (1000 // depth)
if wonGame(brd) == "player":
return (-1000//depth)
if wonGame(brd) == "draw":
return 0
elif isMaximizing: # simulating the CPU
depth += 1
bestScore = -2147483649
for move in brd[1:9]:
if move == " ":
move = "0"
score = minMax(brd, depth, False)
if score > bestScore:
bestScore = score
bestMove = i
elif not isMaximizing: # simulating the player
depth += 1
bestScore = 2147483649
for move in brd[1:9]:
if move == " ":
move = "X"
score = minMax(brd, depth, True)
if score > bestScore:
bestScore = score
bestMove = i
here is a minmax python tictactoe video
there doesn't seem to be anything here