I'm using the MinMax algorithm for a game, and since there are a lot possibilities the MinMax recursion takes way too long, even with "alpha-beta pruning"
My code looks some what like this:
min(state,depth,alpha,beta):
if stopingCond:
return value
for moves in allmoves:
state.do(move)
beta = min(beta, max(state,depth,alpha,beta) )
if alpha >= beta: return beta
return beta
max(state,depth,alpha,beta):
if stopingCond:
return value
for moves in allmoves:
state.do(move)
alpha = max(beta, min(state,depth,alpha,beta) )
if alpha >= beta: return alpha
return beta
I know that sometimes you can use for
loops instead of recursion
but I couldn't find a way to convert it.
If any one has a good idea I would be glad to hear it!
Thanks,